From c01b277016a05d4fe11f9b7b33a7b005071010f4 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 3 Sep 2013 17:53:33 +0200 Subject: [PATCH] Fixing course and courseSession variables are loaded in before and not in the controller constructor + adding comments, removing unused code --- main/inc/global.inc.php | 28 +++++++++------- main/inc/services.php | 3 +- src/ChamiloLMS/Controller/BaseController.php | 33 +++++++++++-------- .../Controller/CommonController.php | 3 -- .../Provider/ReflectionControllerProvider.php | 3 +- 5 files changed, 39 insertions(+), 31 deletions(-) diff --git a/main/inc/global.inc.php b/main/inc/global.inc.php index 6d68c847b2..6e4bc5ea90 100644 --- a/main/inc/global.inc.php +++ b/main/inc/global.inc.php @@ -497,7 +497,6 @@ $app->before( if (!file_exists($app['configuration_file']) && !file_exists($app['configuration_yml_file'])) { $url = str_replace('web', 'main/install', $request->getBasePath()); return new RedirectResponse($url); - //$app->abort(500, "Configuration file was not found."); } // Check the PHP version. @@ -505,11 +504,18 @@ $app->before( $app->abort(500, "Incorrect PHP version."); } + // Check data folder + + if (!is_writable(api_get_path(SYS_DATA_PATH))) { + $app->abort(500, "data folder must be writable."); + } + // Checks temp folder permissions. if (!is_writable(api_get_path(SYS_ARCHIVE_PATH))) { - $app->abort(500, "temp folder must be writable."); + $app->abort(500, "data/temp folder must be writable."); } + // Checking that configuration is loaded if (!isset($app['configuration'])) { $app->abort(500, '$configuration array must be set in the configuration.php file.'); } @@ -525,7 +531,7 @@ $app->before( $filesystem = $app['chamilo.filesystem']; if ($app['debug']) { - // Creates temp folders for every request if debug is on. + // Creates data/temp folders for every request if debug is on. $filesystem->createFolders($app['temp.paths']->folders); } @@ -562,8 +568,7 @@ $app->before( } } - $_setting = Session::read('_setting'); - $_plugins = Session::read('_plugins'); + $app['plugins'] = Session::read('_plugins'); // Default template style. $templateStyle = api_get_setting('template'); @@ -573,8 +578,6 @@ $app->before( // Default layout. $app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl'; - $app['plugins'] = $_plugins; - // Setting languages. $app['api_get_languages'] = api_get_languages(); $app['language_interface'] = $language_interface = api_get_language_interface(); @@ -720,20 +723,21 @@ $app->before( // Check if we are inside a Chamilo course tool $isCourseTool = (strpos($request->getPathInfo(), 'courses/') === false) ? false : true; - //$controllerName = $request->get('_controller'); - - // The course parameter is loaded - $course = $request->get('course'); - // Setting course entity for controllers and templates if ($isCourseTool) { + // The course parameter is loaded + $course = $request->get('course'); + // Converting /courses/XXX/ to a Entity/Course object $course = $app['orm.em']->getRepository('Entity\Course')->findOneByCode($course); $app['course'] = $course; + $app['template']->assign('course', $course); $sessionId = $request->get('id_session'); $session = $app['orm.em']->getRepository('Entity\Session')->findOneById($sessionId); $app['course_session'] = $session; + + $app['template']->assign('course_session', $session); } } ); diff --git a/main/inc/services.php b/main/inc/services.php index efddaa95ab..ef09f7cd35 100644 --- a/main/inc/services.php +++ b/main/inc/services.php @@ -21,8 +21,7 @@ $app['root_dir'] = $app['root_sys']; $app->register(new Flint\Provider\RoutingServiceProvider(), array( 'routing.resource' => $app['sys_config_path'].'routing.yml', 'routing.options' => array( - //'cache_dir' => $app['debug'] == true ? null : $app['sys_temp_path'] - 'cache_dir' => $app['sys_temp_path'] + 'cache_dir' => $app['debug'] == true ? null : $app['sys_temp_path'] ), )); diff --git a/src/ChamiloLMS/Controller/BaseController.php b/src/ChamiloLMS/Controller/BaseController.php index b19882e6a6..d3ac5af6e5 100644 --- a/src/ChamiloLMS/Controller/BaseController.php +++ b/src/ChamiloLMS/Controller/BaseController.php @@ -36,17 +36,6 @@ abstract class BaseController extends FlintController $this->app = $app; // In order to use the Flint Controller. $this->pimple = $app; - - // Inserting course - /** @var \Entity\Course $app['course'] */ - $course = $this->getCourse(); - if ($course) { - $template = $this->get('template'); - $template->assign('course', $course); - - $session = $this->getSession(); - $template->assign('course_session', $session); - } } /** @@ -68,7 +57,23 @@ abstract class BaseController extends FlintController if (isset($this->app['course_session']) && !empty($this->app['course_session'])) { return $this->app['course_session']; } - return null; + return false; + } + + /** + * @return \Template + */ + protected function getTemplate() + { + return $this->app['template']; + } + + /** + * @return \Entity\User + */ + public function getUser() + { + return parent::getUser(); } /** @@ -110,6 +115,9 @@ abstract class BaseController extends FlintController */ abstract protected function generateLinks(); + /** + * @return \Doctrine\ORM\EntityManager + */ protected function getManager() { return $this->get('orm.em'); @@ -456,7 +464,6 @@ abstract class BaseController extends FlintController return new JsonResponse($this->getEntityForJson($object->getId())); } - /** * Returns an entity from its ID, or FALSE in case of error. * diff --git a/src/ChamiloLMS/Controller/CommonController.php b/src/ChamiloLMS/Controller/CommonController.php index 71508d9cd3..1003aebe2d 100644 --- a/src/ChamiloLMS/Controller/CommonController.php +++ b/src/ChamiloLMS/Controller/CommonController.php @@ -40,7 +40,6 @@ class CommonController extends BaseController */ protected function getControllerAlias() { - } /** @@ -70,7 +69,6 @@ class CommonController extends BaseController ); } - /** * * @param array $breadcrumbs @@ -134,5 +132,4 @@ class CommonController extends BaseController ); $app['breadcrumbs'] = $bread; } - } diff --git a/src/ChamiloLMS/Provider/ReflectionControllerProvider.php b/src/ChamiloLMS/Provider/ReflectionControllerProvider.php index 7efc046f4f..2d0467f6e6 100644 --- a/src/ChamiloLMS/Provider/ReflectionControllerProvider.php +++ b/src/ChamiloLMS/Provider/ReflectionControllerProvider.php @@ -39,8 +39,9 @@ class ReflectionControllerProvider implements ControllerProviderInterface // Routes are already cached using Flint if (file_exists($app['sys_temp_path'].'ProjectUrlMatcher.php')) { - return $controllers; + return $controllers; } + $reflection = new \ReflectionClass($app[$this->controllerName]); $className = $reflection->getName();