routes.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Symfony\Component\HttpFoundation\Request;
  4. use \ChamiloSession as Session;
  5. /* can't mount */
  6. $settingNewCourseConditions = function (Request $request) use ($cidReset, $app) {
  7. // The course parameter is loaded
  8. $course = $request->get('cidReq');
  9. // Converting /courses/XXX/ to a Entity/Course object
  10. /** @var Entity\Course $course */
  11. $course = $app['orm.em']->getRepository('Entity\Course')->findOneByCode($course);
  12. if ($course) {
  13. $app['course'] = $course;
  14. $app['template']->assign('course', $course);
  15. Session::write('_real_cid', $course->getId());
  16. Session::write('_cid', $course->getCode());
  17. $courseInfo = api_get_course_info($course->getCode());
  18. Session::write('_course', $courseInfo);
  19. }
  20. $sessionId = $request->get('id_session');
  21. $session = $app['orm.em']->getRepository('Entity\Session')->findOneById($sessionId);
  22. /** @var Entity\Session $session*/
  23. if ($session) {
  24. $app['course_session'] = $session;
  25. $app['template']->assign('course_session', $session);
  26. Session::write('id_session', $session->getId());
  27. }
  28. };
  29. /** Setting course session and group global values */
  30. $settingCourseConditions = function (Request $request) use ($cidReset, $app) {
  31. $cidReq = $request->get('cidReq');
  32. $sessionId = $request->get('id_session');
  33. $groupId = $request->get('gidReq');
  34. $tempCourseId = api_get_course_id();
  35. $tempGroupId = api_get_group_id();
  36. $tempSessionId = api_get_session_id();
  37. $courseReset = false;
  38. $sessionReset = false;
  39. $groupReset = false;
  40. if ((!empty($cidReq) && $tempCourseId != $cidReq) || empty($tempCourseId) || empty($tempCourseId) == -1) {
  41. $courseReset = true;
  42. }
  43. if (isset($cidReset) && $cidReset == 1) {
  44. $courseReset = true;
  45. $sessionReset = true;
  46. $groupReset = true;
  47. }
  48. Session::write('courseReset', $courseReset);
  49. if ($tempGroupId != $groupId || empty($tempGroupId)) {
  50. $groupReset = true;
  51. }
  52. if ($tempSessionId != $sessionId || empty($tempSessionId)) {
  53. $sessionReset = true;
  54. }
  55. if ($courseReset) {
  56. if (!empty($cidReq) && $cidReq != -1) {
  57. $courseInfo = api_get_course_info($cidReq, true, true);
  58. if (!empty($courseInfo)) {
  59. $courseCode = $courseInfo['code'];
  60. $courseId = $courseInfo['real_id'];
  61. Session::write('_real_cid', $courseId);
  62. Session::write('_cid', $courseCode);
  63. Session::write('_course', $courseInfo);
  64. } else {
  65. $app->abort(404, 'Course not available');
  66. }
  67. } else {
  68. Session::erase('_real_cid');
  69. Session::erase('_cid');
  70. Session::erase('_course');
  71. Session::erase('session_name');
  72. Session::erase('id_session');
  73. Session::erase('_gid');
  74. }
  75. }
  76. $courseCode = api_get_course_id();
  77. if (!empty($courseCode) && $courseCode != -1) {
  78. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  79. $time = api_get_utc_datetime();
  80. $sql = "UPDATE $tbl_course SET last_visit= '$time' WHERE code='$courseCode'";
  81. Database::query($sql);
  82. }
  83. if ($sessionReset) {
  84. Session::erase('session_name');
  85. Session::erase('id_session');
  86. if (!empty($sessionId)) {
  87. $sessionInfo = api_get_session_info($sessionId);
  88. if (empty($sessionInfo)) {
  89. $app->abort(404, 'Session not available');
  90. } else {
  91. Session::write('id_session', $sessionId);
  92. }
  93. }
  94. }
  95. if ($groupReset) {
  96. Session::erase('_gid');
  97. if (!empty($groupId)) {
  98. Session::write('_gid', $groupId);
  99. }
  100. }
  101. // @todo fix login_as
  102. if (!isset($_SESSION['login_as'])) {
  103. $userId = api_get_user_id();
  104. // Course login
  105. if (isset($userId)) {
  106. event_course_login(api_get_course_int_id(), $userId, api_get_session_id());
  107. }
  108. }
  109. };
  110. $userCourseAdmin = function(Request $request) use ($app) {
  111. if (api_is_allowed_to_edit()) {
  112. return null;
  113. } else {
  114. return $app->abort(401);
  115. }
  116. };
  117. /** Checks user permissions inside a course teacher? coach? etc */
  118. $userPermissionsInsideACourse = function (Request $request) use ($app) {
  119. $courseId = api_get_course_int_id();
  120. $userId = api_get_user_id();
  121. $sessionId = api_get_session_id();
  122. //If I'm the admin platform i'm a teacher of the course
  123. $is_platformAdmin = api_is_platform_admin();
  124. $courseReset = Session::read('courseReset');
  125. //$app['monolog']->addDebug($courseReset);
  126. //$app['monolog']->addDebug($courseId);
  127. // Course
  128. $is_courseMember = false;
  129. $is_courseAdmin = false;
  130. $is_courseTutor = false;
  131. $is_courseCoach = false;
  132. $is_sessionAdmin = false;
  133. if ($courseReset) {
  134. if (isset($courseId) && $courseId && $courseId != -1) {
  135. $courseInfo = api_get_course_info();
  136. $userId = isset($userId) ? intval($userId) : 0;
  137. $variable = 'accept_legal_'.$userId.'_'.$courseInfo['real_id'].'_'.$sessionId;
  138. $user_pass_open_course = false;
  139. if (api_check_user_access_to_legal($courseInfo['visibility']) && Session::read($variable)) {
  140. $user_pass_open_course = true;
  141. }
  142. //Checking if the user filled the course legal agreement
  143. if ($courseInfo['activate_legal'] == 1 && !api_is_platform_admin()) {
  144. $user_is_subscribed = CourseManager::is_user_accepted_legal(
  145. $userId,
  146. $courseInfo,
  147. $sessionId
  148. ) || $user_pass_open_course;
  149. if (!$user_is_subscribed) {
  150. $url = api_get_path(WEB_CODE_PATH).'course_info/legal.php?course_code='.$courseInfo['code'].'&session_id='.$sessionId;
  151. header('Location: '.$url);
  152. exit;
  153. }
  154. }
  155. //Check if user is subscribed in a course
  156. $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  157. $sql = "SELECT * FROM $course_user_table
  158. WHERE
  159. user_id = '".$userId."' AND
  160. relation_type <> ".COURSE_RELATION_TYPE_RRHH." AND
  161. c_id = ".$courseId;
  162. $result = Database::query($sql);
  163. $cuData = null;
  164. if (Database::num_rows($result) > 0) { // this user have a recorded state for this course
  165. $cuData = Database::fetch_array($result, 'ASSOC');
  166. $is_courseAdmin = (bool)($cuData['status'] == 1);
  167. $is_courseTutor = (bool)($cuData['tutor_id'] == 1);
  168. $is_courseMember = true;
  169. $_courseUser['role'] = $cuData['role'];
  170. Session::write('_courseUser', $_courseUser);
  171. }
  172. //We are in a session course? Check session permissions
  173. if (!empty($sessionId)) {
  174. //I'm not the teacher of the course
  175. if ($is_courseAdmin == false) {
  176. // this user has no status related to this course
  177. // The user is subscribed in a session? The user is a Session coach a Session admin ?
  178. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  179. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  180. //Session coach, session admin, course coach admin
  181. $sql = "SELECT session.id_coach, session_admin_id, session_rcru.id_user
  182. FROM $tbl_session session, $tbl_session_course_user session_rcru
  183. WHERE session_rcru.id_session = session.id AND
  184. session_rcru.c_id = ".$courseInfo['real_id']." AND
  185. session_rcru.id_user = $userId AND
  186. session_rcru.id_session = $sessionId AND
  187. session_rcru.status = 2 ";
  188. $result = Database::query($sql);
  189. $row = Database::store_result($result);
  190. //I'm a session admin?
  191. if (isset($row) && isset($row[0]) && $row[0]['session_admin_id'] == $userId) {
  192. $_courseUser['role'] = 'Professor';
  193. $is_courseMember = false;
  194. $is_courseTutor = false;
  195. $is_courseAdmin = false;
  196. $is_courseCoach = false;
  197. $is_sessionAdmin = true;
  198. } else {
  199. //Im a coach or a student?
  200. $sql = "SELECT cu.id_user, cu.status FROM $tbl_session_course_user cu
  201. WHERE c_id = '$courseId' AND
  202. cu.id_user = '".$userId."' AND
  203. cu.id_session = '".$sessionId."'
  204. LIMIT 1";
  205. $result = Database::query($sql);
  206. if (Database::num_rows($result)) {
  207. $row = Database::fetch_array($result, 'ASSOC');
  208. $session_course_status = $row['status'];
  209. switch ($session_course_status) {
  210. case '2': // coach - teacher
  211. $_courseUser['role'] = 'Professor';
  212. $is_courseMember = true;
  213. $is_courseTutor = true;
  214. $is_courseCoach = true;
  215. $is_sessionAdmin = false;
  216. if (api_get_setting('extend_rights_for_coach') == 'true') {
  217. $is_courseAdmin = true;
  218. } else {
  219. $is_courseAdmin = false;
  220. }
  221. Session::write('_courseUser', $_courseUser);
  222. break;
  223. case '0': //Student
  224. $_courseUser['role'] = '';
  225. $is_courseMember = true;
  226. $is_courseTutor = false;
  227. $is_courseAdmin = false;
  228. $is_courseCoach = false;
  229. $is_sessionAdmin = false;
  230. Session::write('_courseUser', $_courseUser);
  231. break;
  232. default:
  233. // Un-register user
  234. $_courseUser['role'] = '';
  235. $is_courseMember = false;
  236. $is_courseTutor = false;
  237. $is_courseAdmin = false;
  238. $is_sessionAdmin = false;
  239. $is_courseCoach = false;
  240. Session::erase('_courseUser');
  241. break;
  242. }
  243. } else {
  244. // Un-register user
  245. $is_courseMember = false;
  246. $is_courseTutor = false;
  247. $is_courseAdmin = false;
  248. $is_sessionAdmin = false;
  249. $is_courseCoach = false;
  250. Session::erase('_courseUser');
  251. }
  252. }
  253. }
  254. if ($is_platformAdmin) {
  255. $is_courseAdmin = true;
  256. }
  257. }
  258. }
  259. // Checking the course access
  260. $is_allowed_in_course = false;
  261. if (isset($courseInfo)) {
  262. switch ($courseInfo['visibility']) {
  263. case COURSE_VISIBILITY_OPEN_WORLD: // 3
  264. $is_allowed_in_course = true;
  265. break;
  266. case COURSE_VISIBILITY_OPEN_PLATFORM: // 2
  267. if (isset($userId) && !api_is_anonymous($userId)) {
  268. $is_allowed_in_course = true;
  269. }
  270. break;
  271. case COURSE_VISIBILITY_REGISTERED: // 1
  272. if ($is_platformAdmin || $is_courseMember) {
  273. $is_allowed_in_course = true;
  274. }
  275. break;
  276. case COURSE_VISIBILITY_CLOSED: // 0
  277. if ($is_platformAdmin || $is_courseAdmin) {
  278. $is_allowed_in_course = true;
  279. }
  280. break;
  281. }
  282. }
  283. if (!$is_platformAdmin) {
  284. if (!$is_courseMember && isset($courseInfo['registration_code']) && !empty($courseInfo['registration_code'])) {
  285. $is_courseMember = false;
  286. $is_courseAdmin = false;
  287. $is_courseTutor = false;
  288. $is_courseCoach = false;
  289. $is_sessionAdmin = false;
  290. $is_allowed_in_course = false;
  291. }
  292. }
  293. // check the session visibility
  294. if ($is_allowed_in_course == true) {
  295. //if I'm in a session
  296. if ($sessionId != 0) {
  297. if (!$is_platformAdmin) {
  298. // admin is not affected to the invisible session mode
  299. $session_visibility = api_get_session_visibility($sessionId);
  300. switch ($session_visibility) {
  301. case SESSION_INVISIBLE:
  302. $is_allowed_in_course = false;
  303. break;
  304. }
  305. }
  306. }
  307. }
  308. // save the states
  309. Session::write('is_courseAdmin', $is_courseAdmin);
  310. Session::write('is_courseMember', $is_courseMember);
  311. Session::write('is_courseTutor', $is_courseTutor);
  312. Session::write('is_courseCoach', $is_courseCoach);
  313. Session::write('is_allowed_in_course', $is_allowed_in_course);
  314. Session::write('is_sessionAdmin', $is_sessionAdmin);
  315. }
  316. };
  317. /**
  318. * Deletes the exam_password user extra field *only* to students
  319. * @todo move to the login hook system
  320. * @param Request $request
  321. */
  322. $afterLogin = function (Request $request) use ($app) {
  323. if (isset($app['current_user']) && isset($app['current_user']['user_id']) && $app['current_user']['status'] == STUDENT) {
  324. $extraField = new ExtraField('user');
  325. $extraFieldData = $extraField->get_handler_field_info_by_field_variable('exam_password');
  326. if ($extraFieldData && !empty($extraFieldData)) {
  327. $extraField = new ExtraFieldValue('user');
  328. $extraFieldValue = $extraField->get_values_by_handler_and_field_variable($app['current_user']['user_id'], 'exam_password');
  329. if (!empty($extraFieldValue)) {
  330. $extraField->delete_values_by_handler_and_field_id($app['current_user']['user_id'], $extraFieldValue['id']);
  331. }
  332. }
  333. }
  334. };
  335. $removeCidReset = function (Request $request) use ($app) {
  336. // Deleting course info.
  337. Session::erase('_cid');
  338. Session::erase('_real_cid');
  339. Session::erase('_course');
  340. if (!empty($_SESSION)) {
  341. foreach ($_SESSION as $key => $item) {
  342. if (strpos($key, 'lp_autolunch_') === false) {
  343. continue;
  344. } else {
  345. if (isset($_SESSION[$key])) {
  346. Session::erase($key);
  347. }
  348. }
  349. }
  350. }
  351. // Deleting session info.
  352. Session::erase('id_session');
  353. Session::erase('session_name');
  354. // Deleting group info.
  355. Session::erase('_gid');
  356. };
  357. $removeCidResetDependingOfSection = function (Request $request) use ($app, $removeCidReset) {
  358. $file = $request->get('file');
  359. if (!empty($file)) {
  360. $info = pathinfo($file);
  361. $section = $info['dirname'];
  362. if ($section == 'admin') {
  363. $removeCidReset($request);
  364. }
  365. }
  366. };
  367. /** / and /index paths */
  368. $app->match('/', 'index.controller:indexAction', 'GET')
  369. ->assert('type', '.+') //allowing slash "/"
  370. ->before($removeCidReset)
  371. ->after($afterLogin);
  372. $app->match('/index', 'index.controller:indexAction', 'GET')
  373. ->before($removeCidReset)
  374. ->after($afterLogin)
  375. ->bind('index');
  376. /** Userportal */
  377. $app->get('/userportal', 'userPortal.controller:indexAction')
  378. ->before($removeCidReset);
  379. $app->get('/userportal/{type}/{filter}/{page}', 'userPortal.controller:indexAction')
  380. ->before($removeCidReset)
  381. ->value('type', 'courses') //default values
  382. ->value('filter', 'current')
  383. ->value('page', '1')
  384. ->bind('userportal');
  385. /** main files */
  386. $app->match('/main/{file}', 'legacy.controller:classicAction', 'GET|POST')
  387. ->before($removeCidResetDependingOfSection)
  388. ->before($settingCourseConditions)
  389. ->before(
  390. function() use ($app) {
  391. // Do not load breadcrumbs
  392. $app['template']->loadBreadcrumb = false;
  393. })
  394. ->assert('file', '.+')
  395. ->assert('type', '.+');
  396. /** Login form */
  397. $app->match('/login', 'index.controller:loginAction', 'GET|POST')
  398. ->bind('login');
  399. /** Course home instead of courses/MATHS the new URL is web/courses/MATHS */
  400. $app->match('/courses/{cidReq}/{id_session}/', 'course_home.controller:indexAction', 'GET|POST')
  401. ->assert('id_session', '\d+')
  402. ->assert('type', '.+')
  403. ->before($settingCourseConditions)
  404. ->before($userPermissionsInsideACourse)
  405. ->bind('course');
  406. $app->match('/courses/{cidReq}', 'course_home.controller:indexAction', 'GET|POST')
  407. ->assert('type', '.+')
  408. ->before($settingCourseConditions)
  409. ->before($userPermissionsInsideACourse);
  410. // @todo this is the same as above but with out slash (otherwise we will have an httpexception)
  411. $app->match('/courses/{cidReq}/', 'course_home.controller:indexAction', 'GET|POST')
  412. ->assert('type', '.+')
  413. ->before($settingCourseConditions)
  414. ->before($userPermissionsInsideACourse);
  415. // Introduction
  416. $app->match('/introduction/edit/{tool}', 'introduction_tool.controller:editAction', 'GET|POST')
  417. ->assert('type', '.+')
  418. ->before($settingCourseConditions)
  419. ->before($userPermissionsInsideACourse)
  420. ->bind('introduction_edit');
  421. $app->match('/introduction/delete/{tool}', 'introduction_tool.controller:deleteAction', 'GET|POST')
  422. ->assert('type', '.+')
  423. ->before($settingCourseConditions)
  424. ->before($userPermissionsInsideACourse)
  425. ->bind('introduction_delete');
  426. /** Course documents */
  427. $app->get('/data/courses/{courseCode}/document/{file}', 'index.controller:getDocumentAction')
  428. ->assert('file', '.+')
  429. ->assert('type', '.+');
  430. /** Scorm documents */
  431. $app->get('/data/courses/{courseCode}/scorm/{file}', 'index.controller:getScormDocumentAction')
  432. ->assert('file', '.+')
  433. ->assert('type', '.+');
  434. /** Certificates */
  435. $app->match('/certificates/{id}', 'certificate.controller:indexAction', 'GET');
  436. /** Username */
  437. $app->match('/user/{username}', 'user.controller:indexAction', 'GET');
  438. /** Who is online */
  439. /*$app->match('/users/online', 'user.controller:onlineAction', 'GET');
  440. $app->match('/users/online-in-course', 'user.controller:onlineInCourseAction', 'GET');
  441. $app->match('/users/online-in-session', 'user.controller:onlineInSessionAction', 'GET');*/
  442. /** Portal news */
  443. $app->match('/news/{id}', 'news.controller:indexAction', 'GET')
  444. ->bind('portal_news');
  445. /** LP controller (subscribe users to a LP) */
  446. $app->match('/learnpath/subscribe_users/{lpId}', 'learnpath.controller:indexAction', 'GET|POST')
  447. ->bind('subscribe_users');
  448. /** Data document_templates files */
  449. $app->get('/data/document_templates/{file}', 'index.controller:getDocumentTemplateAction')
  450. ->bind('data');
  451. /** Data default_platform_document files */
  452. $app->get('/data/default_platform_document/{file}', 'index.controller:getDefaultPlatformDocumentAction')
  453. ->assert('file', '.+')
  454. ->assert('type', '.+');
  455. /** Data default_platform_document files */
  456. $app->get('/data/default_course_document/{file}', 'index.controller:getDefaultCourseDocumentAction')
  457. ->assert('file', '.+')
  458. ->assert('type', '.+');
  459. /** User files */
  460. $app->match('/data/upload/users/{file}', 'index.controller:getUserFile', 'GET|POST')
  461. ->assert('file', '.+');
  462. /** Group files */
  463. $app->get('/data/upload/groups/{groupId}/{file}', 'index.controller:getGroupFile')
  464. ->assert('file', '.+')
  465. ->assert('type', '.+');
  466. /** Admin */
  467. $app->get('/admin/dashboard', 'index.controller:dashboardAction')
  468. ->assert('type', '.+')
  469. ->bind('admin_dashboard');
  470. /** Question manager - admin */
  471. $app->get('/admin/questionmanager', 'question_manager.controller:questionManagerIndexAction')
  472. ->assert('type', '.+')
  473. ->bind('admin_questionmanager');
  474. $app->match('/admin/questionmanager/questions', 'question_manager.controller:questionsAction', 'GET|POST')
  475. ->assert('type', '.+')
  476. ->bind('admin_questions');
  477. $app->match('/admin/questionmanager/questions/{id}/edit', 'question_manager.controller:editQuestionAction', 'GET|POST')
  478. ->assert('type', '.+')
  479. ->bind('admin_questions_edit');
  480. $app->match('/admin/questionmanager/questions/{id}', 'exercise_manager.controller:getQuestionAction', 'GET|POST')
  481. ->assert('type', '.+')
  482. ->bind('admin_questions_show');
  483. $app->get('/admin/questionmanager/questions/get-categories/{id}', 'question_manager.controller:getCategoriesAction')
  484. ->bind('admin_questions_get_categories');
  485. $app->get('/admin/questionmanager/questions/get-questions-by-category/{categoryId}', 'question_manager.controller:getQuestionsByCategoryAction')
  486. ->bind('admin_get_questions_by_category');
  487. $app->match('/admin/questionmanager/categories/{id}/edit', 'question_manager.controller:editCategoryAction', 'GET|POST')
  488. ->assert('type', '.+')
  489. ->bind('admin_category_edit');
  490. $app->match('/admin/questionmanager/categories/{id}', 'question_manager.controller:showCategoryAction', 'GET')
  491. ->assert('id', '\d+')
  492. ->assert('type', '.+')
  493. ->bind('admin_category_show');
  494. $app->match('/admin/questionmanager/categories/new', 'question_manager.controller:newCategoryAction', 'GET|POST')
  495. ->bind('admin_category_new');
  496. $app->match('/admin/questionmanager/categories/{id}/delete', 'question_manager.controller:deleteCategoryAction', 'POST')
  497. ->bind('admin_category_delete');
  498. /** Editor */
  499. $app->match('/editor/filemanager', 'editor.controller:filemanagerAction', 'GET|POST')
  500. ->assert('type', '.+')
  501. ->bind('filemanager');
  502. $app->match('/editor/connector', 'editor.controller:connectorAction', 'GET|POST')
  503. ->assert('type', '.+')
  504. ->bind('editor_connector');
  505. /** Exercises */
  506. $app->match('courses/{cidReq}/{id_session}/exercise/question-pool', 'exercise_manager.controller:questionPoolAction', 'POST')
  507. ->before($settingCourseConditions)
  508. ->before($userPermissionsInsideACourse)
  509. ->bind('exercise_question_pool_global');
  510. $app->match('courses/{cidReq}/{id_session}/exercise/{exerciseId}/question-pool', 'exercise_manager.controller:questionPoolAction', 'GET|POST')
  511. ->assert('exerciseId', '\d+')
  512. ->before($settingCourseConditions)
  513. ->before($userCourseAdmin)
  514. ->before($userPermissionsInsideACourse)
  515. ->bind('exercise_question_pool');
  516. $app->match('courses/{cidReq}/{id_session}/exercise/{exerciseId}/copy-question/{questionId}', 'exercise_manager.controller:copyQuestionAction', 'GET|POST')
  517. ->assert('questionId', '\d+')
  518. ->assert('exerciseId', '\d+')
  519. ->before($settingCourseConditions)
  520. ->before($userCourseAdmin)
  521. ->before($userPermissionsInsideACourse)
  522. ->bind('exercise_copy_question');
  523. $app->match('courses/{cidReq}/{id_session}/exercise/{exerciseId}/reuse-question/{questionId}', 'exercise_manager.controller:reuseQuestionAction', 'GET|POST')
  524. ->assert('questionId', '\d+')
  525. ->assert('exerciseId', '\d+')
  526. ->before($settingCourseConditions)
  527. ->before($userCourseAdmin)
  528. ->before($userPermissionsInsideACourse)
  529. ->bind('exercise_reuse_question');
  530. /** Course home instead of courses/MATHS the new URL is web/courses/MATHS */
  531. $app->match('/courses/{cidReq}/{id_session}/exercise/question/{id}', 'exercise_manager.controller:getQuestionAction', 'GET')
  532. ->assert('id_session', '\d+')
  533. ->assert('id', '\d+')
  534. ->assert('type', '.+')
  535. ->before($settingCourseConditions)
  536. ->before($userPermissionsInsideACourse)
  537. ->before($userCourseAdmin)
  538. ->bind('question_show');
  539. $app->match('/courses/{cidReq}/{id_session}/exercise/{exerciseId}/question/{id}', 'exercise_manager.controller:getQuestionAction', 'GET')
  540. ->assert('id_session', '\d+')
  541. ->assert('exerciseId', '\d+')
  542. ->assert('id', '\d+')
  543. ->assert('type', '.+')
  544. ->before($settingCourseConditions)
  545. ->before($userPermissionsInsideACourse)
  546. ->before($userCourseAdmin)
  547. ->bind('exercise_question_show');
  548. $app->match('/courses/{cidReq}/{id_session}/exercise/{exerciseId}/dashboard', 'exercise_manager.controller:dashboardAction', 'GET')
  549. ->assert('id_session', '\d+')
  550. ->assert('exerciseId', '\d+')
  551. ->assert('type', '.+')
  552. ->before($settingCourseConditions)
  553. ->before($userPermissionsInsideACourse)
  554. ->before($userCourseAdmin)
  555. ->bind('exercise_dashboard');
  556. $app->match('/courses/{cidReq}/{id_session}/exercise/question/{id}/edit', 'exercise_manager.controller:editQuestionAction', 'GET|POST')
  557. ->assert('type', '.+')
  558. ->before($settingCourseConditions)
  559. ->before($userPermissionsInsideACourse)
  560. ->before($userCourseAdmin)
  561. ->bind('exercise_question_edit');
  562. $app->match('/admin/administrator/', 'admin.controller:indexAction', 'GET')
  563. ->assert('type', '.+')
  564. ->bind('admin_administrator');
  565. $app->match('/ajax', 'model_ajax.controller:indexAction', 'GET')
  566. ->assert('type', '.+')
  567. ->bind('model_ajax');
  568. if ($alreadyInstalled) {
  569. $app->mount('/admin/', new ChamiloLMS\Provider\ReflectionControllerProvider('admin.controller'));
  570. $app->mount('/admin/administrator/upgrade', new ChamiloLMS\Provider\ReflectionControllerProvider('upgrade.controller'));
  571. $app->mount('/admin/administrator/roles', new ChamiloLMS\Provider\ReflectionControllerProvider('role.controller'));
  572. $app->mount('/admin/administrator/question_scores', new ChamiloLMS\Provider\ReflectionControllerProvider('question_score.controller'));
  573. $app->mount('/admin/administrator/question_score_names', new ChamiloLMS\Provider\ReflectionControllerProvider('question_score_name.controller'));
  574. $app->mount('/courses/{course}/curriculum/category', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum_category.controller'));
  575. $app->mount('/courses/{course}/curriculum/item', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum_item.controller'));
  576. $app->mount('/courses/{course}/curriculum/user', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum_user.controller'));
  577. $app->mount('/courses/{course}/curriculum', new ChamiloLMS\Provider\ReflectionControllerProvider('curriculum.controller'));
  578. // Ministerio routes:
  579. $app->mount('/admin/administrator/branches', new ChamiloLMS\Provider\ReflectionControllerProvider('branch.controller'));
  580. $app->mount('/admin/administrator/juries', new ChamiloLMS\Provider\ReflectionControllerProvider('jury.controller'));
  581. $app->mount('/admin/director', new ChamiloLMS\Provider\ReflectionControllerProvider('branch_director.controller'));
  582. $app->mount('/admin/jury_president', new ChamiloLMS\Provider\ReflectionControllerProvider('jury_president.controller'));
  583. $app->mount('/admin/jury_member', new ChamiloLMS\Provider\ReflectionControllerProvider('jury_member.controller'));
  584. $app->mount(
  585. '/admin/question_manager/exercise_distribution',
  586. new ChamiloLMS\Provider\ReflectionControllerProvider('exercise_distribution.controller')
  587. );
  588. $app->mount(
  589. '/admin/exercise_statistics/exercise_distribution',
  590. new ChamiloLMS\Provider\ReflectionControllerProvider('exercise_statistics.controller')
  591. );
  592. $app->match('/resultados-pnc', 'index.controller:resultsAction', 'GET')->bind('resultsAction');
  593. }