';
- $url = api_get_path(WEB_PUBLIC_PATH).'introduction/edit/'.$tool;
+ $url = $urlGenerator->generate(
+ 'introduction.controller:editAction',
+ array('tool' => $tool, 'course' => api_get_course_id())
+ );
+
$introduction_section .= "
";
@@ -226,15 +236,19 @@ class Display
} else {
// Displays "edit intro && delete intro" commands
$introduction_section .= '
';
- //$url = $app['url_generator']->generate('introduction_edit', array('tool' => $moduleId));
- $url = api_get_path(WEB_PUBLIC_PATH).'introduction/edit/'.$tool;
+ $url = $urlGenerator->generate(
+ 'introduction.controller:editAction',
+ array('tool' => $tool, 'course' => api_get_course_id())
+ );
$introduction_section .= "
";
$introduction_section .= Display::return_icon('edit.png', get_lang('Modify')).' ';
$introduction_section .= "";
- //$url = $app['url_generator']->generate('introduction_delete', array('tool' => $moduleId));
- $url = api_get_path(WEB_PUBLIC_PATH).'introduction/delete/'.$tool;
+ $url = $urlGenerator->generate(
+ 'introduction.controller:deleteAction',
+ array('tool' => $tool, 'course' => api_get_course_id())
+ );
$introduction_section .= "
";
$introduction_section .= Display::return_icon('delete.png', get_lang('AddIntro')).' ';
@@ -814,9 +828,10 @@ class Display
/**
* Returns the htmlcode for an image
*
- * @param string $image the filename of the file (in the main/img/ folder
+ * @param string $image_path the filename of the file (in the main/img/ folder
* @param string $alt_text the alt text (probably a language variable)
* @param array additional attributes (for instance height, width, onclick, ...)
+ * @param bool $applyFilter
* @author Julio Montoya 2010
*/
public static function img($image_path, $alt_text = '', $additional_attributes = array(), $applyFilter = true)
diff --git a/main/inc/routes.php b/main/inc/routes.php
index 96afef2c13..208957c8c6 100644
--- a/main/inc/routes.php
+++ b/main/inc/routes.php
@@ -544,19 +544,6 @@ $app->match('/courses/{cidReq}/', 'course_home.controller:indexAction', 'GET|POS
->before($settingCourseConditions)
->before($userPermissionsInsideACourse);
-// Introduction
-$app->match('/introduction/edit/{tool}', 'introduction_tool.controller:editAction', 'GET|POST')
- ->assert('type', '.+')
- ->before($settingCourseConditions)
- ->before($userPermissionsInsideACourse)
- ->bind('introduction_edit');
-
-$app->match('/introduction/delete/{tool}', 'introduction_tool.controller:deleteAction', 'GET|POST')
- ->assert('type', '.+')
- ->before($settingCourseConditions)
- ->before($userPermissionsInsideACourse)
- ->bind('introduction_delete');
-
/** Course documents */
$app->get('/data/courses/{courseCode}/document/{file}', 'index.controller:getDocumentAction')
->assert('file', '.+')
@@ -569,6 +556,12 @@ $app->get('/data/courses/{courseCode}/scorm/{file}', 'index.controller:getScormD
->assert('type', '.+')
->bind('get_scorm_document');
+/** Course documents */
+$app->get('/data/courses/{courseCode}/upload/{file}', 'index.controller:getCourseUploadFileAction')
+ ->assert('file', '.+')
+ ->assert('type', '.+')
+ ->bind('getCourseUploadFileAction');
+
/** Certificates */
$app->match('/certificates/{id}', 'certificate.controller:indexAction', 'GET');
@@ -722,21 +715,27 @@ $app->match('/ajax', 'model_ajax.controller:indexAction', 'GET')
->bind('model_ajax');
if ($alreadyInstalled) {
- $app->mount('/admin/', new ChamiloLMS\Provider\ReflectionControllerProvider('admin.controller'));
- $app->mount('/admin/administrator/upgrade', new ChamiloLMS\Provider\ReflectionControllerProvider('upgrade.controller'));
- $app->mount('/admin/administrator/roles', new ChamiloLMS\Provider\ReflectionControllerProvider('role.controller'));
- $app->mount('/admin/administrator/question_scores', new ChamiloLMS\Provider\ReflectionControllerProvider('question_score.controller'));
- $app->mount('/admin/administrator/question_score_names', new ChamiloLMS\Provider\ReflectionControllerProvider('question_score_name.controller'));
-
- $app->mount('/editor/', new ChamiloLMS\Provider\ReflectionControllerProvider('editor.controller'));
- $app->mount('/user/', new ChamiloLMS\Provider\ReflectionControllerProvider('profile.controller'));
-
- $app->mount('/app/session_path', new ChamiloLMS\Provider\ReflectionControllerProvider('session_path.controller'));
- $app->mount('/app/session_path/tree', new ChamiloLMS\Provider\ReflectionControllerProvider('session_tree.controller'));
-
- $app->mount('/courses/{course}/curriculum/category', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum_category.controller'));
- $app->mount('/courses/{course}/curriculum/item', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum_item.controller'));
- $app->mount('/courses/{course}/curriculum/user', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum_user.controller'));
- $app->mount('/courses/{course}/curriculum', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum.controller'));
+ // Mount controllers.
+ $controllers = array(
+ '/admin/' => 'admin.controller',
+ '/admin/administrator/upgrade' => 'upgrade.controller',
+ '/admin/administrator/roles' => 'role.controller',
+ '/admin/administrator/question_scores' => 'question_score.controller',
+ '/admin/administrator/question_score_names' => 'question_score_name.controller',
+ '/editor/' => 'editor.controller',
+ '/user/' => 'profile.controller',
+ '/app/session_path' => 'session_path.controller',
+ '/app/session_path/tree' => 'session_tree.controller',
+ '/courses/{course}/curriculum/category' => 'curriculum_category.controller',
+ '/courses/{course}/curriculum/item' => 'curriculum_item.controller',
+ '/courses/{course}/curriculum/user' => 'curriculum_user.controller',
+ '/courses/{course}/curriculum' => 'curriculum.controller',
+ '/courses/{course}/course_home' => 'course_home.controller',
+ '/courses/{course}/introduction' => 'introduction.controller',
+ );
+
+ foreach ($controllers as $route => $controller) {
+ $app->mount($route, new ChamiloLMS\Provider\ReflectionControllerProvider($controller));
+ }
}
diff --git a/main/inc/services.php b/main/inc/services.php
index bb53503e41..c987e5fcf8 100644
--- a/main/inc/services.php
+++ b/main/inc/services.php
@@ -287,7 +287,7 @@ $app['form.extensions'] = $app->share($app->extend('form.extensions', function (
return $extensions;
}));
-// Needed to use the "UniqueEntity" validator
+// Needed to use the "UniqueEntity" validator.
$app['validator.validator_factory'] = $app->share(function ($app) {
$uniqueValidator = new Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator($app['manager_registry']);
$factory = new ChamiloLMS\Component\Validator\ConstraintValidatorFactory();
@@ -699,24 +699,6 @@ $app['learnpath.controller'] = $app->share(
}
);
-$app['course_home.controller'] = $app->share(
- function () use ($app) {
- return new ChamiloLMS\Controller\CourseHomeController();
- }
-);
-
-$app['course_home.controller'] = $app->share(
- function () use ($app) {
- return new ChamiloLMS\Controller\CourseHomeController();
- }
-);
-
-$app['introduction_tool.controller'] = $app->share(
- function () use ($app) {
- return new ChamiloLMS\Controller\IntroductionToolController();
- }
-);
-
$app['certificate.controller'] = $app->share(
function () use ($app) {
return new ChamiloLMS\Controller\CertificateController();
@@ -833,6 +815,18 @@ $app['upgrade.controller'] = $app->share(
}
);
+$app['course_home.controller'] = $app->share(
+ function () use ($app) {
+ return new ChamiloLMS\Controller\Tool\CourseHome\CourseHomeController($app);
+ }
+);
+
+$app['introduction.controller'] = $app->share(
+ function () use ($app) {
+ return new ChamiloLMS\Controller\Tool\Introduction\IntroductionController($app);
+ }
+);
+
$app['html_editor'] = $app->share(function($app) {
return new ChamiloLMS\Component\Editor\CkEditor\CkEditor($app['translator'], $app['url_generator'], $app['course']);
//return new ChamiloLMS\Component\Editor\TinyMce\TinyMce($app['translator'], $app['url_generator']);
diff --git a/main/template/default/layout/footer.tpl b/main/template/default/layout/footer.tpl
index 36c9f7365a..85bc7a6b44 100644
--- a/main/template/default/layout/footer.tpl
+++ b/main/template/default/layout/footer.tpl
@@ -144,6 +144,15 @@ $("form").on("click", ' .advanced_parameters', function() {
/** Makes row highlighting possible */
$(document).ready( function() {
+ $(function() {
+ $('a').tooltip({
+ placement: 'right',
+ show: 500,
+ hide: 500
+ });
+ });
+
+
$('.advanced_parameters').addClass('btn-default');
//$('.btn').addClass('btn-default');
diff --git a/main/template/default/tool/course_home/index.tpl b/main/template/default/tool/course_home/index.tpl
new file mode 100644
index 0000000000..561c2ed8c3
--- /dev/null
+++ b/main/template/default/tool/course_home/index.tpl
@@ -0,0 +1,97 @@
+{% extends app.template_style ~ "/layout/layout_1_col.tpl" %}
+{% block content %}
+
+
+
+
+
+

+ {{ 'PleaseStandBy' | trans }}
+
+
+
+
+
+{% if session_info %}
+
+
{{ 'SessionData' | trans }}
+
+
+{% endif %}
+
+{{ lp_warning }}
+{{ exercise_warning }}
+{{ introduction_text }}
+{{ edit_icons }}
+
+
+ {{ icons }}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/main/template/default/tool/course_home/tool/edit.tpl b/main/template/default/tool/course_home/tool/edit.tpl
new file mode 100644
index 0000000000..3dd02f0e11
--- /dev/null
+++ b/main/template/default/tool/course_home/tool/edit.tpl
@@ -0,0 +1,7 @@
+{% extends app.template_style ~ "/layout/layout_1_col.tpl" %}
+{% block content %}
+ {% import app.template_style ~ "/crud_macros/course_crud.tpl" as actions %}
+
+{% endblock %}
diff --git a/main/template/default/tool/course_home/tool/list.tpl b/main/template/default/tool/course_home/tool/list.tpl
new file mode 100644
index 0000000000..cb6de8583a
--- /dev/null
+++ b/main/template/default/tool/course_home/tool/list.tpl
@@ -0,0 +1,34 @@
+{% extends app.template_style ~ "/layout/layout_1_col.tpl" %}
+
+{% block content %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/src/ChamiloLMS/Component/DataFilesystem/DataFilesystem.php b/src/ChamiloLMS/Component/DataFilesystem/DataFilesystem.php
index 5f85e3579b..c083170f47 100644
--- a/src/ChamiloLMS/Component/DataFilesystem/DataFilesystem.php
+++ b/src/ChamiloLMS/Component/DataFilesystem/DataFilesystem.php
@@ -9,6 +9,7 @@ use Symfony\Component\Console;
/**
* @todo use Gaufrette to manage course files (some day)
+ * @todo add security restrictions.
* Class DataFilesystem
* @package ChamiloLMS\Component\DataFilesystem
*/
@@ -75,6 +76,18 @@ class DataFilesystem
return $this->get($file);
}
+ /**
+ * Gets a file from the data/courses/MATHS/document directory
+ * @param $courseCode
+ * @param $file
+ * @return SplFileInfo
+ */
+ public function getCourseUploadFile($courseCode, $file)
+ {
+ $file = 'courses/'.$courseCode.'/upload/'.$file;
+ return $this->get($file);
+ }
+
/**
* Create folders
* @param array $folderList
diff --git a/src/ChamiloLMS/Controller/BaseController.php b/src/ChamiloLMS/Controller/BaseController.php
index fb1908726d..72b9d20db3 100644
--- a/src/ChamiloLMS/Controller/BaseController.php
+++ b/src/ChamiloLMS/Controller/BaseController.php
@@ -151,6 +151,11 @@ abstract class BaseController extends FlintController
return $this->get('orm.em');
}
+ public function sendFile($file, $status = 200, $headers = array(), $contentDisposition = null)
+ {
+ return $this->pimple->sendFile($file, $status, $headers, $contentDisposition);
+ }
+
/**
* Converts an array of URL to absolute URLs using the url_generator service
* @param string $label
diff --git a/src/ChamiloLMS/Controller/CourseHomeController.php b/src/ChamiloLMS/Controller/CourseHomeController.php
deleted file mode 100644
index 13f8fc423e..0000000000
--- a/src/ChamiloLMS/Controller/CourseHomeController.php
+++ /dev/null
@@ -1,125 +0,0 @@
-
- */
-class CourseHomeController
-{
- public $language_files = array('course_home','courses');
-
- public function indexAction(Application $app, $cidReq, $idSession = null)
- {
- $extraJS = array();
- //@todo improve this JS includes should be added using twig
- $extraJS[] ='';
-
- $app['extraJS'] = $extraJS;
-
- //Needed because of this script:
- $course_code = $cidReq;
- $result = require_once api_get_path(SYS_CODE_PATH).'course_home/course_home.php';
- $app['template']->assign('content', $result['content']);
- $app['template']->assign('message', $result['message']);
-
- $response = $app['template']->renderLayout('layout_1_col.tpl');
- return new Response($response, 200, array());
- }
-
- /**
- * @param Application $app
- * @param $courseCode
- * @param $fileName
- * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
- */
- public function getFileAction(Application $app, $courseCode, $fileName)
- {
- $courseInfo = api_get_course_info($courseCode);
- $sessionId = $app['request']->get('id_session');
-
- $docId = \DocumentManager::get_document_id($courseInfo, "/".$fileName);
-
- $filePath = null;
-
- if ($docId) {
- $isVisible = \DocumentManager::is_visible_by_id($docId, $courseInfo, $sessionId, api_get_user_id());
- $documentData = \DocumentManager::get_document_data_by_id($docId, $courseCode);
- $filePath = $documentData['absolute_path'];
- event_download($filePath);
- }
-
- if (!api_is_allowed_to_edit() && !$isVisible) {
- $app->abort(500);
- }
- //DocumentManager::file_send_for_download($full_file_name);
- return $app->sendFile($filePath);
- }
-}
diff --git a/src/ChamiloLMS/Controller/IndexController.php b/src/ChamiloLMS/Controller/IndexController.php
index 0a7a59b7db..bf832f87ae 100644
--- a/src/ChamiloLMS/Controller/IndexController.php
+++ b/src/ChamiloLMS/Controller/IndexController.php
@@ -324,6 +324,24 @@ class IndexController extends CommonController
}
}
+ /**
+ * Gets a document from the data/courses/MATHS/document/file.jpg to the user
+ * @todo check permissions
+ * @param Application $app
+ * @param string $courseCode
+ * @param string $file
+ * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|void
+ */
+ public function getCourseUploadFileAction(Application $app, $courseCode, $file)
+ {
+ try {
+ $file = $app['chamilo.filesystem']->getCourseUploadFile($courseCode, $file);
+ return $app->sendFile($file->getPathname());
+ } catch (\InvalidArgumentException $e) {
+ return $app->abort(404, 'File not found');
+ }
+ }
+
/**
* Gets a document from the data/courses/MATHS/scorm/file.jpg to the user
* @todo check permissions
diff --git a/src/ChamiloLMS/Controller/Tool/CourseHome/CourseHomeController.php b/src/ChamiloLMS/Controller/Tool/CourseHome/CourseHomeController.php
new file mode 100644
index 0000000000..1f091af7f7
--- /dev/null
+++ b/src/ChamiloLMS/Controller/Tool/CourseHome/CourseHomeController.php
@@ -0,0 +1,469 @@
+
+ */
+class CourseHomeController extends CommonController
+{
+ /**
+ * @Route("/courses/{cidReq}/{sessionId}")
+ * @Method({"GET"})
+ *
+ * @param string $cidReq
+ * @param int $id_session
+ * @return Response
+ */
+ public function indexAction($cidReq, $id_session = null)
+ {
+ api_protect_course_script(true);
+
+ $courseCode = api_get_course_id();
+ $sessionId = api_get_session_id();
+ $userId = $this->getUser()->getUserId();
+
+ $coursesAlreadyVisited = $this->getRequest()->getSession()->get('coursesAlreadyVisited');
+
+ $result = $this->autolaunch();
+
+ $show_autolaunch_lp_warning = $result['show_autolaunch_lp_warning'];
+ $show_autolaunch_exercise_warning = $result['show_autolaunch_exercise_warning'];
+
+ if ($show_autolaunch_lp_warning) {
+ $this->getTemplate()->assign(
+ 'lp_warning',
+ Display::return_message(get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'), 'warning')
+ );
+ }
+ if ($show_autolaunch_exercise_warning) {
+ $this->getTemplate()->assign(
+ 'exercise_warning',
+ Display::return_message(get_lang('TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'), 'warning')
+ );
+ }
+
+ $editIcons = Display::url(
+ Display::return_icon('edit.png'),
+ $this->generateUrl('course_home.controller:iconListAction', array('course' => api_get_course_id()))
+ );
+ $this->getTemplate()->assign('edit_icons', $editIcons);
+
+
+ if (!isset($coursesAlreadyVisited[$courseCode])) {
+ event_access_course();
+ $coursesAlreadyVisited[$courseCode] = 1;
+ $this->getRequest()->getSession()->set('coursesAlreadyVisited', $coursesAlreadyVisited);
+ }
+
+ $introduction = Display::return_introduction_section(
+ $this->get('url_generator'),
+ TOOL_COURSE_HOMEPAGE,
+ array(
+ 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
+ 'CreateDocumentDir' => 'document/',
+ 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/'
+ )
+ );
+
+ $this->getTemplate()->assign('introduction_text', $introduction);
+ $this->getRequest()->getSession()->remove('toolgroup');
+ $this->getRequest()->getSession()->remove('_gid');
+
+ $isSpecialCourse = \CourseManager::is_special_course($courseCode);
+
+ if ($isSpecialCourse) {
+ $autoreg = $this->getRequest()->get('autoreg');
+ if ($autoreg == 1) {
+ \CourseManager::subscribe_user($userId, $courseCode, STUDENT);
+ }
+ }
+
+ $script = 'activity.php';
+ if (api_get_setting('homepage_view') == 'activity' || api_get_setting('homepage_view') == 'activity_big') {
+ $script = 'activity.php';
+ } elseif (api_get_setting('homepage_view') == '2column') {
+ $script = '2column.php';
+ } elseif (api_get_setting('homepage_view') == '3column') {
+ $script = '3column.php';
+ } elseif (api_get_setting('homepage_view') == 'vertical_activity') {
+ $script = 'vertical_activity.php';
+ }
+
+ $result = require_once api_get_path(SYS_CODE_PATH).'course_home/'.$script;
+ $this->getTemplate()->assign('icons', $result);
+
+ if (api_get_setting('show_session_data') == 'true' && $sessionId) {
+ $sessionInfo = \CourseHome::show_session_data($sessionId);
+ $this->getTemplate()->assign('session_info', $sessionInfo);
+ }
+
+ $response = $this->get('template')->render_template($this->getTemplatePath().'index.tpl');
+
+ return new Response($response, 200, array());
+ }
+
+ private function autolaunch()
+ {
+ $show_autolaunch_exercise_warning = false;
+
+ // Exercise auto-launch
+ $auto_launch = api_get_course_setting('enable_exercise_auto_launch');
+
+ if (!empty($auto_launch)) {
+ $session_id = api_get_session_id();
+ //Exercise list
+ if ($auto_launch == 2) {
+ if (api_is_platform_admin() || api_is_allowed_to_edit()) {
+ $show_autolaunch_exercise_warning = true;
+ } else {
+ $session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
+ if (!isset($_SESSION[$session_key])) {
+ //redirecting to the Exercise
+ $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&id_session='.$session_id;
+ $_SESSION[$session_key] = true;
+ header("Location: $url");
+ exit;
+ }
+ }
+ } else {
+ $table = Database::get_course_table(TABLE_QUIZ_TEST);
+ $course_id = api_get_course_int_id();
+ $condition = '';
+ if (!empty($session_id)) {
+ $condition = api_get_session_condition($session_id);
+ $sql = "SELECT iid FROM $table WHERE c_id = $course_id AND autolaunch = 1 $condition LIMIT 1";
+ $result = Database::query($sql);
+ //If we found nothing in the session we just called the session_id = 0 autolaunch
+ if (Database::num_rows($result) == 0) {
+ $condition = '';
+ } else {
+ //great, there is an specific auto lunch for this session we leave the $condition
+ }
+ }
+
+ $sql = "SELECT iid FROM $table WHERE c_id = $course_id AND autolaunch = 1 $condition LIMIT 1";
+ $result = Database::query($sql);
+ if (Database::num_rows($result) > 0) {
+ $data = Database::fetch_array($result,'ASSOC');
+ if (!empty($data['iid'])) {
+ if (api_is_platform_admin() || api_is_allowed_to_edit()) {
+ $show_autolaunch_exercise_warning = true;
+ } else {
+ $session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
+ if (!isset($_SESSION[$session_key])) {
+ //redirecting to the LP
+ $url = api_get_path(WEB_CODE_PATH).'exercice/overview.php?'.api_get_cidreq().'&exerciseId='.$data['iid'];
+
+ $_SESSION[$session_key] = true;
+ header("Location: $url");
+ exit;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* Auto launch code */
+ $show_autolaunch_lp_warning = false;
+ $auto_launch = api_get_course_setting('enable_lp_auto_launch');
+ if (!empty($auto_launch)) {
+ $session_id = api_get_session_id();
+ //LP list
+ if ($auto_launch == 2) {
+ if (api_is_platform_admin() || api_is_allowed_to_edit()) {
+ $show_autolaunch_lp_warning = true;
+ } else {
+ $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
+ if (!isset($_SESSION[$session_key])) {
+ //redirecting to the LP
+ $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
+ $_SESSION[$session_key] = true;
+ header("Location: $url");
+ exit;
+ }
+ }
+ } else {
+ $lp_table = Database::get_course_table(TABLE_LP_MAIN);
+ $course_id = api_get_course_int_id();
+ $condition = '';
+ if (!empty($session_id)) {
+ $condition = api_get_session_condition($session_id);
+ $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
+ $result = Database::query($sql);
+ //If we found nothing in the session we just called the session_id = 0 autolunch
+ if (Database::num_rows($result) == 0) {
+ $condition = '';
+ } else {
+ //great, there is an specific auto lunch for this session we leave the $condition
+ }
+ }
+
+ $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
+ $result = Database::query($sql);
+ if (Database::num_rows($result) > 0) {
+ $lp_data = Database::fetch_array($result,'ASSOC');
+ if (!empty($lp_data['id'])) {
+ if (api_is_platform_admin() || api_is_allowed_to_edit()) {
+ $show_autolaunch_lp_warning = true;
+ } else {
+ $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
+ if (!isset($_SESSION[$session_key])) {
+ //redirecting to the LP
+ $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
+
+ $_SESSION[$session_key] = true;
+ header("Location: $url");
+ exit;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return array(
+ 'show_autolaunch_exercise_warning' => $show_autolaunch_exercise_warning,
+ 'show_autolaunch_lp_warning' => $show_autolaunch_lp_warning
+ );
+ }
+
+ /**
+ * @param string $courseCode
+ * @param string $fileName
+ * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
+ */
+ public function getFileAction($courseCode, $fileName)
+ {
+ $courseInfo = api_get_course_info($courseCode);
+ $sessionId = $this->getRequest()->get('id_session');
+
+ $docId = \DocumentManager::get_document_id($courseInfo, "/".$fileName);
+
+ $filePath = null;
+
+ if ($docId) {
+ $isVisible = \DocumentManager::is_visible_by_id($docId, $courseInfo, $sessionId, api_get_user_id());
+ $documentData = \DocumentManager::get_document_data_by_id($docId, $courseCode);
+ $filePath = $documentData['absolute_path'];
+ event_download($filePath);
+ }
+
+ if (!api_is_allowed_to_edit() && !$isVisible) {
+ $this->abort(500);
+ }
+ return $this->sendFile($filePath);
+ }
+
+ /**
+ * @Route("/show/{iconId}")
+ * @Method({"GET"})
+ * @param $iconId
+ * @return null|string
+ */
+ public function showIconAction($iconId)
+ {
+ if (!api_is_allowed_to_edit(null, true)) {
+ return null;
+ }
+ $entityManager = $this->getManager();
+ $criteria = array('cId' => api_get_course_int_id(), 'id' => $iconId);
+ $tool = $this->getRepository('Entity\CTool')->findOneBy($criteria);
+ if ($tool) {
+ $tool->setVisibility(1);
+ }
+ $entityManager->persist($tool);
+ //$entityManager->flush();
+ return Display::return_message(get_lang('Visible'), 'confirmation');
+ }
+
+ /**
+ * @Route("/hide/{iconId}")
+ * @Method({"GET"})
+ * @param $iconId
+ * @return null|string
+ */
+ public function hideIconAction($iconId)
+ {
+ if (!api_is_allowed_to_edit(null, true)) {
+ return null;
+ }
+
+ $entityManager = $this->getManager();
+ $criteria = array('cId' => api_get_course_int_id(), 'id' => $iconId);
+ $tool = $this->getRepository('Entity\CTool')->findOneBy($criteria);
+ if ($tool) {
+ $tool->setVisibility(0);
+ }
+ $entityManager->persist($tool);
+ //$entityManager->flush();
+ return Display::return_message(get_lang('ToolIsNowHidden'), 'confirmation');
+ }
+
+ /**
+ * @Route("/delete/{iconId}")
+ * @Method({"GET"})
+ * @param $iconId
+ * @return null|string
+ */
+ public function deleteIcon($iconId)
+ {
+ if (!api_is_allowed_to_edit(null, true)) {
+ return null;
+ }
+
+ $entityManager = $this->getManager();
+ $criteria = array('cId' => api_get_course_int_id(), 'id' => $iconId, 'added_tool' => 1);
+ $tool = $this->getRepository('Entity\CTool')->findOneBy($criteria);
+ $entityManager->remove($tool);
+ //$entityManager->flush();
+ return Display::return_message(get_lang('Deleted'), 'confirmation');
+ }
+
+ /**
+ * @Route("/icon_list")
+ * @Method({"GET"})
+ */
+ public function iconListAction()
+ {
+ $criteria = array('cId' => $this->getCourse()->getId(), 'sessionId' => 0);
+ $items = $this->getRepository()->findBy($criteria);
+
+ $this->getTemplate()->assign('items', $items);
+ $this->getTemplate()->assign('links', $this->generateLinks());
+ return $this->get('template')->render_template($this->getTemplatePath().'tool/list.tpl');
+ }
+
+ /**
+ * @Route("/{itemId}/edit")
+ * @Method({"GET"})
+ */
+ public function editIconAction($itemId)
+ {
+ $sessionId = $this->getRequest()->get('id_session');
+
+ $criteria = array('cId' => $this->getCourse()->getId(), 'sessionId' => 0, 'id' => $itemId);
+ /** @var CTool $item */
+ $item = $this->getRepository()->findOneBy($criteria);
+ $item->setSessionId($sessionId);
+
+ $form = $this->createForm($this->getFormType(), $item);
+ $form->handleRequest($this->getRequest());
+
+ if ($form->isValid()) {
+ $sessionId = $item->getSessionId();
+ $entityManager = $this->getManager();
+
+ if (!empty($sessionId)) {
+ $criteria = array('cId' => $this->getCourse()->getId(), 'sessionId' => $sessionId, 'id' => $itemId);
+ /** @var CTool $item */
+ $itemFromDb = $this->getRepository()->findOneBy($criteria);
+ if (empty($itemFromDb)) {
+ $newTool = clone $item;
+
+ $query = $this->getManager()->createQueryBuilder('a');
+ $query->select('MAX(s.id) as id');
+ $query->from('Entity\CTool', 's');
+ $query->where('s.cId = :courseId')->setParameter('courseId', $this->getCourse()->getId());
+ $result = $query->getQuery()->getArrayResult();
+ $maxId = $result[0]['id'] + 1;
+ $newTool->setId($maxId);
+ } else {
+ $newTool = $item;
+ }
+ $entityManager->persist($newTool);
+ } else {
+ $entityManager->persist($item);
+ }
+
+ $entityManager->flush();
+
+ if (!empty($item->getCustomIcon())) {
+ $item->createGrayIcon($this->get('imagine'));
+ }
+
+ $this->get('session')->getFlashBag()->add('success', "Updated");
+ $url = $this->generateUrl('course_home.controller:iconListAction');
+ return $this->redirect($url);
+ }
+
+ $this->getTemplate()->assign('item', $item);
+ $this->getTemplate()->assign('form', $form->createView());
+ $this->getTemplate()->assign('links', $this->generateLinks());
+ return $this->get('template')->render_template($this->getTemplatePath().'tool/edit.tpl');
+ }
+
+ /**
+ * @Route("/{itemId}/delete")
+ * @Method({"GET"})
+ */
+ public function deleteIconAction($itemId)
+ {
+ $criteria = array('cId' => $this->getCourse()->getId(), 'sessionId' => 0, 'id' => $itemId);
+ /** @var CTool $item */
+ $item = $this->getRepository()->findOneBy($criteria);
+
+ $item->setCustomIcon(null);
+
+ $entityManager = $this->getManager();
+ $entityManager->persist($item);
+ $entityManager->flush();
+
+ $this->get('session')->getFlashBag()->add('success', "Deleted");
+
+ $this->getTemplate()->assign('links', $this->generateLinks());
+ $url = $this->generateUrl('course_home.controller:iconListAction');
+ return $this->redirect($url);
+ }
+
+ protected function getControllerAlias()
+ {
+ return 'course_home.controller';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getTemplatePath()
+ {
+ return 'tool/course_home/';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getRepository()
+ {
+ return $this->get('orm.em')->getRepository('Entity\CTool');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getNewEntity()
+ {
+ return new CTool();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getFormType()
+ {
+ return new CourseHomeToolType();
+ }
+
+}
diff --git a/src/ChamiloLMS/Controller/IntroductionToolController.php b/src/ChamiloLMS/Controller/Tool/Introduction/IntroductionController.php
similarity index 57%
rename from src/ChamiloLMS/Controller/IntroductionToolController.php
rename to src/ChamiloLMS/Controller/Tool/Introduction/IntroductionController.php
index fd4fdb173c..79b47ccc9c 100644
--- a/src/ChamiloLMS/Controller/IntroductionToolController.php
+++ b/src/ChamiloLMS/Controller/Tool/Introduction/IntroductionController.php
@@ -1,40 +1,51 @@
*/
-class IntroductionToolController
+class IntroductionController extends CommonController
{
/**
- * @param Application $app
+ * @Route("/edit/{tool}")
+ * @Method({"GET"})
+ *
* @param string $tool
* @return Response
*/
- public function editAction(Application $app, $tool)
+ public function editAction($tool)
{
$message = null;
- $request = $app['request'];
- $courseId = $request->get('courseId');
- $sessionId = $request->get('sessionId');
+ // @todo use proper functions not api functions.
+ $courseId = api_get_course_int_id();
+ $sessionId = api_get_session_id();
$tool = \Database::escape_string($tool);
$TBL_INTRODUCTION = \Database::get_course_table(TABLE_TOOL_INTRO);
- $url = $app['url_generator']->generate('introduction_edit', array('tool' => $tool)).'?'.api_get_cidreq();
+ $url = $this->generateUrl(
+ 'introduction.controller:editAction',
+ array('tool' => $tool, 'course' => api_get_course_id())
+ );
+
$form = $this->getForm($url);
+
if ($form->validate()) {
$values = $form->exportValues();
$content = $values['content'];
- $sql = "REPLACE $TBL_INTRODUCTION SET c_id = $courseId, id='$tool', intro_text='".\Database::escape_string($content)."', session_id='".intval($sessionId)."'";
+ $sql = "REPLACE $TBL_INTRODUCTION
+ SET c_id = $courseId, id='$tool', intro_text='".\Database::escape_string($content)."', session_id='".intval($sessionId)."'";
\Database::query($sql);
$message = \Display::return_message(get_lang('IntroductionTextUpdated'), 'confirmation', false);
} else {
@@ -50,35 +61,41 @@ class IntroductionToolController
$form->setDefaults(array('content' => $content));
}
- $app['template']->assign('content', $form->return_form());
- $app['template']->assign('message', $message);
- $response = $app['template']->renderLayout('layout_1_col.tpl');
+ $this->getTemplate()->assign('content', $form->return_form());
+ $this->getTemplate()->assign('message', $message);
+ $response = $this->getTemplate()->renderLayout('layout_1_col.tpl');
return new Response($response, 200, array());
}
/**
- * @param Application $app
+ * @Route("/delete/{tool}")
+ * @Method({"GET"})
+ *
* @param string $tool
* @return Response
*/
- public function deleteAction(Application $app, $tool)
+ public function deleteAction($tool)
{
- /** @var \Request $request */
- $request = $app['request'];
+ $request = $this->getRequest();
$courseId = $request->get('courseId');
$sessionId = $request->get('sessionId');
$tool = \Database::escape_string($tool);
$TBL_INTRODUCTION = \Database::get_course_table(TABLE_TOOL_INTRO);
- \Database::query("DELETE FROM $TBL_INTRODUCTION WHERE c_id = $courseId AND id='".$tool."' AND session_id='".intval($sessionId)."'");
+ \Database::query("DELETE FROM $TBL_INTRODUCTION
+ WHERE c_id = $courseId AND id='".$tool."' AND session_id='".intval($sessionId)."'");
$message = \Display::return_message(get_lang('IntroductionTextDeleted'), 'confirmation');
- $url = $app['url_generator']->generate('introduction_edit', array('tool' => $tool)).'?'.api_get_cidreq();
+ $url = $this->generateUrl(
+ 'introduction.controller:editAction',
+ array('tool' => $tool, 'course' => api_get_course_id())
+ );
+
$form = $this->getForm($url);
- $app['template']->assign('content', $form->return_form());
- $app['template']->assign('message', $message);
- $response = $app['template']->renderLayout('layout_1_col.tpl');
+ $this->getTemplate()->assign('content', $form->return_form());
+ $this->getTemplate()->assign('message', $message);
+ $response = $this->getTemplate()->renderLayout('layout_1_col.tpl');
return new Response($response, 200, array());
}
diff --git a/src/ChamiloLMS/Form/CourseHomeToolType.php b/src/ChamiloLMS/Form/CourseHomeToolType.php
new file mode 100644
index 0000000000..a797055958
--- /dev/null
+++ b/src/ChamiloLMS/Form/CourseHomeToolType.php
@@ -0,0 +1,48 @@
+add('name', 'text');
+ $builder->add('link', 'text');
+ $builder->add(
+ 'custom_icon',
+ 'file',
+ array('required' => false, 'data_class' => null)
+ );
+ $builder->add('target', 'choice', array('choices' => array('_self', '_blank')));
+ $builder->add('visibility', 'choice', array('choices' => array('1', '0')));
+ $builder->add('c_id', 'hidden');
+ $builder->add('session_id', 'hidden');
+
+ $builder->add('description', 'textarea');
+ $builder->add('submit', 'submit');
+ }
+
+ public function setDefaultOptions(OptionsResolverInterface $resolver)
+ {
+ $resolver->setDefaults(
+ array(
+ 'data_class' => 'Entity\CTool'
+ )
+ );
+ }
+
+ public function getName()
+ {
+ return 'courseHomeTool';
+ }
+}