| Total Complexity | 88 |
| Total Lines | 895 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like CoursesController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CoursesController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class CoursesController |
||
| 20 | { |
||
| 21 | private $toolname; |
||
| 22 | private $view; |
||
| 23 | private $model; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Constructor. |
||
| 27 | */ |
||
| 28 | public function __construct() |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * It's used for listing courses, |
||
| 38 | * render to courses_list view. |
||
| 39 | * |
||
| 40 | * @param string $action |
||
| 41 | * @param string $message confirmation message(optional) |
||
| 42 | */ |
||
| 43 | public function courseList($action, $message = '') |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * It's used for listing categories, render to categories_list view. |
||
| 61 | */ |
||
| 62 | public function categoryList() |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * It's used for listing courses with categories, |
||
| 89 | * render to courses_categories view. |
||
| 90 | * |
||
| 91 | * @param string $action |
||
| 92 | * @param string $category_code |
||
| 93 | * @param string $message |
||
| 94 | * @param string $error |
||
| 95 | * @param string $content |
||
| 96 | * @param array $limit will be used if $random_value is not set. |
||
| 97 | * This array should contains 'start' and 'length' keys |
||
| 98 | * |
||
| 99 | * @internal param \action $string |
||
| 100 | * @internal param \Category $string code (optional) |
||
| 101 | */ |
||
| 102 | public function courses_categories( |
||
| 103 | $action, |
||
| 104 | $category_code = null, |
||
| 105 | $message = '', |
||
| 106 | $error = '', |
||
| 107 | $content = null, |
||
| 108 | $limit = [] |
||
| 109 | ) { |
||
| 110 | $data = []; |
||
| 111 | $listCategories = CoursesAndSessionsCatalog::getCourseCategoriesTree(); |
||
| 112 | |||
| 113 | $data['countCoursesInCategory'] = CourseCategory::countCoursesInCategory($category_code); |
||
| 114 | if ($action === 'display_random_courses') { |
||
| 115 | // Random value is used instead limit filter |
||
| 116 | $data['browse_courses_in_category'] = CoursesAndSessionsCatalog::getCoursesInCategory(null, 12); |
||
| 117 | $data['countCoursesInCategory'] = count($data['browse_courses_in_category']); |
||
| 118 | } else { |
||
| 119 | if (!isset($category_code)) { |
||
| 120 | $category_code = $listCategories['ALL']['code']; // by default first category |
||
| 121 | } |
||
| 122 | $limit = isset($limit) ? $limit : self::getLimitArray(); |
||
| 123 | $listCourses = CoursesAndSessionsCatalog::getCoursesInCategory($category_code, null, $limit); |
||
| 124 | |||
| 125 | $data['browse_courses_in_category'] = $listCourses; |
||
| 126 | } |
||
| 127 | |||
| 128 | $data['list_categories'] = $listCategories; |
||
| 129 | $data['code'] = Security::remove_XSS($category_code); |
||
| 130 | |||
| 131 | // getting all the courses to which the user is subscribed to |
||
| 132 | $curr_user_id = api_get_user_id(); |
||
| 133 | $user_courses = $this->model->get_courses_of_user($curr_user_id); |
||
| 134 | $user_coursecodes = []; |
||
| 135 | |||
| 136 | // we need only the course codes as these will be used to match against the courses of the category |
||
| 137 | if ($user_courses != '') { |
||
| 138 | foreach ($user_courses as $key => $value) { |
||
| 139 | $user_coursecodes[] = $value['code']; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | if (api_is_drh()) { |
||
| 144 | $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id()); |
||
| 145 | foreach ($courses as $course) { |
||
| 146 | $user_coursecodes[] = $course['code']; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | $data['user_coursecodes'] = $user_coursecodes; |
||
| 151 | $data['action'] = $action; |
||
| 152 | $data['message'] = $message; |
||
| 153 | $data['content'] = $content; |
||
| 154 | $data['error'] = $error; |
||
| 155 | $data['catalogShowCoursesSessions'] = 0; |
||
| 156 | $showCoursesSessions = (int) api_get_setting('catalog_show_courses_sessions'); |
||
| 157 | if ($showCoursesSessions > 0) { |
||
| 158 | $data['catalogShowCoursesSessions'] = $showCoursesSessions; |
||
| 159 | } |
||
| 160 | |||
| 161 | // render to the view |
||
| 162 | $this->view->set_data($data); |
||
| 163 | $this->view->set_layout('layout'); |
||
| 164 | $this->view->set_template('courses_categories'); |
||
| 165 | $this->view->render(); |
||
| 166 | } |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @param string $search_term |
||
| 170 | * @param string $message |
||
| 171 | * @param string $error |
||
| 172 | * @param string $content |
||
| 173 | * @param array $limit |
||
| 174 | * @param bool $justVisible Whether to search only in courses visibles in the catalogue |
||
| 175 | */ |
||
| 176 | public function search_courses( |
||
| 177 | $search_term, |
||
| 178 | $message = '', |
||
| 179 | $error = '', |
||
| 180 | $content = null, |
||
| 181 | $limit = [], |
||
| 182 | $justVisible = false |
||
| 183 | ) { |
||
| 184 | $data = []; |
||
| 185 | $limit = !empty($limit) ? $limit : self::getLimitArray(); |
||
| 186 | $browse_course_categories = CoursesAndSessionsCatalog::getCourseCategories(); |
||
| 187 | $data['countCoursesInCategory'] = CourseCategory::countCoursesInCategory('ALL', $search_term); |
||
| 188 | $data['browse_courses_in_category'] = CoursesAndSessionsCatalog::search_courses( |
||
| 189 | $search_term, |
||
| 190 | $limit, |
||
| 191 | $justVisible |
||
| 192 | ); |
||
| 193 | $data['browse_course_categories'] = $browse_course_categories; |
||
| 194 | $data['search_term'] = Security::remove_XSS($search_term); //filter before showing in template |
||
| 195 | |||
| 196 | // getting all the courses to which the user is subscribed to |
||
| 197 | $curr_user_id = api_get_user_id(); |
||
| 198 | $user_courses = $this->model->get_courses_of_user($curr_user_id); |
||
| 199 | $user_coursecodes = []; |
||
| 200 | |||
| 201 | // we need only the course codes as these will be used to match against the courses of the category |
||
| 202 | if ($user_courses != '') { |
||
| 203 | foreach ($user_courses as $value) { |
||
| 204 | $user_coursecodes[] = $value['code']; |
||
| 205 | } |
||
| 206 | } |
||
| 207 | |||
| 208 | $data['user_coursecodes'] = $user_coursecodes; |
||
| 209 | $data['message'] = $message; |
||
| 210 | $data['content'] = $content; |
||
| 211 | $data['error'] = $error; |
||
| 212 | $data['action'] = 'display_courses'; |
||
| 213 | |||
| 214 | // render to the view |
||
| 215 | $this->view->set_data($data); |
||
| 216 | $this->view->set_layout('catalog_layout'); |
||
| 217 | $this->view->set_template('courses_categories'); |
||
| 218 | $this->view->render(); |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Create a category |
||
| 223 | * render to listing view. |
||
| 224 | * |
||
| 225 | * @param string $title |
||
| 226 | */ |
||
| 227 | public function addCourseCategory($title) |
||
| 228 | { |
||
| 229 | $result = $this->model->store_course_category($title); |
||
| 230 | if ($result) { |
||
| 231 | Display::addFlash( |
||
| 232 | Display::return_message(get_lang('CourseCategoryStored')) |
||
| 233 | ); |
||
| 234 | } else { |
||
| 235 | Display::addFlash( |
||
| 236 | Display::return_message( |
||
| 237 | get_lang('ACourseCategoryWithThisNameAlreadyExists'), |
||
| 238 | 'error' |
||
| 239 | ) |
||
| 240 | ); |
||
| 241 | } |
||
| 242 | header('Location: '.api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses'); |
||
| 243 | exit; |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Change course category |
||
| 248 | * render to listing view. |
||
| 249 | * |
||
| 250 | * @param string $course_code |
||
| 251 | * @param int $category_id |
||
| 252 | */ |
||
| 253 | public function change_course_category($course_code, $category_id) |
||
| 254 | { |
||
| 255 | $courseInfo = api_get_course_info($course_code); |
||
| 256 | $courseId = $courseInfo['real_id']; |
||
| 257 | |||
| 258 | $result = $this->model->updateCourseCategory($courseId, $category_id); |
||
| 259 | if ($result) { |
||
| 260 | Display::addFlash( |
||
| 261 | Display::return_message(get_lang('EditCourseCategorySucces')) |
||
| 262 | ); |
||
| 263 | } |
||
| 264 | $action = 'sortmycourses'; |
||
| 265 | $this->courseList($action); |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Move up/down courses inside a category |
||
| 270 | * render to listing view. |
||
| 271 | * |
||
| 272 | * @param string $move move to up or down |
||
| 273 | * @param string $course_code |
||
| 274 | * @param int $category_id Category id |
||
| 275 | */ |
||
| 276 | public function move_course($move, $course_code, $category_id) |
||
| 277 | { |
||
| 278 | $result = $this->model->move_course($move, $course_code, $category_id); |
||
| 279 | if ($result) { |
||
| 280 | Display::addFlash( |
||
| 281 | Display::return_message(get_lang('CourseSortingDone')) |
||
| 282 | ); |
||
| 283 | } |
||
| 284 | $action = 'sortmycourses'; |
||
| 285 | $this->courseList($action); |
||
| 286 | } |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Move up/down categories |
||
| 290 | * render to listing view. |
||
| 291 | * |
||
| 292 | * @param string $move move to up or down |
||
| 293 | * @param int $category_id Category id |
||
| 294 | */ |
||
| 295 | public function move_category($move, $category_id) |
||
| 296 | { |
||
| 297 | $result = $this->model->move_category($move, $category_id); |
||
| 298 | if ($result) { |
||
| 299 | Display::addFlash( |
||
| 300 | Display::return_message(get_lang('CategorySortingDone')) |
||
| 301 | ); |
||
| 302 | } |
||
| 303 | $action = 'sortmycourses'; |
||
| 304 | $this->courseList($action); |
||
| 305 | } |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Edit course category |
||
| 309 | * render to listing view. |
||
| 310 | * |
||
| 311 | * @param string $title Category title |
||
| 312 | * @param int $category Category id |
||
| 313 | */ |
||
| 314 | public function edit_course_category($title, $category) |
||
| 315 | { |
||
| 316 | $result = $this->model->store_edit_course_category($title, $category); |
||
| 317 | if ($result) { |
||
| 318 | Display::addFlash( |
||
| 319 | Display::return_message(get_lang('CourseCategoryEditStored')) |
||
| 320 | ); |
||
| 321 | } |
||
| 322 | $action = 'sortmycourses'; |
||
| 323 | $this->courseList($action); |
||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Delete a course category |
||
| 328 | * render to listing view. |
||
| 329 | * |
||
| 330 | * @param int Category id |
||
| 331 | */ |
||
| 332 | public function delete_course_category($category_id) |
||
| 333 | { |
||
| 334 | $result = $this->model->delete_course_category($category_id); |
||
| 335 | if ($result) { |
||
| 336 | Display::addFlash( |
||
| 337 | Display::return_message(get_lang('CourseCategoryDeleted')) |
||
| 338 | ); |
||
| 339 | } |
||
| 340 | $action = 'sortmycourses'; |
||
| 341 | $this->courseList($action); |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * Unsubscribe user from a course |
||
| 346 | * render to listing view. |
||
| 347 | * |
||
| 348 | * @param string $course_code |
||
| 349 | * @param string $search_term |
||
| 350 | * @param string $category_code |
||
| 351 | */ |
||
| 352 | public function unsubscribe_user_from_course( |
||
| 353 | $course_code, |
||
| 354 | $search_term = null, |
||
| 355 | $category_code = null |
||
| 356 | ) { |
||
| 357 | $result = $this->model->remove_user_from_course($course_code); |
||
| 358 | $message = ''; |
||
| 359 | $error = ''; |
||
| 360 | |||
| 361 | if ($result) { |
||
| 362 | Display::addFlash( |
||
| 363 | Display::return_message(get_lang('YouAreNowUnsubscribed')) |
||
| 364 | ); |
||
| 365 | } |
||
| 366 | |||
| 367 | if (!empty($search_term)) { |
||
| 368 | CoursesAndSessionsCatalog::search_courses($search_term, $message, $error); |
||
| 369 | } else { |
||
| 370 | $this->courses_categories( |
||
| 371 | 'subcribe', |
||
| 372 | $category_code, |
||
| 373 | $message, |
||
| 374 | $error |
||
| 375 | ); |
||
| 376 | } |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Get the html block for courses categories. |
||
| 381 | * |
||
| 382 | * @param string $code Current category code |
||
| 383 | * @param bool $hiddenLinks Whether hidden links |
||
| 384 | * @param array $limit |
||
| 385 | * |
||
| 386 | * @return string The HTML block |
||
| 387 | */ |
||
| 388 | public function getCoursesCategoriesBlock( |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Get a HTML button for subscribe to session. |
||
| 498 | * |
||
| 499 | * @param int $sessionId The session ID |
||
| 500 | * @param string $sessionName The session name |
||
| 501 | * @param bool $checkRequirements Optional. |
||
| 502 | * Whether the session has requirement. Default is false |
||
| 503 | * @param bool $includeText Optional. Whether show the text in button |
||
| 504 | * @param bool $btnBing |
||
| 505 | * |
||
| 506 | * @return string The button HTML |
||
| 507 | */ |
||
| 508 | public function getRegisteredInSessionButton( |
||
| 509 | $sessionId, |
||
| 510 | $sessionName, |
||
| 511 | $checkRequirements = false, |
||
| 512 | $includeText = false, |
||
| 513 | $btnBing = false |
||
| 514 | ) { |
||
| 515 | if ($btnBing) { |
||
| 516 | $btnBing = 'btn-lg btn-block'; |
||
| 517 | } else { |
||
| 518 | $btnBing = 'btn-sm'; |
||
| 519 | } |
||
| 520 | if ($checkRequirements) { |
||
| 521 | $url = api_get_path(WEB_AJAX_PATH); |
||
| 522 | $url .= 'sequence.ajax.php?'; |
||
| 523 | $url .= http_build_query([ |
||
| 524 | 'a' => 'get_requirements', |
||
| 525 | 'id' => intval($sessionId), |
||
| 526 | 'type' => SequenceResource::SESSION_TYPE, |
||
| 527 | ]); |
||
| 528 | |||
| 529 | return Display::toolbarButton( |
||
| 530 | get_lang('CheckRequirements'), |
||
| 531 | $url, |
||
| 532 | 'shield', |
||
| 533 | 'info', |
||
| 534 | [ |
||
| 535 | 'class' => $btnBing.' ajax', |
||
| 536 | 'data-title' => get_lang('CheckRequirements'), |
||
| 537 | 'data-size' => 'md', |
||
| 538 | 'title' => get_lang('CheckRequirements'), |
||
| 539 | ], |
||
| 540 | $includeText |
||
| 541 | ); |
||
| 542 | } |
||
| 543 | |||
| 544 | $catalogSessionAutoSubscriptionAllowed = false; |
||
| 545 | if (api_get_setting('catalog_allow_session_auto_subscription') === 'true') { |
||
| 546 | $catalogSessionAutoSubscriptionAllowed = true; |
||
| 547 | } |
||
| 548 | |||
| 549 | $url = api_get_path(WEB_CODE_PATH); |
||
| 550 | |||
| 551 | if ($catalogSessionAutoSubscriptionAllowed) { |
||
| 552 | $url .= 'auth/courses.php?'; |
||
| 553 | $url .= http_build_query([ |
||
| 554 | 'action' => 'subscribe_to_session', |
||
| 555 | 'session_id' => intval($sessionId), |
||
| 556 | ]); |
||
| 557 | |||
| 558 | $result = Display::toolbarButton( |
||
| 559 | get_lang('Subscribe'), |
||
| 560 | $url, |
||
| 561 | 'pencil', |
||
| 562 | 'primary', |
||
| 563 | [ |
||
| 564 | 'class' => $btnBing.' ajax', |
||
| 565 | 'data-title' => get_lang('AreYouSureToSubscribe'), |
||
| 566 | 'data-size' => 'md', |
||
| 567 | 'title' => get_lang('Subscribe'), |
||
| 568 | ], |
||
| 569 | $includeText |
||
| 570 | ); |
||
| 571 | } else { |
||
| 572 | $url .= 'inc/email_editor.php?'; |
||
| 573 | $url .= http_build_query([ |
||
| 574 | 'action' => 'subscribe_me_to_session', |
||
| 575 | 'session' => Security::remove_XSS($sessionName), |
||
| 576 | ]); |
||
| 577 | |||
| 578 | $result = Display::toolbarButton( |
||
| 579 | get_lang('SubscribeToSessionRequest'), |
||
| 580 | $url, |
||
| 581 | 'pencil', |
||
| 582 | 'primary', |
||
| 583 | ['class' => $btnBing], |
||
| 584 | $includeText |
||
| 585 | ); |
||
| 586 | } |
||
| 587 | |||
| 588 | $hook = HookResubscribe::create(); |
||
| 589 | if (!empty($hook)) { |
||
| 590 | $hook->setEventData([ |
||
| 591 | 'session_id' => intval($sessionId), |
||
| 592 | ]); |
||
| 593 | try { |
||
| 594 | $hook->notifyResubscribe(HOOK_EVENT_TYPE_PRE); |
||
| 595 | } catch (Exception $exception) { |
||
| 596 | $result = $exception->getMessage(); |
||
| 597 | } |
||
| 598 | } |
||
| 599 | |||
| 600 | return $result; |
||
| 601 | } |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Generate a label if the user has been registered in session. |
||
| 605 | * |
||
| 606 | * @return string The label |
||
| 607 | */ |
||
| 608 | public function getAlreadyRegisteredInSessionLabel() |
||
| 617 | ] |
||
| 618 | ); |
||
| 619 | } |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Get a icon for a session. |
||
| 623 | * |
||
| 624 | * @param string $sessionName The session name |
||
| 625 | * |
||
| 626 | * @return string The icon |
||
| 627 | */ |
||
| 628 | public function getSessionIcon($sessionName) |
||
| 635 | ); |
||
| 636 | } |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Return Session catalog rendered view. |
||
| 640 | * |
||
| 641 | * @param string $action |
||
| 642 | * @param string $nameTools |
||
| 643 | * @param array $limit |
||
| 644 | */ |
||
| 645 | public function sessionList($action, $nameTools, $limit = []) |
||
| 646 | { |
||
| 647 | $date = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d'); |
||
| 648 | $hiddenLinks = isset($_GET['hidden_links']) ? $_GET['hidden_links'] == 1 : false; |
||
| 649 | $limit = isset($limit) ? $limit : self::getLimitArray(); |
||
| 650 | $countSessions = SessionManager::countSessionsByEndDate($date); |
||
| 651 | $sessions = CoursesAndSessionsCatalog::browseSessions($date, $limit); |
||
| 652 | |||
| 653 | $pageTotal = ceil($countSessions / $limit['length']); |
||
| 654 | // Do NOT show pagination if only one page or less |
||
| 655 | $cataloguePagination = $pageTotal > 1 ? CourseCategory::getCatalogPagination($limit['current'], $limit['length'], $pageTotal) : ''; |
||
| 656 | $sessionsBlocks = $this->getFormattedSessionsBlock($sessions); |
||
| 657 | |||
| 658 | // Get session search catalogue URL |
||
| 659 | $courseUrl = CourseCategory::getCourseCategoryUrl( |
||
| 660 | 1, |
||
| 661 | $limit['length'], |
||
| 662 | null, |
||
| 663 | 0, |
||
| 664 | 'subscribe' |
||
| 665 | ); |
||
| 666 | |||
| 667 | $tpl = new Template(); |
||
| 668 | $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses()); |
||
| 669 | $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions()); |
||
| 670 | $tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true'); |
||
| 671 | $tpl->assign('course_url', $courseUrl); |
||
| 672 | $tpl->assign('catalog_pagination', $cataloguePagination); |
||
| 673 | $tpl->assign('hidden_links', $hiddenLinks); |
||
| 674 | $tpl->assign('search_token', Security::get_token()); |
||
| 675 | $tpl->assign('search_date', $date); |
||
| 676 | $tpl->assign('web_session_courses_ajax_url', api_get_path(WEB_AJAX_PATH).'course.ajax.php'); |
||
| 677 | $tpl->assign('sessions', $sessionsBlocks); |
||
| 678 | $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel()); |
||
| 679 | |||
| 680 | $layout = $tpl->get_template('auth/session_catalog.html.twig'); |
||
| 681 | $content = $tpl->fetch($layout); |
||
| 682 | $tpl->assign('content', $content); |
||
| 683 | $tpl->display_one_col_template(); |
||
| 684 | } |
||
| 685 | |||
| 686 | /** |
||
| 687 | * Show the Session Catalogue with filtered session by course tags. |
||
| 688 | * |
||
| 689 | * @param array $limit Limit info |
||
| 690 | */ |
||
| 691 | public function sessionsListByCoursesTag(array $limit) |
||
| 722 | } |
||
| 723 | |||
| 724 | /** |
||
| 725 | * Show the Session Catalogue with filtered session by a query term. |
||
| 726 | * |
||
| 727 | * @param array $limit |
||
| 728 | */ |
||
| 729 | public function sessionListBySearch(array $limit) |
||
| 730 | { |
||
| 731 | $q = isset($_REQUEST['q']) ? Security::remove_XSS($_REQUEST['q']) : null; |
||
| 732 | $hiddenLinks = isset($_GET['hidden_links']) ? (int) $_GET['hidden_links'] == 1 : false; |
||
| 733 | $courseUrl = CourseCategory::getCourseCategoryUrl( |
||
| 734 | 1, |
||
| 735 | $limit['length'], |
||
| 736 | null, |
||
| 737 | 0, |
||
| 738 | 'subscribe' |
||
| 739 | ); |
||
| 740 | $searchDate = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d'); |
||
| 741 | |||
| 742 | $sessions = CoursesAndSessionsCatalog::browseSessionsBySearch($q, $limit); |
||
| 743 | $sessionsBlocks = $this->getFormattedSessionsBlock($sessions); |
||
| 744 | |||
| 745 | $tpl = new Template(); |
||
| 746 | $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses()); |
||
| 747 | $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions()); |
||
| 748 | $tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true' ? true : false); |
||
| 749 | $tpl->assign('course_url', $courseUrl); |
||
| 750 | $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel()); |
||
| 751 | $tpl->assign('hidden_links', $hiddenLinks); |
||
| 752 | $tpl->assign('search_token', Security::get_token()); |
||
| 753 | $tpl->assign('search_date', Security::remove_XSS($searchDate)); |
||
| 754 | $tpl->assign('search_tag', Security::remove_XSS($q)); |
||
| 755 | $tpl->assign('sessions', $sessionsBlocks); |
||
| 756 | |||
| 757 | $contentTemplate = $tpl->get_template('auth/session_catalog.tpl'); |
||
| 758 | |||
| 759 | $tpl->display($contentTemplate); |
||
| 760 | } |
||
| 761 | |||
| 762 | /** |
||
| 763 | * @return array |
||
| 764 | */ |
||
| 765 | public static function getLimitArray() |
||
| 766 | { |
||
| 767 | $pageCurrent = isset($_REQUEST['pageCurrent']) ? (int) $_GET['pageCurrent'] : 1; |
||
| 768 | $pageLength = isset($_REQUEST['pageLength']) ? (int) $_GET['pageLength'] : CoursesAndSessionsCatalog::PAGE_LENGTH; |
||
| 769 | |||
| 770 | return [ |
||
| 771 | 'start' => ($pageCurrent - 1) * $pageLength, |
||
| 772 | 'current' => $pageCurrent, |
||
| 773 | 'length' => $pageLength, |
||
| 774 | ]; |
||
| 775 | } |
||
| 776 | |||
| 777 | /** |
||
| 778 | * Get the formatted data for sessions block to be displayed on Session Catalog page. |
||
| 779 | * |
||
| 780 | * @param array $sessions The session list |
||
| 781 | * |
||
| 782 | * @return array |
||
| 783 | */ |
||
| 784 | private function getFormattedSessionsBlock(array $sessions) |
||
| 914 | } |
||
| 915 | } |
||
| 916 |