From ced8a752260a8eff7c606ecd9d9317b401293ead Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 21 May 2013 10:19:22 +0200 Subject: [PATCH] Adding breadcrumb for the new question pool page --- main/inc/services.php | 17 ++-- main/template/default/layout/bread.tpl | 30 ++++++++ main/template/default/layout/main_header.tpl | 8 +- main/template/default/layout/page_body.tpl | 2 +- .../Controller/CommonController.php | 77 +++++++++++++------ .../Controller/ExerciseController.php | 67 +++++++++++++++- 6 files changed, 163 insertions(+), 38 deletions(-) create mode 100644 main/template/default/layout/bread.tpl diff --git a/main/inc/services.php b/main/inc/services.php index 6afdd062d1..c24ea851df 100644 --- a/main/inc/services.php +++ b/main/inc/services.php @@ -271,9 +271,12 @@ if (is_writable($app['sys_temp_path'])) { if ($app['debug']) { // Adding symfony2 web profiler (memory, time, logs, etc) if (api_get_setting('allow_web_profiler') == 'true') { - $app->register($p = new Silex\Provider\WebProfilerServiceProvider(), array( - 'profiler.cache_dir' => $app['profiler.cache_dir'], - )); + $app->register( + $p = new Silex\Provider\WebProfilerServiceProvider(), + array( + 'profiler.cache_dir' => $app['profiler.cache_dir'], + ) + ); $app->mount('/_profiler', $p); } //$app->register(new Whoops\Provider\Silex\WhoopsServiceProvider); @@ -281,8 +284,6 @@ if (is_writable($app['sys_temp_path'])) { } } -// Registering Menu service provider (too gently creating menus with the URLgenerator provider) -$app->register(new \Knp\Menu\Silex\KnpMenuServiceProvider()); // Pagerfanta settings (Pagination using Doctrine2, arrays, etc) use FranMoreno\Silex\Provider\PagerfantaServiceProvider; @@ -302,13 +303,15 @@ $app['pagerfanta.view.options'] = array( 'default_view' => 'twitter_bootstrap' // the pagination style ); +// Registering Menu service provider (too gently creating menus with the URLgenerator provider) +$app->register(new \Knp\Menu\Silex\KnpMenuServiceProvider()); + // @todo use a app['image_processor'] setting define('IMAGE_PROCESSOR', 'gd'); // imagick or gd strings // Setting the Imagine service provider to deal with image transformations used in social group. $app->register(new Grom\Silex\ImagineServiceProvider(), array( - 'imagine.factory' => 'Gd', - //'imagine.base_path' => __DIR__.'/vendor/imagine', + 'imagine.factory' => 'Gd' )); // Prompts Doctrine SQL queries using monolog diff --git a/main/template/default/layout/bread.tpl b/main/template/default/layout/bread.tpl new file mode 100644 index 0000000000..951429ba93 --- /dev/null +++ b/main/template/default/layout/bread.tpl @@ -0,0 +1,30 @@ +{% block compressed_root %} +{% spaceless %} + {{ block('root') }} +{% endspaceless %} +{% endblock %} + +{% block root %} + {{ block('breadcrumb') }} +{% endblock %} + +{% block breadcrumb %} + {% if item %} + + {% endif %} +{% endblock %} + +{% block item %} + {% for item in item.children %} + {% if matcher.isCurrent(item) %} +
  • {{ block('label') }}
  • + {% else %} +
  • {{ block('label') }} /
  • + {% endif %} + {% endfor %} +{% endblock %} +{% block label %} + {{ item.label }} +{% endblock %} diff --git a/main/template/default/layout/main_header.tpl b/main/template/default/layout/main_header.tpl index 3b5c6749e3..ef5361d0d3 100644 --- a/main/template/default/layout/main_header.tpl +++ b/main/template/default/layout/main_header.tpl @@ -98,10 +98,12 @@ {% include app.template_style ~ "/layout/menu.tpl" %} {# breadcrumb #} - {{ breadcrumb }} + {% if app.breadcrumbs %} + {{ app.breadcrumbs }} + {% else %} + {{ breadcrumb }} + {% endif %} - - {% if app.full_width == 1 %}
    {% else %} diff --git a/main/template/default/layout/page_body.tpl b/main/template/default/layout/page_body.tpl index 93ac014414..a5e3caaf8a 100644 --- a/main/template/default/layout/page_body.tpl +++ b/main/template/default/layout/page_body.tpl @@ -28,4 +28,4 @@
    {% include app.template_style ~ "/layout/welcome_to_course.tpl" %}
    -{% endif %} \ No newline at end of file +{% endif %} diff --git a/src/ChamiloLMS/Controller/CommonController.php b/src/ChamiloLMS/Controller/CommonController.php index 3804022cfa..a6ce48ba45 100644 --- a/src/ChamiloLMS/Controller/CommonController.php +++ b/src/ChamiloLMS/Controller/CommonController.php @@ -3,6 +3,9 @@ namespace ChamiloLMS\Controller; use \ChamiloSession as Session; +use Silex\Application; +use Knp\Menu\Matcher\Matcher; + /** * @package ChamiloLMS.CommonController @@ -21,32 +24,58 @@ class CommonController } /** - * + * @param Application $app + * @param $breadcrumbs */ - public function cidReset() + public function setBreadcrumb(Application $app, $breadcrumbs) { - Session::erase('_cid'); - Session::erase('_real_cid'); - Session::erase('_course'); - - if (!empty($_SESSION)) { - foreach ($_SESSION as $key => $item) { - if (strpos($key,'lp_autolunch_') === false) { - continue; - } else { - if (isset($_SESSION[$key])) { - Session::erase($key); - } - } - } - } - //Deleting session info - if (api_get_session_id()) { - Session::erase('id_session'); - Session::erase('session_name'); - } - if (api_get_group_id()) { - Session::erase('_gid'); + $courseInfo = api_get_course_info(); + + // Adding course breadcrumb. + if (!empty($courseInfo)) { + $courseBreadcrumb = array( + 'name' => \Display::return_icon('home.png').' '.$courseInfo['title'], + 'url' => array( + 'route' => 'course', + 'routeParameters' => array( + 'cidReq' => api_get_course_id(), + 'id_session' => api_get_session_id() + ) + ) + ); + array_unshift($breadcrumbs, $courseBreadcrumb); } + + $app['main_breadcrumb'] = function ($app) use ($breadcrumbs) { + /** @var \Knp\Menu\Silex\RouterAwareFactory $menu */ + $menu = $app['knp_menu.factory']->createItem( + 'root', + array( + 'childrenAttributes' => array( + 'class' => 'breadcrumb', + 'currentClass' => 'active' + ) + ) + ); + + foreach ($breadcrumbs as $item) { + $menu->addChild($item['name'], $item['url']); + } + return $menu; + }; + + $matcher = new Matcher(); + $voter = new \Knp\Menu\Silex\Voter\RouteVoter(); + $voter->setRequest($app['request']); + $matcher->addVoter($voter); + $renderer = new \Knp\Menu\Renderer\TwigRenderer($app['twig'], 'bread.tpl', $matcher); + $bread = $renderer->render( + $app['main_breadcrumb'], + array( + 'template' => 'default/layout/bread.tpl' + ) + ); + $app['breadcrumbs'] = $bread; } + } diff --git a/src/ChamiloLMS/Controller/ExerciseController.php b/src/ChamiloLMS/Controller/ExerciseController.php index c5e6f279c6..58851ad8a7 100644 --- a/src/ChamiloLMS/Controller/ExerciseController.php +++ b/src/ChamiloLMS/Controller/ExerciseController.php @@ -9,11 +9,12 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; use \ChamiloSession as Session; + /** * @package ChamiloLMS.Controller * @author Julio Montoya */ -class ExerciseController +class ExerciseController extends CommonController { public function dashboardAction(Application $app, $exerciseId) @@ -101,6 +102,52 @@ class ExerciseController $extraJS[] = api_get_jqgrid_js(); $app['extraJS'] = $extraJS; + // @todo this should be auto + + if (empty($exerciseId)) { + $breadcrumbs = array( + array( + 'name' => get_lang('Exercise'), + 'url' => array( + 'uri' => api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq() + ) + ), + array( + 'name' => get_lang('QuestionPool'), + 'url' => array( + 'route' => 'exercise_question_pool_global', + 'routeParameters' => array( + 'cidReq' => api_get_course_id(), + 'id_session' => api_get_session_id(), + //'exerciseId' => $exerciseId, + ) + ) + ) + ); + } else { + $breadcrumbs = array( + array( + 'name' => get_lang('Exercise'), + 'url' => array( + 'uri' => api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidreq().'&exerciseId'.$exerciseId + ) + ), + array( + 'name' => get_lang('QuestionPool'), + 'url' => array( + 'route' => 'exercise_question_pool', + 'routeParameters' => array( + 'cidReq' => api_get_course_id(), + 'id_session' => api_get_session_id(), + 'exerciseId' => $exerciseId, + ) + ) + ) + ); + } + + $this->setBreadcrumb($app, $breadcrumbs); + $questionColumns = \Question::getQuestionColumns($cidReq); //$questionColumns = \Question::getQuestionColumns($cidReq, null, null, true); @@ -212,7 +259,14 @@ class ExerciseController $question->setDefaultValues = true; // Generating edit URL. - $url = $app['url_generator']->generate('exercise_question_edit', array('cidReq' => api_get_course_id(), 'id_session' => api_get_session_id(), 'id' => $id)); + $url = $app['url_generator']->generate( + 'exercise_question_edit', + array( + 'cidReq' => api_get_course_id(), + 'id_session' => api_get_session_id(), + 'id' => $id + ) + ); // Creating a new form $form = new \FormValidator('edit_question', 'post', $url); @@ -229,7 +283,14 @@ class ExerciseController // Save answers. $question->processAnswersCreation($form); - $url = $app['url_generator']->generate('exercise_question_show', array('cidReq' => api_get_course_id(), 'id_session' => api_get_session_id(), 'id' => $id)); + $url = $app['url_generator']->generate( + 'exercise_question_show', + array( + 'cidReq' => api_get_course_id(), + 'id_session' => api_get_session_id(), + 'id' => $id + ) + ); return $app->redirect($url); }