| Total Complexity | 189 |
| Total Lines | 1189 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like PageController 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 PageController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class PageController |
||
| 25 | { |
||
| 26 | public $maxPerPage = 5; |
||
| 27 | |||
| 28 | |||
| 29 | /** |
||
| 30 | * Returns an online help block read from the home/home_menu_[lang].html |
||
| 31 | * file |
||
| 32 | * @return string HTML block |
||
| 33 | */ |
||
| 34 | public function returnHelp() |
||
| 35 | { |
||
| 36 | $home = api_get_home_path(); |
||
| 37 | $user_selected_language = api_get_language_isocode(); |
||
| 38 | $sys_path = api_get_path(SYS_PATH); |
||
| 39 | $platformLanguage = api_get_setting('language.platform_language'); |
||
| 40 | |||
| 41 | if (!isset($user_selected_language)) { |
||
| 42 | $user_selected_language = $platformLanguage; |
||
| 43 | } |
||
| 44 | $home_menu = @(string)file_get_contents($sys_path.$home.'home_menu_'.$user_selected_language.'.html'); |
||
| 45 | if (!empty($home_menu)) { |
||
| 46 | $home_menu_content = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
||
| 47 | $this->show_right_block( |
||
| 48 | get_lang('MenuGeneral'), |
||
| 49 | null, |
||
| 50 | 'help_block', |
||
| 51 | ['content' => $home_menu_content] |
||
| 52 | ); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Returns an HTML block with links to the skills tools |
||
| 58 | * @return string HTML <div> block |
||
| 59 | */ |
||
| 60 | public function returnSkillsLinks() |
||
| 61 | { |
||
| 62 | if (api_get_setting('skill.allow_skills_tool') == 'true') { |
||
| 63 | $content = []; |
||
| 64 | $content[] = [ |
||
| 65 | 'title' => get_lang('MySkills'), |
||
| 66 | 'href' => api_get_path(WEB_CODE_PATH).'social/skills_wheel.php' |
||
| 67 | ]; |
||
| 68 | |||
| 69 | if (api_get_setting('skill.allow_hr_skills_management') == 'true' |
||
| 70 | || api_is_platform_admin()) { |
||
| 71 | $content[] = [ |
||
| 72 | 'title' => get_lang('ManageSkills'), |
||
| 73 | 'href' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php' |
||
| 74 | ]; |
||
| 75 | } |
||
| 76 | $this->show_right_block(get_lang("Skills"), $content, 'skill_block'); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Returns an HTML block with the notice, as found in the |
||
| 82 | * home/home_notice_[lang].html file |
||
| 83 | * @return string HTML <div> block |
||
| 84 | */ |
||
| 85 | public function returnNotice() |
||
| 86 | { |
||
| 87 | $sys_path = api_get_path(SYS_PATH); |
||
| 88 | $user_selected_language = api_get_language_isocode(); |
||
| 89 | $home = api_get_home_path(); |
||
| 90 | |||
| 91 | // Notice |
||
| 92 | $home_notice = @(string)file_get_contents($sys_path.$home.'home_notice_'.$user_selected_language.'.html'); |
||
| 93 | if (empty($home_notice)) { |
||
| 94 | $home_notice = @(string)file_get_contents($sys_path.$home.'home_notice.html'); |
||
| 95 | } |
||
| 96 | |||
| 97 | if (!empty($home_notice)) { |
||
| 98 | $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice))); |
||
| 99 | $home_notice = Display::div($home_notice, ['class' => 'homepage_notice']); |
||
| 100 | |||
| 101 | $this->show_right_block(get_lang('Notice'), null, 'notice_block', ['content' => $home_notice]); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Returns the received content packaged in <div> block, with the title as |
||
| 107 | * <h4> |
||
| 108 | * @param string Title to include as h4 |
||
| 109 | * @param string Longer content to show (usually a <ul> list) |
||
| 110 | * @param string ID to be added to the HTML attributes for the block |
||
| 111 | * @param array Array of attributes to add to the HTML block |
||
| 112 | * @return string HTML <div> block |
||
| 113 | * @todo use the menu builder |
||
| 114 | */ |
||
| 115 | public function show_right_block($title, $content, $id, $params = null) |
||
| 116 | { |
||
| 117 | if (!empty($id)) { |
||
| 118 | $params['id'] = $id; |
||
| 119 | } |
||
| 120 | $block_menu = [ |
||
| 121 | 'id' => $params['id'], |
||
| 122 | 'title' => $title, |
||
| 123 | 'elements' => $content, |
||
| 124 | 'content' => isset($params['content']) ? $params['content'] : null |
||
| 125 | ]; |
||
| 126 | |||
| 127 | //$app['template']->assign($id, $block_menu); |
||
| 128 | } |
||
| 129 | |||
| 130 | |||
| 131 | /** |
||
| 132 | * Returns a content search form in an HTML <div>, pointing at the |
||
| 133 | * main/search/ directory. If search_enabled is not set, then it returns |
||
| 134 | * an empty string |
||
| 135 | * @return string HTML <div> block showing the search form, or an empty string if search not enabled |
||
| 136 | */ |
||
| 137 | public function return_search_block() |
||
| 138 | { |
||
| 139 | $html = ''; |
||
| 140 | if (api_get_setting('search.search_enabled') == 'true') { |
||
| 141 | $html .= '<div class="searchbox">'; |
||
| 142 | $search_btn = get_lang('Search'); |
||
| 143 | $search_content = '<br /> |
||
| 144 | <form action="main/search/" method="post"> |
||
| 145 | <input type="text" id="query" class="span2" name="query" value="" /> |
||
| 146 | <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button> |
||
| 147 | </form></div>'; |
||
| 148 | $html .= $this->show_right_block(get_lang('Search'), $search_content, 'search_block'); |
||
| 149 | } |
||
| 150 | |||
| 151 | return $html; |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Returns a list of announcements |
||
| 156 | * @param int User ID |
||
|
|
|||
| 157 | * @param bool True: show the announcements as a slider. False: show them as a vertical list |
||
| 158 | * @return string HTML list of announcements |
||
| 159 | */ |
||
| 160 | public function getAnnouncements($user_id = null, $show_slide = true) |
||
| 161 | { |
||
| 162 | // Display System announcements |
||
| 163 | $hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected'); |
||
| 164 | if ($hideAnnouncements == 'true' && empty($user_id)) { |
||
| 165 | return null; |
||
| 166 | } |
||
| 167 | |||
| 168 | $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null; |
||
| 169 | $announcement = intval($announcement); |
||
| 170 | |||
| 171 | if (!api_is_anonymous() && $user_id) { |
||
| 172 | $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT; |
||
| 173 | if ($show_slide) { |
||
| 174 | $announcements = SystemAnnouncementManager::displayAnnouncementsSlider( |
||
| 175 | $visibility, |
||
| 176 | $announcement |
||
| 177 | ); |
||
| 178 | } else { |
||
| 179 | $announcements = SystemAnnouncementManager::displayAllAnnouncements( |
||
| 180 | $visibility, |
||
| 181 | $announcement |
||
| 182 | ); |
||
| 183 | } |
||
| 184 | } else { |
||
| 185 | if ($show_slide) { |
||
| 186 | $announcements = SystemAnnouncementManager::displayAnnouncementsSlider( |
||
| 187 | SystemAnnouncementManager::VISIBLE_GUEST, |
||
| 188 | $announcement |
||
| 189 | ); |
||
| 190 | } else { |
||
| 191 | $announcements = SystemAnnouncementManager::displayAllAnnouncements( |
||
| 192 | SystemAnnouncementManager::VISIBLE_GUEST, |
||
| 193 | $announcement |
||
| 194 | ); |
||
| 195 | } |
||
| 196 | } |
||
| 197 | |||
| 198 | return $announcements; |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Return the homepage, including announcements |
||
| 203 | * @return string The portal's homepage as an HTML string |
||
| 204 | */ |
||
| 205 | public function returnHomePage() |
||
| 206 | { |
||
| 207 | // Including the page for the news |
||
| 208 | $html = null; |
||
| 209 | $home = api_get_path(SYS_DATA_PATH).api_get_home_path(); |
||
| 210 | $home_top_temp = null; |
||
| 211 | |||
| 212 | if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) { |
||
| 213 | $open = @(string)file_get_contents(api_get_path(SYS_PATH).$home.$_GET['include']); |
||
| 214 | $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
||
| 215 | } else { |
||
| 216 | $user_selected_language = api_get_user_language(); |
||
| 217 | |||
| 218 | if (!file_exists($home.'home_news_'.$user_selected_language.'.html')) { |
||
| 219 | if (file_exists($home.'home_top.html')) { |
||
| 220 | $home_top_temp = file($home.'home_top.html'); |
||
| 221 | } else { |
||
| 222 | //$home_top_temp = file('home/'.'home_top.html'); |
||
| 223 | } |
||
| 224 | if (!empty($home_top_temp)) { |
||
| 225 | $home_top_temp = implode('', $home_top_temp); |
||
| 226 | } |
||
| 227 | } else { |
||
| 228 | if (file_exists($home.'home_top_'.$user_selected_language.'.html')) { |
||
| 229 | $home_top_temp = file_get_contents($home.'home_top_'.$user_selected_language.'.html'); |
||
| 230 | } else { |
||
| 231 | $home_top_temp = file_get_contents($home.'home_top.html'); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | if (empty($home_top_temp) && api_is_platform_admin()) { |
||
| 236 | $home_top_temp = get_lang('PortalHomepageDefaultIntroduction'); |
||
| 237 | } |
||
| 238 | $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp); |
||
| 239 | if (!empty($open)) { |
||
| 240 | $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
||
| 241 | } |
||
| 242 | } |
||
| 243 | |||
| 244 | return $html; |
||
| 245 | } |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Returns an HTML block with classes (if show_groups_to_users is true) |
||
| 249 | * @return string A list of links to users classes tools, or an empty string if show_groups_to_users is disabled |
||
| 250 | */ |
||
| 251 | public function return_classes_block() |
||
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Prepares a block with all the pending exercises in all courses |
||
| 285 | * @param array Array of courses (arrays) of the user |
||
| 286 | * @return void Doesn't return anything but prepares and HTML block for use in templates |
||
| 287 | */ |
||
| 288 | public function return_exercise_block($personal_course_list, $tpl) |
||
| 289 | { |
||
| 290 | $exercise_list = []; |
||
| 291 | if (!empty($personal_course_list)) { |
||
| 292 | foreach ($personal_course_list as $course_item) { |
||
| 293 | $course_code = $course_item['c']; |
||
| 294 | $session_id = $course_item['id_session']; |
||
| 295 | |||
| 296 | $exercises = ExerciseLib::get_exercises_to_be_taken($course_code, $session_id); |
||
| 297 | |||
| 298 | foreach ($exercises as $exercise_item) { |
||
| 299 | $exercise_item['course_code'] = $course_code; |
||
| 300 | $exercise_item['session_id'] = $session_id; |
||
| 301 | $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC'); |
||
| 302 | |||
| 303 | $exercise_list[] = $exercise_item; |
||
| 304 | } |
||
| 305 | } |
||
| 306 | if (!empty($exercise_list)) { |
||
| 307 | $exercise_list = ArrayClass::msort($exercise_list, 'tms'); |
||
| 308 | $my_exercise = $exercise_list[0]; |
||
| 309 | $url = Display::url( |
||
| 310 | $my_exercise['title'], |
||
| 311 | api_get_path( |
||
| 312 | WEB_CODE_PATH |
||
| 313 | ).'exercise/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id'] |
||
| 314 | ); |
||
| 315 | $tpl->assign('exercise_url', $url); |
||
| 316 | $tpl->assign( |
||
| 317 | 'exercise_end_date', |
||
| 318 | api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT) |
||
| 319 | ); |
||
| 320 | } |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Display list of courses in a category. |
||
| 326 | * (for anonymous users) |
||
| 327 | * |
||
| 328 | * @version 1.1 |
||
| 329 | * @author Patrick Cool <[email protected]>, Ghent University - refactoring and code cleaning |
||
| 330 | * @author Julio Montoya <[email protected]>, Beeznest template modifs |
||
| 331 | */ |
||
| 332 | public function return_courses_in_categories() |
||
| 333 | { |
||
| 334 | $result = ''; |
||
| 335 | $stok = Security::get_token(); |
||
| 336 | |||
| 337 | // Initialization. |
||
| 338 | $user_identified = (api_get_user_id() > 0 && !api_is_anonymous()); |
||
| 339 | $web_course_path = api_get_path(WEB_COURSE_PATH); |
||
| 340 | $category = Database::escape_string($_GET['category']); |
||
| 341 | $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true'; |
||
| 342 | |||
| 343 | // Database table definitions. |
||
| 344 | $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE); |
||
| 345 | $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY); |
||
| 346 | |||
| 347 | // Get list of courses in category $category. |
||
| 348 | $sql_get_course_list = "SELECT * FROM $main_course_table cours |
||
| 349 | WHERE category_code = '".Database::escape_string($_GET['category'])."' |
||
| 350 | ORDER BY title, UPPER(visual_code)"; |
||
| 351 | |||
| 352 | // Showing only the courses of the current access_url_id. |
||
| 353 | if (api_is_multiple_url_enabled()) { |
||
| 354 | $url_access_id = api_get_current_access_url_id(); |
||
| 355 | if ($url_access_id != -1) { |
||
| 356 | $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
||
| 357 | $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course |
||
| 358 | ON (url_rel_course.c_id = course.id) |
||
| 359 | WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string( |
||
| 360 | $_GET['category'] |
||
| 361 | )."' ORDER BY title, UPPER(visual_code)"; |
||
| 362 | } |
||
| 363 | } |
||
| 364 | |||
| 365 | // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' |
||
| 366 | $sql_result_courses = Database::query($sql_get_course_list); |
||
| 367 | |||
| 368 | while ($course_result = Database::fetch_array($sql_result_courses)) { |
||
| 369 | $course_list[] = $course_result; |
||
| 370 | } |
||
| 371 | |||
| 372 | $platform_visible_courses = ''; |
||
| 373 | // $setting_show_also_closed_courses |
||
| 374 | if ($user_identified) { |
||
| 375 | if ($setting_show_also_closed_courses) { |
||
| 376 | $platform_visible_courses = ''; |
||
| 377 | } else { |
||
| 378 | $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )"; |
||
| 379 | } |
||
| 380 | } else { |
||
| 381 | if ($setting_show_also_closed_courses) { |
||
| 382 | $platform_visible_courses = ''; |
||
| 383 | } else { |
||
| 384 | $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )"; |
||
| 385 | } |
||
| 386 | } |
||
| 387 | $sqlGetSubCatList = " |
||
| 388 | SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse |
||
| 389 | FROM $main_category_table t1 |
||
| 390 | LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id |
||
| 391 | LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses) |
||
| 392 | WHERE t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")." |
||
| 393 | GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name"; |
||
| 394 | |||
| 395 | |||
| 396 | // Showing only the category of courses of the current access_url_id |
||
| 397 | if (api_is_multiple_url_enabled()) { |
||
| 398 | $url_access_id = api_get_current_access_url_id(); |
||
| 399 | if ($url_access_id != -1) { |
||
| 400 | $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
||
| 401 | $sqlGetSubCatList = " |
||
| 402 | SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse |
||
| 403 | FROM $main_category_table t1 |
||
| 404 | LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id |
||
| 405 | LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses) |
||
| 406 | INNER JOIN $tbl_url_rel_course as url_rel_course |
||
| 407 | ON (url_rel_course.c_id = t3.id) |
||
| 408 | WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")." |
||
| 409 | GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name"; |
||
| 410 | } |
||
| 411 | } |
||
| 412 | |||
| 413 | $resCats = Database::query($sqlGetSubCatList); |
||
| 414 | $thereIsSubCat = false; |
||
| 415 | if (Database::num_rows($resCats) > 0) { |
||
| 416 | $htmlListCat = Display::page_header(get_lang('CatList')); |
||
| 417 | $htmlListCat .= '<ul>'; |
||
| 418 | while ($catLine = Database::fetch_array($resCats)) { |
||
| 419 | if ($catLine['code'] != $category) { |
||
| 420 | $category_has_open_courses = $this->category_has_open_courses($catLine['code']); |
||
| 421 | if ($category_has_open_courses) { |
||
| 422 | // The category contains courses accessible to anonymous visitors. |
||
| 423 | $htmlListCat .= '<li>'; |
||
| 424 | $htmlListCat .= '<a href="'.api_get_self( |
||
| 425 | ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>'; |
||
| 426 | if (api_get_setting('show_number_of_courses') == 'true') { |
||
| 427 | $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')'; |
||
| 428 | } |
||
| 429 | $htmlListCat .= "</li>"; |
||
| 430 | $thereIsSubCat = true; |
||
| 431 | } elseif ($catLine['children_count'] > 0) { |
||
| 432 | // The category has children, subcategories. |
||
| 433 | $htmlListCat .= '<li>'; |
||
| 434 | $htmlListCat .= '<a href="'.api_get_self( |
||
| 435 | ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>'; |
||
| 436 | $htmlListCat .= "</li>"; |
||
| 437 | $thereIsSubCat = true; |
||
| 438 | } elseif (api_get_setting('show_empty_course_categories') == 'true') { |
||
| 439 | /* End changed code to eliminate the (0 courses) after empty categories. */ |
||
| 440 | $htmlListCat .= '<li>'; |
||
| 441 | $htmlListCat .= $catLine['name']; |
||
| 442 | $htmlListCat .= "</li>"; |
||
| 443 | $thereIsSubCat = true; |
||
| 444 | } // Else don't set thereIsSubCat to true to avoid printing things if not requested. |
||
| 445 | } else { |
||
| 446 | $htmlTitre = '<p>'; |
||
| 447 | if (api_get_setting('show_back_link_on_top_of_tree') == 'true') { |
||
| 448 | $htmlTitre .= '<a href="'.api_get_self().'"><< '.get_lang('BackToHomePage').'</a>'; |
||
| 449 | } |
||
| 450 | if (!is_null($catLine['parent_id']) || |
||
| 451 | (api_get_setting('show_back_link_on_top_of_tree') != 'true' && |
||
| 452 | !is_null($catLine['code'])) |
||
| 453 | ) { |
||
| 454 | $htmlTitre .= '<a href="'.api_get_self( |
||
| 455 | ).'?category='.$catLine['parent_id'].'"><< '.get_lang('Up').'</a>'; |
||
| 456 | } |
||
| 457 | $htmlTitre .= "</p>"; |
||
| 458 | if ($category != "" && !is_null($catLine['code'])) { |
||
| 459 | $htmlTitre .= '<h3>'.$catLine['name']."</h3>"; |
||
| 460 | } else { |
||
| 461 | $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>"; |
||
| 462 | } |
||
| 463 | } |
||
| 464 | } |
||
| 465 | $htmlListCat .= "</ul>"; |
||
| 466 | } |
||
| 467 | $result .= $htmlTitre; |
||
| 468 | if ($thereIsSubCat) { |
||
| 469 | $result .= $htmlListCat; |
||
| 470 | } |
||
| 471 | while ($categoryName = Database::fetch_array($resCats)) { |
||
| 472 | $result .= '<h3>'.$categoryName['name']."</h3>\n"; |
||
| 473 | } |
||
| 474 | $numrows = Database::num_rows($sql_result_courses); |
||
| 475 | $courses_list_string = ''; |
||
| 476 | $courses_shown = 0; |
||
| 477 | if ($numrows > 0) { |
||
| 478 | $courses_list_string .= Display::page_header(get_lang('CourseList')); |
||
| 479 | $courses_list_string .= "<ul>"; |
||
| 480 | |||
| 481 | if (api_get_user_id()) { |
||
| 482 | $courses_of_user = $this->get_courses_of_user(api_get_user_id()); |
||
| 483 | } |
||
| 484 | |||
| 485 | foreach ($course_list as $course) { |
||
| 486 | // $setting_show_also_closed_courses |
||
| 487 | if (!$setting_show_also_closed_courses) { |
||
| 488 | // If we do not show the closed courses |
||
| 489 | // we only show the courses that are open to the world (to everybody) |
||
| 490 | // and the courses that are open to the platform (if the current user is a registered user. |
||
| 491 | if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) { |
||
| 492 | $courses_shown++; |
||
| 493 | $courses_list_string .= "<li>\n"; |
||
| 494 | $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />'; |
||
| 495 | $course_details = []; |
||
| 496 | if (api_get_setting('course.display_coursecode_in_courselist') == |
||
| 497 | 'true') { |
||
| 498 | $course_details[] = $course['visual_code']; |
||
| 499 | } |
||
| 500 | if (api_get_setting('course.display_teacher_in_courselist') == |
||
| 501 | 'true') { |
||
| 502 | $course_details[] = $course['tutor_name']; |
||
| 503 | } |
||
| 504 | if (api_get_setting('display.show_different_course_language') == |
||
| 505 | 'true' && $course['course_language'] != api_get_setting( |
||
| 506 | 'language.platform_language' |
||
| 507 | ) |
||
| 508 | ) { |
||
| 509 | $course_details[] = $course['course_language']; |
||
| 510 | } |
||
| 511 | $courses_list_string .= implode(' - ', $course_details); |
||
| 512 | $courses_list_string .= "</li>\n"; |
||
| 513 | } |
||
| 514 | } else { |
||
| 515 | // We DO show the closed courses. |
||
| 516 | // The course is accessible if (link to the course homepage): |
||
| 517 | // 1. the course is open to the world (doesn't matter if the user is logged in or not): $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD); |
||
| 518 | // 2. the user is logged in and the course is open to the world or open to the platform: ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM); |
||
| 519 | // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED; |
||
| 520 | // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting); |
||
| 521 | // 5. the user is the platform admin api_is_platform_admin(). |
||
| 522 | // |
||
| 523 | $courses_shown++; |
||
| 524 | $courses_list_string .= "<li>\n"; |
||
| 525 | if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD |
||
| 526 | || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) |
||
| 527 | || ($user_identified && key_exists( |
||
| 528 | $course['code'], |
||
| 529 | $courses_of_user |
||
| 530 | ) && $course['visibility'] != COURSE_VISIBILITY_CLOSED) |
||
| 531 | || $courses_of_user[$course['code']]['status'] == '1' |
||
| 532 | || api_is_platform_admin() |
||
| 533 | ) { |
||
| 534 | $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'; |
||
| 535 | } |
||
| 536 | $courses_list_string .= $course['title']; |
||
| 537 | if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD |
||
| 538 | || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) |
||
| 539 | || ($user_identified && key_exists( |
||
| 540 | $course['code'], |
||
| 541 | $courses_of_user |
||
| 542 | ) && $course['visibility'] != COURSE_VISIBILITY_CLOSED) |
||
| 543 | || $courses_of_user[$course['code']]['status'] == '1' |
||
| 544 | || api_is_platform_admin() |
||
| 545 | ) { |
||
| 546 | $courses_list_string .= '</a><br />'; |
||
| 547 | } |
||
| 548 | $course_details = []; |
||
| 549 | if (api_get_setting('course.display_coursecode_in_courselist') == 'true') { |
||
| 550 | $course_details[] = $course['visual_code']; |
||
| 551 | } |
||
| 552 | if (api_get_setting('course.display_teacher_in_courselist') == 'true') { |
||
| 553 | $course_details[] = $course['tutor_name']; |
||
| 554 | } |
||
| 555 | if (api_get_setting( |
||
| 556 | 'display.show_different_course_language' |
||
| 557 | ) == 'true' && $course['course_language'] != api_get_setting( |
||
| 558 | 'language.platform_language' |
||
| 559 | ) |
||
| 560 | ) { |
||
| 561 | $course_details[] = $course['course_language']; |
||
| 562 | } |
||
| 563 | if (api_get_setting( |
||
| 564 | 'show_different_course_language' |
||
| 565 | ) == 'true' && $course['course_language'] != api_get_setting( |
||
| 566 | 'language.platform_language' |
||
| 567 | ) |
||
| 568 | ) { |
||
| 569 | $course_details[] = $course['course_language']; |
||
| 570 | } |
||
| 571 | |||
| 572 | $courses_list_string .= implode(' - ', $course_details); |
||
| 573 | // We display a subscription link if: |
||
| 574 | // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied |
||
| 575 | // 2. |
||
| 576 | if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) { |
||
| 577 | if ($course['subscribe'] == '1') { |
||
| 578 | $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS( |
||
| 579 | $_GET['category'] |
||
| 580 | ).'" method="post">'; |
||
| 581 | $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">'; |
||
| 582 | $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />'; |
||
| 583 | $courses_list_string .= '<input type="image" name="unsub" src="'.api_get_path(WEB_IMG_PATH).'enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').' |
||
| 584 | </form>'; |
||
| 585 | } else { |
||
| 586 | $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed'); |
||
| 587 | } |
||
| 588 | } |
||
| 589 | $courses_list_string .= "</li>"; |
||
| 590 | } //end else |
||
| 591 | } // end foreach |
||
| 592 | $courses_list_string .= "</ul>"; |
||
| 593 | } |
||
| 594 | if ($courses_shown > 0) { |
||
| 595 | // Only display the list of courses and categories if there was more than |
||
| 596 | // 0 courses visible to the world (we're in the anonymous list here). |
||
| 597 | $result .= $courses_list_string; |
||
| 598 | } |
||
| 599 | if ($category != '') { |
||
| 600 | $result .= '<p><a href="'.api_get_self().'"> '.Display :: return_icon('back.png', get_lang('BackToHomePage')).get_lang('BackToHomePage').'</a></p>'; |
||
| 601 | } |
||
| 602 | |||
| 603 | return $result; |
||
| 604 | } |
||
| 605 | |||
| 606 | /** |
||
| 607 | * @param int $user_id |
||
| 608 | * @param string $filter |
||
| 609 | * @param int $page |
||
| 610 | * |
||
| 611 | * @return bool |
||
| 612 | */ |
||
| 613 | public function returnMyCourseCategories($user_id, $filter, $page) |
||
| 614 | { |
||
| 615 | if (empty($user_id)) { |
||
| 616 | return false; |
||
| 617 | } |
||
| 618 | $loadDirs = api_get_setting('document.show_documents_preview') == 'true' ? true : false; |
||
| 619 | $start = ($page - 1) * $this->maxPerPage; |
||
| 620 | |||
| 621 | $nbResults = (int)CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, true); |
||
| 622 | |||
| 623 | $html = CourseManager::displayPersonalCourseCategories( |
||
| 624 | $user_id, |
||
| 625 | $filter, |
||
| 626 | $loadDirs, |
||
| 627 | false, |
||
| 628 | $start, |
||
| 629 | $this->maxPerPage |
||
| 630 | ); |
||
| 631 | |||
| 632 | $adapter = new FixedAdapter($nbResults, []); |
||
| 633 | $pagerfanta = new Pagerfanta($adapter); |
||
| 634 | $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default |
||
| 635 | $pagerfanta->setCurrentPage($page); // 1 by default |
||
| 636 | |||
| 637 | $this->app['pagerfanta.view.router.name'] = 'userportal'; |
||
| 638 | $this->app['pagerfanta.view.router.params'] = [ |
||
| 639 | 'filter' => $filter, |
||
| 640 | 'type' => 'courses', |
||
| 641 | 'page' => $page |
||
| 642 | ]; |
||
| 643 | $this->app['template']->assign('pagination', $pagerfanta); |
||
| 644 | |||
| 645 | return $html; |
||
| 646 | } |
||
| 647 | |||
| 648 | public function returnSpecialCourses($user_id, $filter, $page) |
||
| 649 | { |
||
| 650 | if (empty($user_id)) { |
||
| 651 | return false; |
||
| 652 | } |
||
| 653 | |||
| 654 | $loadDirs = api_get_setting('document.show_documents_preview') == 'true' ? true : false; |
||
| 655 | $start = ($page - 1) * $this->maxPerPage; |
||
| 656 | |||
| 657 | $nbResults = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, true); |
||
| 658 | |||
| 659 | $html = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage); |
||
| 660 | if (!empty($html)) { |
||
| 661 | $adapter = new FixedAdapter($nbResults, []); |
||
| 662 | $pagerfanta = new Pagerfanta($adapter); |
||
| 663 | $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default |
||
| 664 | $pagerfanta->setCurrentPage($page); // 1 by default |
||
| 665 | $this->app['pagerfanta.view.router.name'] = 'userportal'; |
||
| 666 | $this->app['pagerfanta.view.router.params'] = [ |
||
| 667 | 'filter' => $filter, |
||
| 668 | 'type' => 'courses', |
||
| 669 | 'page' => $page |
||
| 670 | ]; |
||
| 671 | $this->app['template']->assign('pagination', $pagerfanta); |
||
| 672 | } |
||
| 673 | |||
| 674 | return $html; |
||
| 675 | } |
||
| 676 | |||
| 677 | /** |
||
| 678 | * The most important function here, prints the session and course list (user_portal.php) |
||
| 679 | * |
||
| 680 | * @param int $user_id |
||
| 681 | * @param string $filter |
||
| 682 | * @param int $page |
||
| 683 | * @return string HTML list of sessions and courses |
||
| 684 | * |
||
| 685 | */ |
||
| 686 | public function returnCourses($user_id, $filter, $page) |
||
| 743 | } |
||
| 744 | |||
| 745 | public function returnSessionsCategories($user_id, $filter, $page) |
||
| 746 | { |
||
| 747 | if (empty($user_id)) { |
||
| 748 | return false; |
||
| 749 | } |
||
| 750 | |||
| 751 | $load_history = (isset($filter) && $filter == 'history') ? true : false; |
||
| 752 | |||
| 753 | $start = ($page - 1) * $this->maxPerPage; |
||
| 754 | |||
| 755 | $nbResults = UserManager::getCategories($user_id, false, true, true); |
||
| 756 | $session_categories = UserManager::getCategories( |
||
| 757 | $user_id, |
||
| 758 | false, |
||
| 759 | false, |
||
| 760 | true, |
||
| 761 | $start, |
||
| 762 | $this->maxPerPage |
||
| 763 | ); |
||
| 764 | |||
| 765 | $html = null; |
||
| 766 | //Showing history title |
||
| 767 | if ($load_history) { |
||
| 768 | $html .= Display::page_subheader(get_lang('HistoryTrainingSession')); |
||
| 769 | if (empty($session_categories)) { |
||
| 770 | $html .= get_lang('YouDoNotHaveAnySessionInItsHistory'); |
||
| 771 | } |
||
| 772 | } |
||
| 773 | |||
| 774 | $load_directories_preview = api_get_setting('document.show_documents_preview') == 'true' ? true : false; |
||
| 775 | $sessions_with_category = $html; |
||
| 776 | |||
| 777 | if (isset($session_categories) && !empty($session_categories)) { |
||
| 778 | foreach ($session_categories as $session_category) { |
||
| 779 | $session_category_id = $session_category['session_category']['id']; |
||
| 780 | |||
| 781 | // All sessions included in |
||
| 782 | $count_courses_session = 0; |
||
| 783 | $html_sessions = ''; |
||
| 784 | foreach ($session_category['sessions'] as $session) { |
||
| 785 | $session_id = $session['session_id']; |
||
| 786 | |||
| 787 | // Don't show empty sessions. |
||
| 788 | if (count($session['courses']) < 1) { |
||
| 789 | continue; |
||
| 790 | } |
||
| 791 | |||
| 792 | $html_courses_session = ''; |
||
| 793 | $count = 0; |
||
| 794 | foreach ($session['courses'] as $course) { |
||
| 795 | if (api_get_setting('session.hide_courses_in_sessions') == 'false') { |
||
| 796 | $html_courses_session .= CourseManager::get_logged_user_course_html($course, $session_id); |
||
| 797 | } |
||
| 798 | $count_courses_session++; |
||
| 799 | $count++; |
||
| 800 | } |
||
| 801 | |||
| 802 | $params = []; |
||
| 803 | if ($count > 0) { |
||
| 804 | $params['icon'] = Display::return_icon( |
||
| 805 | 'window_list.png', |
||
| 806 | $session['session_name'], |
||
| 807 | ['id' => 'session_img_'.$session_id], |
||
| 808 | ICON_SIZE_LARGE |
||
| 809 | ); |
||
| 810 | |||
| 811 | //Default session name |
||
| 812 | $session_link = $session['session_name']; |
||
| 813 | $params['link'] = null; |
||
| 814 | |||
| 815 | if (api_get_setting('session.session_page_enabled') == 'true' && !api_is_drh()) { |
||
| 816 | //session name with link |
||
| 817 | $session_link = Display::tag( |
||
| 818 | 'a', |
||
| 819 | $session['session_name'], |
||
| 820 | ['href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id] |
||
| 821 | ); |
||
| 822 | $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id; |
||
| 823 | } |
||
| 824 | |||
| 825 | $params['title'] = $session_link; |
||
| 826 | |||
| 827 | $moved_status = \SessionManager::getSessionChangeUserReason( |
||
| 828 | isset($session['moved_status']) ? $session['moved_status'] : '' |
||
| 829 | ); |
||
| 830 | $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null; |
||
| 831 | |||
| 832 | $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status; |
||
| 833 | $params['dates'] = \SessionManager::parseSessionDates( |
||
| 834 | $session |
||
| 835 | ); |
||
| 836 | |||
| 837 | if (api_is_platform_admin()) { |
||
| 838 | $params['right_actions'] = '<a href="'.api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session_id.'">'.Display::return_icon( |
||
| 839 | 'edit.png', |
||
| 840 | get_lang('Edit'), |
||
| 841 | ['align' => 'absmiddle'], |
||
| 842 | ICON_SIZE_SMALL |
||
| 843 | ).'</a>'; |
||
| 844 | } |
||
| 845 | $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session; |
||
| 846 | } |
||
| 847 | } |
||
| 848 | |||
| 849 | if ($count_courses_session > 0) { |
||
| 850 | $params = []; |
||
| 851 | $params['icon'] = Display::return_icon( |
||
| 852 | 'folder_blue.png', |
||
| 853 | $session_category['session_category']['name'], |
||
| 854 | [], |
||
| 855 | ICON_SIZE_LARGE |
||
| 856 | ); |
||
| 857 | |||
| 858 | if (api_is_platform_admin()) { |
||
| 859 | $params['right_actions'] = '<a href="'.api_get_path( |
||
| 860 | WEB_CODE_PATH |
||
| 861 | ).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon( |
||
| 862 | 'edit.png', |
||
| 863 | get_lang('Edit'), |
||
| 864 | [], |
||
| 865 | ICON_SIZE_SMALL |
||
| 866 | ).'</a>'; |
||
| 867 | } |
||
| 868 | |||
| 869 | $params['title'] = $session_category['session_category']['name']; |
||
| 870 | |||
| 871 | if (api_is_platform_admin()) { |
||
| 872 | $params['link'] = api_get_path( |
||
| 873 | WEB_CODE_PATH |
||
| 874 | ).'admin/session_category_edit.php?&id='.$session_category['session_category']['id']; |
||
| 875 | } |
||
| 876 | |||
| 877 | $session_category_start_date = $session_category['session_category']['date_start']; |
||
| 878 | $session_category_end_date = $session_category['session_category']['date_end']; |
||
| 879 | |||
| 880 | if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00') { |
||
| 881 | $params['subtitle'] = sprintf( |
||
| 882 | get_lang('FromDateXToDateY'), |
||
| 883 | $session_category['session_category']['date_start'], |
||
| 884 | $session_category['session_category']['date_end'] |
||
| 885 | ); |
||
| 886 | } else { |
||
| 887 | if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') { |
||
| 888 | $params['subtitle'] = get_lang('From').' '.$session_category_start_date; |
||
| 889 | } |
||
| 890 | if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') { |
||
| 891 | $params['subtitle'] = get_lang('Until').' '.$session_category_end_date; |
||
| 892 | } |
||
| 893 | } |
||
| 894 | $sessions_with_category .= CourseManager::course_item_parent( |
||
| 895 | CourseManager::course_item_html($params, true), |
||
| 896 | $html_sessions |
||
| 897 | ); |
||
| 898 | } |
||
| 899 | } |
||
| 900 | |||
| 901 | //Pagination |
||
| 902 | $adapter = new FixedAdapter($nbResults, []); |
||
| 903 | $pagerfanta = new Pagerfanta($adapter); |
||
| 904 | $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default |
||
| 905 | $pagerfanta->setCurrentPage($page); // 1 by default |
||
| 906 | |||
| 907 | $this->app['pagerfanta.view.router.name'] = 'userportal'; |
||
| 908 | $this->app['pagerfanta.view.router.params'] = [ |
||
| 909 | 'filter' => $filter, |
||
| 910 | 'type' => 'sessioncategories', |
||
| 911 | 'page' => $page |
||
| 912 | ]; |
||
| 913 | $this->app['template']->assign('pagination', $pagerfanta); |
||
| 914 | } |
||
| 915 | |||
| 916 | return $sessions_with_category; |
||
| 917 | } |
||
| 918 | |||
| 919 | /** |
||
| 920 | * @param int $user_id |
||
| 921 | * @param string $filter current|history |
||
| 922 | * @param int $page |
||
| 923 | * @return bool|null|string |
||
| 924 | */ |
||
| 925 | public function returnSessions($user_id, $filter, $page) |
||
| 926 | { |
||
| 927 | if (empty($user_id)) { |
||
| 928 | return false; |
||
| 929 | } |
||
| 930 | |||
| 931 | $loadHistory = (isset($filter) && $filter == 'history') ? true : false; |
||
| 932 | |||
| 933 | /*$app['session_menu'] = function ($app) use ($loadHistory) { |
||
| 934 | $menu = $app['knp_menu.factory']->createItem( |
||
| 935 | 'root', |
||
| 936 | array( |
||
| 937 | 'childrenAttributes' => array( |
||
| 938 | 'class' => 'nav nav-tabs', |
||
| 939 | 'currentClass' => 'active' |
||
| 940 | ) |
||
| 941 | ) |
||
| 942 | ); |
||
| 943 | |||
| 944 | $current = $menu->addChild( |
||
| 945 | get_lang('Current'), |
||
| 946 | array( |
||
| 947 | 'route' => 'userportal', |
||
| 948 | 'routeParameters' => array( |
||
| 949 | 'filter' => 'current', |
||
| 950 | 'type' => 'sessions' |
||
| 951 | ) |
||
| 952 | ) |
||
| 953 | ); |
||
| 954 | $history = $menu->addChild( |
||
| 955 | get_lang('HistoryTrainingSession'), |
||
| 956 | array( |
||
| 957 | 'route' => 'userportal', |
||
| 958 | 'routeParameters' => array( |
||
| 959 | 'filter' => 'history', |
||
| 960 | 'type' => 'sessions' |
||
| 961 | ) |
||
| 962 | ) |
||
| 963 | ); |
||
| 964 | //@todo use URIVoter |
||
| 965 | if ($loadHistory) { |
||
| 966 | $history->setCurrent(true); |
||
| 967 | } else { |
||
| 968 | $current->setCurrent(true); |
||
| 969 | } |
||
| 970 | |||
| 971 | return $menu; |
||
| 972 | };*/ |
||
| 973 | |||
| 974 | //@todo move this in template |
||
| 975 | //$app['knp_menu.menus'] = array('actions_menu' => 'session_menu'); |
||
| 976 | |||
| 977 | $start = ($page - 1) * $this->maxPerPage; |
||
| 978 | |||
| 979 | if ($loadHistory) { |
||
| 980 | // Load sessions in category in *history*. |
||
| 981 | $nbResults = (int)UserManager::get_sessions_by_category( |
||
| 982 | $user_id, |
||
| 983 | true, |
||
| 984 | true, |
||
| 985 | true, |
||
| 986 | null, |
||
| 987 | null, |
||
| 988 | 'no_category' |
||
| 989 | ); |
||
| 990 | |||
| 991 | $session_categories = UserManager::get_sessions_by_category( |
||
| 992 | $user_id, |
||
| 993 | true, |
||
| 994 | false, |
||
| 995 | true, |
||
| 996 | $start, |
||
| 997 | $this->maxPerPage, |
||
| 998 | 'no_category' |
||
| 999 | ); |
||
| 1000 | } else { |
||
| 1001 | // Load sessions in category. |
||
| 1002 | $nbResults = (int)UserManager::get_sessions_by_category( |
||
| 1003 | $user_id, |
||
| 1004 | false, |
||
| 1005 | true, |
||
| 1006 | false, |
||
| 1007 | null, |
||
| 1008 | null, |
||
| 1009 | 'no_category' |
||
| 1010 | ); |
||
| 1011 | |||
| 1012 | $session_categories = UserManager::get_sessions_by_category( |
||
| 1013 | $user_id, |
||
| 1014 | false, |
||
| 1015 | false, |
||
| 1016 | false, |
||
| 1017 | $start, |
||
| 1018 | $this->maxPerPage, |
||
| 1019 | 'no_category' |
||
| 1020 | ); |
||
| 1021 | } |
||
| 1022 | |||
| 1023 | $html = null; |
||
| 1024 | |||
| 1025 | // Showing history title |
||
| 1026 | if ($loadHistory) { |
||
| 1027 | // $html .= Display::page_subheader(get_lang('HistoryTrainingSession')); |
||
| 1028 | if (empty($session_categories)) { |
||
| 1029 | $html .= get_lang('YouDoNotHaveAnySessionInItsHistory'); |
||
| 1030 | } |
||
| 1031 | } |
||
| 1032 | |||
| 1033 | $load_directories_preview = api_get_setting('document.show_documents_preview') == 'true' ? true : false; |
||
| 1034 | $sessions_with_no_category = $html; |
||
| 1035 | |||
| 1036 | if (isset($session_categories) && !empty($session_categories)) { |
||
| 1037 | foreach ($session_categories as $session_category) { |
||
| 1038 | $session_category_id = $session_category['session_category']['id']; |
||
| 1039 | |||
| 1040 | // Sessions does not belong to a session category |
||
| 1041 | if ($session_category_id == 0) { |
||
| 1042 | |||
| 1043 | // Independent sessions |
||
| 1044 | if (isset($session_category['sessions'])) { |
||
| 1045 | foreach ($session_category['sessions'] as $session) { |
||
| 1046 | $session_id = $session['session_id']; |
||
| 1047 | |||
| 1048 | // Don't show empty sessions. |
||
| 1049 | if (count($session['courses']) < 1) { |
||
| 1050 | continue; |
||
| 1051 | } |
||
| 1052 | |||
| 1053 | // Courses inside the current session. |
||
| 1054 | $date_session_start = $session['access_start_date']; |
||
| 1055 | $date_session_end = $session['access_end_date']; |
||
| 1056 | $coachAccessStartDate = $session['coach_access_start_date']; |
||
| 1057 | $coachAccessEndDate = $session['coach_access_end_date']; |
||
| 1058 | |||
| 1059 | $session_now = time(); |
||
| 1060 | $count_courses_session = 0; |
||
| 1061 | $count_courses_session = 0; |
||
| 1062 | |||
| 1063 | // Loop course content |
||
| 1064 | $html_courses_session = []; |
||
| 1065 | $atLeastOneCourseIsVisible = false; |
||
| 1066 | |||
| 1067 | foreach ($session['courses'] as $course) { |
||
| 1068 | $is_coach_course = api_is_coach($session_id, $course['real_id']); |
||
| 1069 | $allowed_time = 0; |
||
| 1070 | |||
| 1071 | // Read only and accessible |
||
| 1072 | if (api_get_setting('session.hide_courses_in_sessions') == 'false') { |
||
| 1073 | $courseUserHtml = CourseManager::get_logged_user_course_html( |
||
| 1074 | $course, |
||
| 1075 | $session_id, |
||
| 1076 | $load_directories_preview |
||
| 1077 | ); |
||
| 1078 | |||
| 1079 | if (isset($courseUserHtml[1])) { |
||
| 1080 | $course_session = $courseUserHtml[1]; |
||
| 1081 | $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : ''; |
||
| 1082 | $html_courses_session[] = $course_session; |
||
| 1083 | } |
||
| 1084 | } |
||
| 1085 | $count_courses_session++; |
||
| 1086 | } |
||
| 1087 | |||
| 1088 | if ($count_courses_session > 0) { |
||
| 1089 | $params = []; |
||
| 1090 | |||
| 1091 | $params['icon'] = Display::return_icon( |
||
| 1092 | 'window_list.png', |
||
| 1093 | $session['session_name'], |
||
| 1094 | ['id' => 'session_img_'.$session_id], |
||
| 1095 | ICON_SIZE_LARGE |
||
| 1096 | ); |
||
| 1097 | $params['is_session'] = true; |
||
| 1098 | //Default session name |
||
| 1099 | $session_link = $session['session_name']; |
||
| 1100 | $params['link'] = null; |
||
| 1101 | |||
| 1102 | if (api_get_setting('session.session_page_enabled') == 'true' && !api_is_drh()) { |
||
| 1103 | //session name with link |
||
| 1104 | $session_link = Display::tag( |
||
| 1105 | 'a', |
||
| 1106 | $session['session_name'], |
||
| 1107 | [ |
||
| 1108 | 'href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id |
||
| 1109 | ] |
||
| 1110 | ); |
||
| 1111 | $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id; |
||
| 1112 | } |
||
| 1113 | |||
| 1114 | $params['title'] = $session_link; |
||
| 1115 | |||
| 1116 | $moved_status = \SessionManager::getSessionChangeUserReason( |
||
| 1117 | isset($session['moved_status']) ? $session['moved_status'] : '' |
||
| 1118 | ); |
||
| 1119 | $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null; |
||
| 1120 | |||
| 1121 | $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status; |
||
| 1122 | //$params['dates'] = $session['date_message']; |
||
| 1123 | |||
| 1124 | $params['dates'] = \SessionManager::parseSessionDates( |
||
| 1125 | $session |
||
| 1126 | ); |
||
| 1127 | $params['right_actions'] = ''; |
||
| 1128 | if (api_is_platform_admin()) { |
||
| 1129 | $params['right_actions'] .= |
||
| 1130 | Display::url( |
||
| 1131 | Display::return_icon( |
||
| 1132 | 'edit.png', |
||
| 1133 | get_lang('Edit'), |
||
| 1134 | ['align' => 'absmiddle'], |
||
| 1135 | ICON_SIZE_SMALL |
||
| 1136 | ), |
||
| 1137 | api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session_id |
||
| 1138 | ); |
||
| 1139 | } |
||
| 1140 | |||
| 1141 | if (api_get_setting('session.hide_courses_in_sessions') == 'false') { |
||
| 1142 | // $params['extra'] .= $html_courses_session; |
||
| 1143 | } |
||
| 1144 | $courseDataToString = CourseManager::parseCourseListData($html_courses_session); |
||
| 1145 | $sessions_with_no_category .= CourseManager::course_item_parent( |
||
| 1146 | CourseManager::course_item_html($params, true), |
||
| 1147 | $courseDataToString |
||
| 1148 | ); |
||
| 1149 | } |
||
| 1150 | } |
||
| 1151 | } |
||
| 1152 | } |
||
| 1153 | } |
||
| 1154 | |||
| 1155 | /*$adapter = new FixedAdapter($nbResults, array()); |
||
| 1156 | $pagerfanta = new Pagerfanta($adapter); |
||
| 1157 | $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default |
||
| 1158 | $pagerfanta->setCurrentPage($page); // 1 by default |
||
| 1159 | |||
| 1160 | $this->app['pagerfanta.view.router.name'] = 'userportal'; |
||
| 1161 | $this->app['pagerfanta.view.router.params'] = array( |
||
| 1162 | 'filter' => $filter, |
||
| 1163 | 'type' => 'sessions', |
||
| 1164 | 'page' => $page |
||
| 1165 | ); |
||
| 1166 | $this->app['template']->assign('pagination', $pagerfanta);*/ |
||
| 1167 | } |
||
| 1168 | |||
| 1169 | return $sessions_with_no_category; |
||
| 1170 | } |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Shows a welcome message when the user doesn't have any content in |
||
| 1174 | * the course list |
||
| 1175 | * @param object A Template object used to declare variables usable in the given template |
||
| 1176 | * @return void |
||
| 1177 | */ |
||
| 1178 | public function return_welcome_to_course_block($tpl) |
||
| 1194 | } |
||
| 1195 | |||
| 1196 | /** |
||
| 1197 | * @param array |
||
| 1198 | */ |
||
| 1199 | public function returnNavigationLinks($items) |
||
| 1200 | { |
||
| 1201 | // Main navigation section. |
||
| 1202 | // Tabs that are deactivated are added here. |
||
| 1203 | if (!empty($items)) { |
||
| 1204 | $content = '<ul class="nav nav-list">'; |
||
| 1205 | foreach ($items as $section => $navigation_info) { |
||
| 1213 | } |
||
| 1214 | } |
||
| 1215 | } |
||
| 1216 |