Fixing course and courseSession variables are loaded in before and not in the controller constructor + adding comments, removing unused code

skala
Julio Montoya 12 years ago
parent 6fb01d3b5d
commit c01b277016
  1. 28
      main/inc/global.inc.php
  2. 3
      main/inc/services.php
  3. 33
      src/ChamiloLMS/Controller/BaseController.php
  4. 3
      src/ChamiloLMS/Controller/CommonController.php
  5. 3
      src/ChamiloLMS/Provider/ReflectionControllerProvider.php

@ -497,7 +497,6 @@ $app->before(
if (!file_exists($app['configuration_file']) && !file_exists($app['configuration_yml_file'])) { if (!file_exists($app['configuration_file']) && !file_exists($app['configuration_yml_file'])) {
$url = str_replace('web', 'main/install', $request->getBasePath()); $url = str_replace('web', 'main/install', $request->getBasePath());
return new RedirectResponse($url); return new RedirectResponse($url);
//$app->abort(500, "Configuration file was not found.");
} }
// Check the PHP version. // Check the PHP version.
@ -505,11 +504,18 @@ $app->before(
$app->abort(500, "Incorrect PHP version."); $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. // Checks temp folder permissions.
if (!is_writable(api_get_path(SYS_ARCHIVE_PATH))) { 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'])) { if (!isset($app['configuration'])) {
$app->abort(500, '$configuration array must be set in the configuration.php file.'); $app->abort(500, '$configuration array must be set in the configuration.php file.');
} }
@ -525,7 +531,7 @@ $app->before(
$filesystem = $app['chamilo.filesystem']; $filesystem = $app['chamilo.filesystem'];
if ($app['debug']) { 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); $filesystem->createFolders($app['temp.paths']->folders);
} }
@ -562,8 +568,7 @@ $app->before(
} }
} }
$_setting = Session::read('_setting'); $app['plugins'] = Session::read('_plugins');
$_plugins = Session::read('_plugins');
// Default template style. // Default template style.
$templateStyle = api_get_setting('template'); $templateStyle = api_get_setting('template');
@ -573,8 +578,6 @@ $app->before(
// Default layout. // Default layout.
$app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl'; $app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl';
$app['plugins'] = $_plugins;
// Setting languages. // Setting languages.
$app['api_get_languages'] = api_get_languages(); $app['api_get_languages'] = api_get_languages();
$app['language_interface'] = $language_interface = api_get_language_interface(); $app['language_interface'] = $language_interface = api_get_language_interface();
@ -720,20 +723,21 @@ $app->before(
// Check if we are inside a Chamilo course tool // Check if we are inside a Chamilo course tool
$isCourseTool = (strpos($request->getPathInfo(), 'courses/') === false) ? false : true; $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 // Setting course entity for controllers and templates
if ($isCourseTool) { if ($isCourseTool) {
// The course parameter is loaded
$course = $request->get('course');
// Converting /courses/XXX/ to a Entity/Course object // Converting /courses/XXX/ to a Entity/Course object
$course = $app['orm.em']->getRepository('Entity\Course')->findOneByCode($course); $course = $app['orm.em']->getRepository('Entity\Course')->findOneByCode($course);
$app['course'] = $course; $app['course'] = $course;
$app['template']->assign('course', $course);
$sessionId = $request->get('id_session'); $sessionId = $request->get('id_session');
$session = $app['orm.em']->getRepository('Entity\Session')->findOneById($sessionId); $session = $app['orm.em']->getRepository('Entity\Session')->findOneById($sessionId);
$app['course_session'] = $session; $app['course_session'] = $session;
$app['template']->assign('course_session', $session);
} }
} }
); );

@ -21,8 +21,7 @@ $app['root_dir'] = $app['root_sys'];
$app->register(new Flint\Provider\RoutingServiceProvider(), array( $app->register(new Flint\Provider\RoutingServiceProvider(), array(
'routing.resource' => $app['sys_config_path'].'routing.yml', 'routing.resource' => $app['sys_config_path'].'routing.yml',
'routing.options' => array( 'routing.options' => array(
//'cache_dir' => $app['debug'] == true ? null : $app['sys_temp_path'] 'cache_dir' => $app['debug'] == true ? null : $app['sys_temp_path']
'cache_dir' => $app['sys_temp_path']
), ),
)); ));

@ -36,17 +36,6 @@ abstract class BaseController extends FlintController
$this->app = $app; $this->app = $app;
// In order to use the Flint Controller. // In order to use the Flint Controller.
$this->pimple = $app; $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'])) { if (isset($this->app['course_session']) && !empty($this->app['course_session'])) {
return $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(); abstract protected function generateLinks();
/**
* @return \Doctrine\ORM\EntityManager
*/
protected function getManager() protected function getManager()
{ {
return $this->get('orm.em'); return $this->get('orm.em');
@ -456,7 +464,6 @@ abstract class BaseController extends FlintController
return new JsonResponse($this->getEntityForJson($object->getId())); return new JsonResponse($this->getEntityForJson($object->getId()));
} }
/** /**
* Returns an entity from its ID, or FALSE in case of error. * Returns an entity from its ID, or FALSE in case of error.
* *

@ -40,7 +40,6 @@ class CommonController extends BaseController
*/ */
protected function getControllerAlias() protected function getControllerAlias()
{ {
} }
/** /**
@ -70,7 +69,6 @@ class CommonController extends BaseController
); );
} }
/** /**
* *
* @param array $breadcrumbs * @param array $breadcrumbs
@ -134,5 +132,4 @@ class CommonController extends BaseController
); );
$app['breadcrumbs'] = $bread; $app['breadcrumbs'] = $bread;
} }
} }

@ -39,8 +39,9 @@ class ReflectionControllerProvider implements ControllerProviderInterface
// Routes are already cached using Flint // Routes are already cached using Flint
if (file_exists($app['sys_temp_path'].'ProjectUrlMatcher.php')) { if (file_exists($app['sys_temp_path'].'ProjectUrlMatcher.php')) {
return $controllers; return $controllers;
} }
$reflection = new \ReflectionClass($app[$this->controllerName]); $reflection = new \ReflectionClass($app[$this->controllerName]);
$className = $reflection->getName(); $className = $reflection->getName();

Loading…
Cancel
Save