Passed
Push — 1.11.x ( c6e91c...ce048c )
by Julito
10:24
created

IndexManager::setGradeBookDependencyBar()   F

Complexity

Conditions 26
Paths > 20000

Size

Total Lines 132
Code Lines 88

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 26
eloc 88
nc 55202
nop 1
dl 0
loc 132
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * Class IndexManager.
7
 */
8
class IndexManager
9
{
10
    const VIEW_BY_DEFAULT = 0;
11
    const VIEW_BY_SESSION = 1;
12
13
    // An instance of the template engine
14
    // No need to initialize because IndexManager is not static,
15
    // and the constructor immediately instantiates a Template
16
    public $tpl;
17
    public $name = '';
18
    public $home = '';
19
    public $default_home = 'home/';
20
21
    /**
22
     * Construct.
23
     *
24
     * @param string $title
25
     */
26
    public function __construct($title)
27
    {
28
        $this->tpl = new Template($title);
29
        $this->home = api_get_home_path();
30
        $this->user_id = api_get_user_id();
31
        $this->load_directories_preview = false;
32
33
        // Load footer plugins systematically
34
        /*$config = api_get_settings_params(array('subkey = ? ' => 'customfooter', ' AND category = ? ' => 'Plugins'));
35
        if (!empty($config)) {
36
            foreach ($config as $fooid => $configrecord) {
37
                $canonic = preg_replace('/^customfooter_/', '', $configrecord['variable']);
38
                $footerconfig->$canonic = $configrecord['selected_value'];
39
            }
40
            if (!empty($footerconfig->footer_left)) {
41
                $this->tpl->assign('plugin_footer_left', $footerconfig->footer_left);
42
            }
43
            if (!empty($footerconfig->footer_right)) {
44
                $this->tpl->assign('plugin_footer_right', $footerconfig->footer_right);
45
            }
46
        }*/
47
48
        if (api_get_setting('show_documents_preview') === 'true') {
49
            $this->load_directories_preview = true;
50
        }
51
    }
52
53
    /**
54
     * @param $listA
55
     * @param $listB
56
     *
57
     * @return int
58
     */
59
    public static function compareListUserCategory($listA, $listB)
60
    {
61
        if ($listA['title'] == $listB['title']) {
62
            return 0;
63
        }
64
65
        if ($listA['title'] > $listB['title']) {
66
            return 1;
67
        }
68
69
        return -1;
70
    }
71
72
    /**
73
     * @param $view
74
     * @param $userId
75
     */
76
    public static function setDefaultMyCourseView($view, $userId)
77
    {
78
        setcookie('defaultMyCourseView'.$userId, $view);
79
    }
80
81
    /**
82
     * @param bool $setLoginForm
83
     */
84
    public function set_login_form($setLoginForm = true)
85
    {
86
        global $loginFailed;
87
        $this->tpl->setLoginForm($setLoginForm);
88
    }
89
90
    /**
91
     * @param array $personal_course_list
92
     */
93
    public function return_exercise_block($personal_course_list)
94
    {
95
        $exercise_list = [];
96
        if (!empty($personal_course_list)) {
97
            foreach ($personal_course_list as $course_item) {
98
                $course_code = $course_item['c'];
99
                $session_id = $course_item['id_session'];
100
101
                $exercises = ExerciseLib::get_exercises_to_be_taken(
102
                    $course_code,
103
                    $session_id
104
                );
105
106
                foreach ($exercises as $exercise_item) {
107
                    $exercise_item['course_code'] = $course_code;
108
                    $exercise_item['session_id'] = $session_id;
109
                    $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC');
110
111
                    $exercise_list[] = $exercise_item;
112
                }
113
            }
114
            if (!empty($exercise_list)) {
115
                $exercise_list = msort($exercise_list, 'tms');
116
                $my_exercise = $exercise_list[0];
117
                $url = Display::url(
118
                    $my_exercise['title'],
119
                    api_get_path(
120
                        WEB_CODE_PATH
121
                    ).'exercise/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']
122
                );
123
                $this->tpl->assign('exercise_url', $url);
124
                $this->tpl->assign(
125
                    'exercise_end_date',
126
                    api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT)
127
                );
128
            }
129
        }
130
    }
131
132
    /**
133
     * @param bool $show_slide
134
     *
135
     * @return string|null
136
     */
137
    public function return_announcements($show_slide = true)
138
    {
139
        $hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected');
140
        $currentUserId = api_get_user_id();
141
        if ($hideAnnouncements === 'true' && empty($currentUserId)) {
142
            return null;
143
        }
144
        $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
145
        $announcement = (int) $announcement;
146
147
        if (!api_is_anonymous() && $this->user_id) {
148
            $visibility = SystemAnnouncementManager::getCurrentUserVisibility();
149
            if ($show_slide) {
150
                $announcements = SystemAnnouncementManager::displayAnnouncementsSlider(
151
                    $visibility,
152
                    $announcement
153
                );
154
            } else {
155
                $announcements = SystemAnnouncementManager::displayAllAnnouncements(
156
                    $visibility,
157
                    $announcement
158
                );
159
            }
160
        } else {
161
            if ($show_slide) {
162
                $announcements = SystemAnnouncementManager::displayAnnouncementsSlider(
163
                    SystemAnnouncementManager::VISIBLE_GUEST,
164
                    $announcement
165
                );
166
            } else {
167
                $announcements = SystemAnnouncementManager::displayAllAnnouncements(
168
                    SystemAnnouncementManager::VISIBLE_GUEST,
169
                    $announcement
170
                );
171
            }
172
        }
173
174
        return $announcements;
175
    }
176
177
    /**
178
     * Alias for the online_logout() function.
179
     *
180
     * @param bool  $redirect   Whether to ask online_logout to redirect to index.php or not
181
     * @param array $logoutInfo Information stored by local.inc.php before new context ['uid'=> x, 'cid'=>y, 'sid'=>z]
182
     */
183
    public function logout($redirect = true, $logoutInfo = [])
184
    {
185
        online_logout($this->user_id, true);
186
        Event::courseLogout($logoutInfo);
187
    }
188
189
    /**
190
     * Includes a created page.
191
     *
192
     * @param bool $getIncludedFile Whether to include a file as provided in URL GET or simply the homepage
193
     *
194
     * @return string
195
     */
196
    public function return_home_page($getIncludedFile = false)
197
    {
198
        $userId = api_get_user_id();
199
        // Including the page for the news
200
        $html = '';
201
        if ($getIncludedFile === true) {
202
            if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
203
                $open = @(string) file_get_contents($this->home.$_GET['include']);
204
                $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
205
            }
206
        } else {
207
            // Hiding home top when user not connected.
208
            $hideTop = api_get_setting('hide_home_top_when_connected');
209
            if ($hideTop == 'true' && !empty($userId)) {
210
                return $html;
211
            }
212
213
            if (!empty($_SESSION['user_language_choice'])) {
214
                $user_selected_language = $_SESSION['user_language_choice'];
215
            } elseif (!empty($_SESSION['_user']['language'])) {
216
                $user_selected_language = $_SESSION['_user']['language'];
217
            } else {
218
                $user_selected_language = api_get_setting('platformLanguage');
219
            }
220
221
            $home_top_temp = '';
222
            // Try language specific home
223
            if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
224
                $home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
225
            }
226
227
            // Try default language home
228
            if (empty($home_top_temp)) {
229
                if (file_exists($this->home.'home_top.html')) {
230
                    $home_top_temp = file_get_contents($this->home.'home_top.html');
231
                } else {
232
                    if (file_exists($this->default_home.'home_top.html')) {
233
                        $home_top_temp = file_get_contents($this->default_home.'home_top.html');
234
                    }
235
                }
236
            }
237
238
            if (trim($home_top_temp) == '' && api_is_platform_admin()) {
239
                $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
240
            } else {
241
                $home_top_temp;
242
            }
243
            $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
244
            $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
245
        }
246
247
        return $html;
248
    }
249
250
    /**
251
     * @return string
252
     */
253
    public function return_notice()
254
    {
255
        $user_selected_language = api_get_interface_language();
256
        // Notice
257
        $home_notice = @(string) file_get_contents($this->home.'home_notice_'.$user_selected_language.'.html');
258
        if (empty($home_notice)) {
259
            $home_notice = @(string) file_get_contents($this->home.'home_notice.html');
260
        }
261
        if (!empty($home_notice)) {
262
            $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
263
        }
264
265
        return $home_notice;
266
    }
267
268
    /**
269
     * @return string
270
     */
271
    public function return_help()
272
    {
273
        $user_selected_language = api_get_interface_language();
274
        $platformLanguage = api_get_setting('platformLanguage');
275
276
        // Help section.
277
        /* Hide right menu "general" and other parts on anonymous right menu. */
278
        if (!isset($user_selected_language)) {
279
            $user_selected_language = $platformLanguage;
280
        }
281
282
        $html = '';
283
        $home_menu = @(string) file_get_contents($this->home.'home_menu_'.$user_selected_language.'.html');
284
        if (!empty($home_menu)) {
285
            $html = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
286
        }
287
288
        return $html;
289
    }
290
291
    /**
292
     * Generate the block for show a panel with links to My Certificates and Certificates Search pages.
293
     *
294
     * @return array The HTML code for the panel
295
     */
296
    public function returnSkillLinks()
297
    {
298
        $items = [];
299
300
        if (!api_is_anonymous() &&
301
            api_get_configuration_value('hide_my_certificate_link') === false
302
        ) {
303
            $items[] = [
304
                'icon' => Display::return_icon('graduation.png', get_lang('MyCertificates')),
305
                'link' => api_get_path(WEB_CODE_PATH).'gradebook/my_certificates.php',
306
                'title' => get_lang('MyCertificates'),
307
            ];
308
        }
309
        if (api_get_setting('allow_public_certificates') == 'true') {
310
            $items[] = [
311
                'icon' => Display::return_icon('search_graduation.png', get_lang('Search')),
312
                'link' => api_get_path(WEB_CODE_PATH).'gradebook/search.php',
313
                'title' => get_lang('Search'),
314
            ];
315
        }
316
317
        $myCertificate = GradebookUtils::get_certificate_by_user_id(
318
            +0,
319
            $this->user_id
320
        );
321
322
        if ($myCertificate) {
0 ignored issues
show
introduced by
$myCertificate is of type Datetime, thus it always evaluated to true.
Loading history...
323
            $items[] = [
324
                'icon' => Display::return_icon(
325
                    'skill-badges.png',
326
                    get_lang('MyGeneralCertificate'),
327
                    null,
328
                    ICON_SIZE_SMALL
329
                ),
330
                'link' => api_get_path(WEB_CODE_PATH).'social/my_skills_report.php?a=generate_custom_skill',
331
                'title' => get_lang('MyGeneralCertificate'),
332
            ];
333
        }
334
335
        if (Skill::isAllowed(api_get_user_id(), false)) {
336
            $items[] = [
337
                'icon' => Display::return_icon('skill-badges.png', get_lang('MySkills')),
338
                'link' => api_get_path(WEB_CODE_PATH).'social/my_skills_report.php',
339
                'title' => get_lang('MySkills'),
340
            ];
341
            $allowSkillsManagement = api_get_setting('allow_hr_skills_management') == 'true';
342
            if (($allowSkillsManagement && api_is_drh()) || api_is_platform_admin()) {
343
                $items[] = [
344
                    'icon' => Display::return_icon('edit-skill.png', get_lang('MySkills')),
345
                    'link' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php',
346
                    'title' => get_lang('ManageSkills'),
347
                ];
348
            }
349
        }
350
351
        return $items;
352
    }
353
354
    /**
355
     * Reacts on a failed login:
356
     * Displays an explanation with a link to the registration form.
357
     *
358
     * @version 1.0.1
359
     */
360
    public function handle_login_failed()
361
    {
362
        return $this->tpl->handleLoginFailed();
363
    }
364
365
    /**
366
     * Display list of courses in a category.
367
     * (for anonymous users).
368
     *
369
     * @version 1.1
370
     *
371
     * @author  Patrick Cool <[email protected]>, Ghent University - refactoring and code cleaning
372
     * @author  Julio Montoya <[email protected]>, Beeznest template modifs
373
     */
374
    public function return_courses_in_categories()
375
    {
376
        $result = '';
377
        $stok = Security::get_token();
378
379
        // Initialization.
380
        $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
381
        $web_course_path = api_get_path(WEB_COURSE_PATH);
382
        $category = isset($_GET['category']) ? Database::escape_string($_GET['category']) : '';
383
        $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
384
385
        // Database table definitions.
386
        $main_course_table = Database::get_main_table(TABLE_MAIN_COURSE);
387
        $main_category_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
388
389
        // Get list of courses in category $category.
390
        $sql = "SELECT * FROM $main_course_table cours
391
                WHERE category_code = '".$category."'
392
                ORDER BY title, UPPER(visual_code)";
393
394
        // Showing only the courses of the current access_url_id.
395
        if (api_is_multiple_url_enabled()) {
396
            $url_access_id = api_get_current_access_url_id();
397
            if ($url_access_id != -1) {
398
                $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
399
                $sql = "SELECT * FROM $main_course_table as course
400
                        INNER JOIN $tbl_url_rel_course as url_rel_course
401
                        ON (url_rel_course.c_id = course.id)
402
                        WHERE
403
                            access_url_id = $url_access_id AND
404
                            category_code = '".$category."'
405
                        ORDER BY title, UPPER(visual_code)";
406
            }
407
        }
408
409
        // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
410
        $queryResult = Database::query($sql);
411
        while ($course_result = Database::fetch_array($queryResult)) {
412
            $course_list[] = $course_result;
413
        }
414
        $numRows = Database::num_rows($queryResult);
415
416
        // $setting_show_also_closed_courses
417
        if ($user_identified) {
418
            if ($setting_show_also_closed_courses) {
419
                $platform_visible_courses = '';
420
            } else {
421
                $platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
422
            }
423
        } else {
424
            if ($setting_show_also_closed_courses) {
425
                $platform_visible_courses = '';
426
            } else {
427
                $platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
428
            }
429
        }
430
        $sqlGetSubCatList = "
431
                    SELECT  t1.name,
432
                            t1.code,
433
                            t1.parent_id,
434
                            t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
435
                    FROM $main_category_table t1
436
                    LEFT JOIN $main_category_table t2
437
                    ON t1.code=t2.parent_id
438
                    LEFT JOIN $main_course_table t3
439
                    ON (t3.category_code = t1.code $platform_visible_courses)
440
                    WHERE t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
441
                    GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count
442
                    ORDER BY t1.tree_pos, t1.name";
443
444
        // Showing only the category of courses of the current access_url_id
445
        if (api_is_multiple_url_enabled()) {
446
            $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
447
            $courseCategoryCondition = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
448
449
            $url_access_id = api_get_current_access_url_id();
450
            if ($url_access_id != -1) {
451
                $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
452
                $sqlGetSubCatList = "
453
                    SELECT t1.name,
454
                            t1.code,
455
                            t1.parent_id,
456
                            t1.children_count,
457
                            COUNT(DISTINCT t3.code) AS nbCourse
458
                    FROM $main_category_table t1
459
                    $courseCategoryCondition
460
                    LEFT JOIN $main_category_table t2 ON t1.code = t2.parent_id
461
                    LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses)
462
                    INNER JOIN $tbl_url_rel_course as url_rel_course
463
                    ON (url_rel_course.c_id = t3.id)
464
                    WHERE
465
                        url_rel_course.access_url_id = $url_access_id AND
466
                        t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
467
                    GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count
468
                    ORDER BY t1.tree_pos, t1.name";
469
            }
470
        }
471
472
        $resCats = Database::query($sqlGetSubCatList);
473
        $thereIsSubCat = false;
474
475
        $htmlTitre = '';
476
        $htmlListCat = '';
477
        if (Database::num_rows($resCats) > 0) {
478
            $htmlListCat = Display::page_header(get_lang('CatList'));
479
            $htmlListCat .= '<ul>';
480
            while ($catLine = Database::fetch_array($resCats)) {
481
                $category_has_open_courses = self::category_has_open_courses($catLine['code']);
482
                if ($category_has_open_courses) {
483
                    // The category contains courses accessible to anonymous visitors.
484
                    $htmlListCat .= '<li>';
485
                    $htmlListCat .= '<a href="'.api_get_self(
486
                        ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
487
                    if (api_get_setting('show_number_of_courses') == 'true') {
488
                        $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
489
                    }
490
                    $htmlListCat .= "</li>";
491
                    $thereIsSubCat = true;
492
                } elseif ($catLine['children_count'] > 0) {
493
                    // The category has children, subcategories.
494
                    $htmlListCat .= '<li>';
495
                    $htmlListCat .= '<a href="'.api_get_self(
496
                        ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
497
                    $htmlListCat .= "</li>";
498
                    $thereIsSubCat = true;
499
                } elseif (api_get_setting('show_empty_course_categories') == 'true') {
500
                    /* End changed code to eliminate the (0 courses) after empty categories. */
501
                    $htmlListCat .= '<li>';
502
                    $htmlListCat .= $catLine['name'];
503
                    $htmlListCat .= "</li>";
504
                    $thereIsSubCat = true;
505
                } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
506
                // TODO: deprecate this useless feature - this includes removing system variable
507
                if (empty($htmlTitre)) {
508
                    $htmlTitre = '<p>';
509
                    if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
510
                        $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
511
                    }
512
                    $htmlTitre .= "</p>";
513
                }
514
            }
515
            $htmlListCat .= "</ul>";
516
        }
517
        $result .= $htmlTitre;
518
        if ($thereIsSubCat) {
519
            $result .= $htmlListCat;
520
        }
521
        while ($categoryName = Database::fetch_array($resCats)) {
522
            $result .= '<h3>'.$categoryName['name']."</h3>\n";
523
        }
524
525
        $courses_list_string = '';
526
        $courses_shown = 0;
527
        if ($numRows > 0) {
528
            $courses_list_string .= Display::page_header(get_lang('CourseList'));
529
            $courses_list_string .= "<ul>";
530
            if (api_get_user_id()) {
531
                $courses_of_user = [];
532
                $coursesByUserCategory = CourseManager::getCoursesByUserCourseCategory(api_get_user_id());
533
                if (!empty($coursesByUserCategory)) {
534
                    foreach ($coursesByUserCategory as $courseItem) {
535
                        $courses_of_user[$courseItem['code']] = $courseItem;
536
                    }
537
                }
538
            }
539
            foreach ($course_list as $course) {
540
                // $setting_show_also_closed_courses
541
                if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) {
542
                    continue;
543
                }
544
                if (!$setting_show_also_closed_courses) {
545
                    // If we do not show the closed courses
546
                    // we only show the courses that are open to the world (to everybody)
547
                    // and the courses that are open to the platform (if the current user is a registered user.
548
                    if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) ||
549
                        ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)
550
                    ) {
551
                        $courses_shown++;
552
                        $courses_list_string .= "<li>";
553
                        $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
554
                        $course_details = [];
555
                        if (api_get_setting('display_coursecode_in_courselist') === 'true') {
556
                            $course_details[] = '('.$course['visual_code'].')';
557
                        }
558
                        if (api_get_setting('display_teacher_in_courselist') === 'true') {
559
                            $course_details[] = CourseManager::getTeacherListFromCourseCodeToString($course['code']);
560
                        }
561
                        if (api_get_setting('show_different_course_language') === 'true' &&
562
                            $course['course_language'] != api_get_setting('platformLanguage')
563
                        ) {
564
                            $course_details[] = $course['course_language'];
565
                        }
566
                        $courses_list_string .= implode(' - ', $course_details);
567
                        $courses_list_string .= "</li>";
568
                    }
569
                } else {
570
                    // We DO show the closed courses.
571
                    // The course is accessible if (link to the course homepage):
572
                    // 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);
573
                    // 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);
574
                    // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
575
                    // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
576
                    // 5. the user is the platform admin api_is_platform_admin().
577
578
                    $courses_shown++;
579
                    $courses_list_string .= "<li>";
580
                    if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
581
                        || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
582
                        || ($user_identified && array_key_exists($course['code'], $courses_of_user)
583
                            && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
584
                        || $courses_of_user[$course['code']]['status'] == '1'
585
                        || api_is_platform_admin()
586
                    ) {
587
                        $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
588
                    }
589
                    $courses_list_string .= $course['title'];
590
                    if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
591
                        || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
592
                        || ($user_identified && array_key_exists($course['code'], $courses_of_user)
593
                            && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
594
                        || $courses_of_user[$course['code']]['status'] == '1'
595
                        || api_is_platform_admin()
596
                    ) {
597
                        $courses_list_string .= '</a><br />';
598
                    }
599
                    $course_details = [];
600
                    if (api_get_setting('display_coursecode_in_courselist') === 'true') {
601
                        $course_details[] = '('.$course['visual_code'].')';
602
                    }
603
                    if (api_get_setting('display_teacher_in_courselist') === 'true') {
604
                        if (!empty($course['tutor_name'])) {
605
                            $course_details[] = $course['tutor_name'];
606
                        }
607
                    }
608
                    if (api_get_setting('show_different_course_language') == 'true' &&
609
                        $course['course_language'] != api_get_setting('platformLanguage')
610
                    ) {
611
                        $course_details[] = $course['course_language'];
612
                    }
613
614
                    $courses_list_string .= implode(' - ', $course_details);
615
                    // We display a subscription link if:
616
                    // 1. it is allowed to register for the course and if the course is not already in
617
                    // the courselist of the user and if the user is identified
618
                    // 2.
619
                    if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
620
                        if ($course['subscribe'] == '1') {
621
                            $courses_list_string .= '&nbsp;<a class="btn btn-primary" href="main/auth/courses.php?action=subscribe_course&sec_token='.$stok.'&course_code='.$course['code'].'&category_code='.Security::remove_XSS(
622
                                    $_GET['category']
623
                                ).'">'.get_lang('Subscribe').'</a><br />';
624
                        } else {
625
                            $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
626
                        }
627
                    }
628
                    $courses_list_string .= "</li>";
629
                } //end else
630
            } // end foreach
631
            $courses_list_string .= "</ul>";
632
        }
633
        if ($courses_shown > 0) {
634
            // Only display the list of courses and categories if there was more than
635
            // 0 courses visible to the world (we're in the anonymous list here).
636
            $result .= $courses_list_string;
637
        }
638
        if ($category != '') {
639
            $result .= '<p><a href="'.api_get_self().'">'
640
                .Display:: return_icon('back.png', get_lang('BackToHomePage'))
641
                .get_lang('BackToHomePage').'</a></p>';
642
        }
643
644
        return $result;
645
    }
646
647
    /**
648
     * This function checks if there are courses that are open to the world in the platform course categories
649
     * (=faculties).
650
     *
651
     * @param string $category
652
     *
653
     * @return bool
654
     */
655
    public function category_has_open_courses($category)
656
    {
657
        $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
658
        $main_course_table = Database::get_main_table(TABLE_MAIN_COURSE);
659
        $category = Database::escape_string($category);
660
        $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
661
        $sql_result = Database::query($sql_query);
662
        while ($course = Database::fetch_array($sql_result)) {
663
            if (!$setting_show_also_closed_courses) {
664
                if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) ||
665
                    ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)
666
                ) {
667
                    return true; //at least one open course
668
                }
669
            } else {
670
                if (isset($course['visibility'])) {
671
                    return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
672
                }
673
            }
674
        }
675
676
        return false;
677
    }
678
679
    /**
680
     * Adds a form to let users login.
681
     *
682
     * @version 1.1
683
     */
684
    public function display_login_form()
685
    {
686
        return $this->tpl->displayLoginForm();
687
    }
688
689
    /**
690
     * @return string
691
     *
692
     * @todo use FormValidator
693
     */
694
    public function return_search_block()
695
    {
696
        $html = '';
697
        if (api_get_setting('search_enabled') == 'true') {
698
            $search_btn = get_lang('Search');
699
            $search_content = '<form action="main/search/" method="post">
700
                <div class="form-group">
701
                <input type="text" id="query" class="form-control" name="query" value="" />
702
                <button class="btn btn-default" type="submit" name="submit" value="'.$search_btn.'" />'.
703
                $search_btn.' </button>
704
                </div></form>';
705
            $html .= $this->showRightBlock(get_lang('Search'), $search_content, 'search_block');
706
        }
707
708
        return $html;
709
    }
710
711
    /**
712
     * @param        $title
713
     * @param        $content
714
     * @param string $id
715
     * @param array  $params
716
     * @param string $idAccordion
717
     * @param string $idCollapse
718
     *
719
     * @return string
720
     *
721
     * @todo use the template system
722
     */
723
    public function showRightBlock(
724
        $title,
725
        $content,
726
        $id = '',
727
        $params = [],
728
        $idAccordion = '',
729
        $idCollapse = ''
730
    ) {
731
        $html = '';
732
        if (!empty($idAccordion)) {
733
            $html .= '<div class="panel-group" id="'.$idAccordion.'" role="tablist" aria-multiselectable="true">';
734
            $html .= '<div class="panel panel-default" id="'.$id.'">';
735
            $html .= '<div class="panel-heading" role="tab"><h4 class="panel-title">';
736
            $html .= '<a role="button" data-toggle="collapse" data-parent="#'.$idAccordion.'" href="#'.$idCollapse.'" aria-expanded="true" aria-controls="'.$idCollapse.'">'.$title.'</a>';
737
            $html .= '</h4></div>';
738
            $html .= '<div id="'.$idCollapse.'" class="panel-collapse collapse in" role="tabpanel">';
739
            $html .= '<div class="panel-body">'.$content.'</div>';
740
            $html .= '</div></div></div>';
741
        } else {
742
            if (!empty($id)) {
743
                $params['id'] = $id;
744
            }
745
            $params['class'] = 'panel panel-default';
746
            $html = null;
747
            if (!empty($title)) {
748
                $html .= '<div class="panel-heading">'.$title.'</div>';
749
            }
750
            $html .= '<div class="panel-body">'.$content.'</div>';
751
            $html = Display::div($html, $params);
752
        }
753
754
        return $html;
755
    }
756
757
    /**
758
     * @return string
759
     */
760
    public function returnClassesBlock()
761
    {
762
        if (api_get_setting('show_groups_to_users') !== 'true') {
763
            return '';
764
        }
765
766
        $items = [];
767
768
        $usergroup = new UserGroup();
769
        if (api_is_platform_admin()) {
770
            $items[] = [
771
                'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add',
772
                'title' => get_lang('AddClasses'),
773
            ];
774
        } else {
775
            if (api_is_teacher() && $usergroup->allowTeachers()) {
776
                $items[] = [
777
                    'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php',
778
                    'title' => get_lang('ClassList'),
779
                ];
780
            }
781
        }
782
783
        $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
784
        if (!empty($usergroup_list)) {
785
            foreach ($usergroup_list as $group_id) {
786
                $data = $usergroup->get($group_id);
787
                $items[] = [
788
                    'link' => api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id'],
789
                    'title' => $data['name'],
790
                ];
791
            }
792
        }
793
794
        $html = $this->showRightBlock(
795
            get_lang('Classes'),
796
            self::returnRightBlockItems($items),
797
            'classes_block'
798
        );
799
800
        return $html;
801
    }
802
803
    /**
804
     * @return string
805
     */
806
    public function return_user_image_block()
807
    {
808
        $html = '';
809
        if (!api_is_anonymous()) {
810
            $userPicture = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
811
            $content = null;
812
813
            if (api_get_setting('allow_social_tool') == 'true') {
814
                $content .= '<a style="text-align:center" href="'.api_get_path(WEB_CODE_PATH).'social/home.php">
815
                <img class="img-circle" src="'.$userPicture.'"></a>';
816
            } else {
817
                $content .= '<a style="text-align:center" href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php">
818
                <img class="img-circle" title="'.get_lang('EditProfile').'" src="'.$userPicture.'"></a>';
819
            }
820
821
            $html = $this->showRightBlock(
822
                null,
823
                $content,
824
                'user_image_block',
825
                ['style' => 'text-align:center;']
826
            );
827
        }
828
829
        return $html;
830
    }
831
832
    /**
833
     * @return array
834
     */
835
    public function return_profile_block()
836
    {
837
        $userInfo = api_get_user_info();
838
        $userId = api_get_user_id();
839
        if (empty($userId)) {
840
            return;
841
        }
842
843
        $items = [];
844
        $userGroup = new UserGroup();
845
        //  @todo Add a platform setting to add the user image.
846
        if (api_get_setting('allow_message_tool') === 'true') {
847
            // New messages.
848
            $number_of_new_messages = MessageManager::getCountNewMessages();
849
            // New contact invitations.
850
            $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(
851
                $userId
852
            );
853
854
            // New group invitations sent by a moderator.
855
            $group_pending_invitations = $userGroup->get_groups_by_user(
856
                $userId,
857
                GROUP_USER_PERMISSION_PENDING_INVITATION,
858
                false
859
            );
860
            $group_pending_invitations = count($group_pending_invitations);
861
            $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
862
            $cant_msg = Display::badge($number_of_new_messages);
863
864
            $items[] = [
865
                'class' => 'inbox-message-social',
866
                'icon' => Display::return_icon('inbox.png', get_lang('Inbox')),
867
                'link' => api_get_path(WEB_CODE_PATH).'messages/inbox.php',
868
                'title' => get_lang('Inbox').$cant_msg,
869
            ];
870
871
            $items[] = [
872
                'class' => 'new-message-social',
873
                'icon' => Display::return_icon('new-message.png', get_lang('Compose')),
874
                'link' => api_get_path(WEB_CODE_PATH).'messages/new_message.php',
875
                'title' => get_lang('Compose'),
876
            ];
877
878
            if (api_get_setting('allow_social_tool') == 'true') {
879
                $total_invitations = Display::badge($total_invitations);
880
                $items[] = [
881
                    'class' => 'invitations-social',
882
                    'icon' => Display::return_icon('invitations.png', get_lang('PendingInvitations')),
883
                    'link' => api_get_path(WEB_CODE_PATH).'social/invitations.php',
884
                    'title' => get_lang('PendingInvitations').$total_invitations,
885
                ];
886
            }
887
        }
888
889
        $items[] = [
890
            'class' => 'personal-data',
891
            'icon' => Display::return_icon('database.png', get_lang('PersonalDataReport')),
892
            'link' => api_get_path(WEB_CODE_PATH).'social/personal_data.php',
893
            'title' => get_lang('PersonalDataReport'),
894
        ];
895
896
        if (api_get_configuration_value('allow_my_files_link_in_homepage')) {
897
            if (api_get_setting('allow_my_files') !== 'false') {
898
                $items[] = [
899
                    'class' => 'myfiles-social',
900
                    'icon' => Display::return_icon('sn-files.png', get_lang('Files')),
901
                    'link' => api_get_path(WEB_CODE_PATH).'social/myfiles.php',
902
                    'title' => get_lang('MyFiles'),
903
                ];
904
            }
905
        }
906
907
        $items[] = [
908
            'class' => 'profile-social',
909
            'icon' => Display::return_icon('edit-profile.png', get_lang('EditProfile')),
910
            'link' => Display::getProfileEditionLink($userId),
911
            'title' => get_lang('EditProfile'),
912
        ];
913
914
        if (api_get_configuration_value('show_link_request_hrm_user') &&
915
            api_is_drh()
916
        ) {
917
            $label = get_lang('RequestLinkingToUser');
918
            $items[] = [
919
                'icon' => Display::return_icon('new_group.png', $label),
920
                'link' => api_get_path(WEB_CODE_PATH).'social/require_user_linking.php',
921
                'title' => $label,
922
            ];
923
        }
924
925
        if (bbb::showGlobalConferenceLink($userInfo)) {
926
            $bbb = new bbb('', '', true, api_get_user_id());
927
            $url = $bbb->getListingUrl();
928
            $items[] = [
929
                'class' => 'video-conference',
930
                'icon' => Display::return_icon(
931
                    'bbb.png',
932
                    get_lang('VideoConference')
933
                ),
934
                'link' => $url,
935
                'title' => get_lang('VideoConference'),
936
            ];
937
        }
938
939
        if (true === api_get_configuration_value('whispeak_auth_enabled')) {
940
            $itemTitle = WhispeakAuthPlugin::create()->get_title();
941
942
            $items[] = [
943
                'class' => 'whispeak-enrollment',
944
                'icon' => Display::return_icon('addworkuser.png', $itemTitle),
945
                'link' => WhispeakAuthPlugin::getEnrollmentUrl(),
946
                'title' => $itemTitle,
947
            ];
948
        }
949
950
        return $items;
951
    }
952
953
    /**
954
     * @return array
955
     */
956
    public function return_navigation_links()
957
    {
958
        $items = [];
959
        // Deleting the myprofile link.
960
        if (api_get_setting('allow_social_tool') == 'true') {
961
            unset($this->tpl->menu_navigation['myprofile']);
962
        }
963
964
        $hideMenu = api_get_configuration_value('hide_main_navigation_menu');
965
        if ($hideMenu === true) {
966
            return '';
967
        }
968
969
        // Main navigation section.
970
        // Tabs that are deactivated are added here.
971
        if (!empty($this->tpl->menu_navigation)) {
972
            foreach ($this->tpl->menu_navigation as $section => $navigation_info) {
973
                $items[] = [
974
                    'icon' => null,
975
                    'link' => $navigation_info['url'],
976
                    'title' => $navigation_info['title'],
977
                ];
978
            }
979
        }
980
981
        return $items;
982
    }
983
984
    /**
985
     * @return array
986
     */
987
    public function return_course_block()
988
    {
989
        if (api_get_configuration_value('hide_course_sidebar')) {
990
            return '';
991
        }
992
        $isHrm = api_is_drh();
993
        $show_create_link = false;
994
        $show_course_link = false;
995
        if (api_is_allowed_to_create_course()) {
996
            $show_create_link = true;
997
        }
998
999
        if (api_get_setting('allow_students_to_browse_courses') === 'true') {
1000
            $show_course_link = true;
1001
        }
1002
1003
        $items = [];
1004
1005
        // My account section
1006
        if ($show_create_link) {
1007
            if (api_get_setting('course_validation') == 'true' && !api_is_platform_admin()) {
1008
                $items[] = [
1009
                    'class' => 'add-course',
1010
                    'icon' => Display::return_icon('new-course.png', get_lang('CreateCourseRequest')),
1011
                    'link' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php',
1012
                    'title' => get_lang('CreateCourseRequest'),
1013
                ];
1014
            } else {
1015
                $items[] = [
1016
                    'class' => 'add-course',
1017
                    'icon' => Display::return_icon('new-course.png', get_lang('CourseCreate')),
1018
                    'link' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php',
1019
                    'title' => get_lang('CourseCreate'),
1020
                ];
1021
            }
1022
1023
            if (SessionManager::allowToManageSessions()) {
1024
                $items[] = [
1025
                    'class' => 'add-session',
1026
                    'icon' => Display::return_icon('session.png', get_lang('AddSession')),
1027
                    'link' => api_get_path(WEB_CODE_PATH).'session/session_add.php',
1028
                    'title' => get_lang('AddSession'),
1029
                ];
1030
            }
1031
        }
1032
1033
        // Sort courses
1034
        if (api_get_configuration_value('view_grid_courses') != true) {
1035
            $items[] = [
1036
                'class' => 'order-course',
1037
                'icon' => Display::return_icon('order-course.png', get_lang('SortMyCourses')),
1038
                'link' => api_get_path(WEB_CODE_PATH).'auth/sort_my_courses.php',
1039
                'title' => get_lang('SortMyCourses'),
1040
            ];
1041
        }
1042
1043
        // Session history
1044
        if (isset($_GET['history']) && intval($_GET['history']) == 1) {
1045
            $items[] = [
1046
                'class' => 'history-course',
1047
                'icon' => Display::return_icon('history-course.png', get_lang('DisplayTrainingList')),
1048
                'link' => api_get_path(WEB_PATH).'user_portal.php',
1049
                'title' => get_lang('DisplayTrainingList'),
1050
            ];
1051
        } else {
1052
            $items[] = [
1053
                'class' => 'history-course',
1054
                'icon' => Display::return_icon('history-course.png', get_lang('HistoryTrainingSessions')),
1055
                'link' => api_get_path(WEB_PATH).'user_portal.php?history=1',
1056
                'title' => get_lang('HistoryTrainingSessions'),
1057
            ];
1058
        }
1059
1060
        if ($isHrm) {
1061
            $items[] = [
1062
                'link' => api_get_path(WEB_CODE_PATH).'auth/hrm_courses.php',
1063
                'title' => get_lang('HrmAssignedUsersCourseList'),
1064
            ];
1065
        }
1066
1067
        // Course catalog
1068
        if ($show_course_link) {
1069
            if (!api_is_drh()) {
1070
                $items[] = [
1071
                    'class' => 'list-course',
1072
                    'icon' => Display::return_icon('catalog-course.png', get_lang('CourseCatalog')),
1073
                    'link' => api_get_path(WEB_CODE_PATH).'auth/courses.php',
1074
                    'title' => get_lang('CourseCatalog'),
1075
                ];
1076
            } else {
1077
                $items[] = [
1078
                    'link' => api_get_path(WEB_CODE_PATH).'dashboard/index.php',
1079
                    'title' => get_lang('Dashboard'),
1080
                ];
1081
            }
1082
        }
1083
1084
        return $items;
1085
    }
1086
1087
    /**
1088
     * Shows a welcome message when the user doesn't have any content in the course list.
1089
     */
1090
    public function return_welcome_to_course_block()
1091
    {
1092
        $count_courses = CourseManager::count_courses();
1093
        $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
1094
1095
        $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
1096
        $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
1097
1098
        $this->tpl->assign('course_catalog_url', $course_catalog_url);
1099
        $this->tpl->assign('course_list_url', $course_list_url);
1100
        $this->tpl->assign('course_catalog_link', Display::url(get_lang('Here'), $course_catalog_url));
1101
        $this->tpl->assign('course_list_link', Display::url(get_lang('Here'), $course_list_url));
1102
        $this->tpl->assign('count_courses', $count_courses);
1103
1104
        return $this->tpl->fetch($tpl);
1105
    }
1106
1107
    /**
1108
     * @return array
1109
     */
1110
    public function return_hot_courses()
1111
    {
1112
        return CourseManager::return_hot_courses(30, 6);
1113
    }
1114
1115
    /**
1116
     * UserPortal view for session, return the HTML of the course list.
1117
     *
1118
     * @param $user_id
1119
     *
1120
     * @return string
1121
     */
1122
    public function returnCoursesAndSessionsViewBySession($user_id)
1123
    {
1124
        $sessionCount = 0;
1125
        $courseCount = 0;
1126
        $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
1127
1128
        if ($load_history) {
1129
            // Load sessions in category in *history*
1130
            $session_categories = UserManager::get_sessions_by_category($user_id, true);
1131
        } else {
1132
            // Load sessions in category
1133
            $session_categories = UserManager::get_sessions_by_category($user_id, false);
1134
        }
1135
1136
        $html = '';
1137
        $loadDirs = $this->load_directories_preview;
1138
1139
        // If we're not in the history view...
1140
        $listCoursesInfo = [];
1141
        if (!isset($_GET['history'])) {
1142
            // Display special courses
1143
            $specialCoursesResult = CourseManager::returnSpecialCourses(
1144
                $user_id,
1145
                $loadDirs
1146
            );
1147
            $specialCourses = $specialCoursesResult;
1148
1149
            if ($specialCourses) {
1150
                $this->tpl->assign('courses', $specialCourses);
1151
                $html = $this->tpl->fetch(
1152
                    $this->tpl->get_template('/user_portal/classic_courses_without_category.tpl')
1153
                );
1154
            }
1155
1156
            // Display courses
1157
            // [code=>xxx, real_id=>000]
1158
            $listCourses = CourseManager::get_courses_list_by_user_id(
1159
                $user_id,
1160
                false
1161
            );
1162
1163
            foreach ($listCourses as $i => $listCourseCodeId) {
1164
                if (isset($listCourseCodeId['special_course'])) {
1165
                    continue;
1166
                }
1167
                $courseCategory = CourseManager::getUserCourseCategoryForCourse(
1168
                    $user_id,
1169
                    $listCourseCodeId['real_id']
1170
                );
1171
1172
                $userCatTitle = '';
1173
                $userCategoryId = 0;
1174
                if ($courseCategory) {
1175
                    $userCategoryId = $courseCategory['user_course_cat'];
1176
                    $userCatTitle = $courseCategory['title'];
1177
                }
1178
1179
                $listCourse = api_get_course_info_by_id($listCourseCodeId['real_id']);
1180
                $listCoursesInfo[] = [
1181
                    'course' => $listCourse,
1182
                    'code' => $listCourseCodeId['code'],
1183
                    'id' => $listCourseCodeId['real_id'],
1184
                    'title' => $listCourse['title'],
1185
                    'userCatId' => $userCategoryId,
1186
                    'userCatTitle' => $userCatTitle,
1187
                ];
1188
                $courseCount++;
1189
            }
1190
            usort($listCoursesInfo, 'self::compareByCourse');
1191
        }
1192
1193
        $listCoursesInSession = [];
1194
        if (is_array($session_categories)) {
1195
            // all courses that are in a session
1196
            $listCoursesInSession = SessionManager::getNamedSessionCourseForCoach($user_id);
1197
        }
1198
1199
        // we got all courses
1200
        // for each user category, sorted alphabetically, display courses
1201
        $listUserCategories = CourseManager::get_user_course_categories($user_id);
1202
        $listCoursesAlreadyDisplayed = [];
1203
        uasort($listUserCategories, "self::compareListUserCategory");
1204
        $listUserCategories[0] = '';
1205
1206
        $html .= '<div class="session-view-block">';
1207
        foreach ($listUserCategories as $userCategoryId => $userCat) {
1208
            // add user category
1209
            $userCategoryHtml = '';
1210
            if ($userCategoryId != 0) {
1211
                $userCategoryHtml = '<div class="session-view-well ">';
1212
                $userCategoryHtml .= self::getHtmlForUserCategory($userCategoryId, $userCat['title']);
1213
            }
1214
            // look for course in this userCat in session courses : $listCoursesInSession
1215
            $htmlCategory = '';
1216
            if (isset($listCoursesInSession[$userCategoryId])) {
1217
                // list of courses in this user cat
1218
                foreach ($listCoursesInSession[$userCategoryId]['courseInUserCatList'] as $i => $listCourse) {
1219
                    // add course
1220
                    $listCoursesAlreadyDisplayed[$listCourse['courseId']] = 1;
1221
                    if ($userCategoryId == 0) {
1222
                        $htmlCategory .= '<div class="panel panel-default">';
1223
                    } else {
1224
                        $htmlCategory .= '<div class="panel panel-default">';
1225
                    }
1226
                    $htmlCategory .= '<div class="panel-body">';
1227
                    $coursesInfo = $listCourse['course'];
1228
1229
                    $htmlCategory .= self::getHtmlForCourse(
1230
                        $coursesInfo,
1231
                        $userCategoryId,
1232
                        1,
1233
                        $loadDirs
1234
                    );
1235
                    // list of session category
1236
                    $htmlSessionCategory = '<div class="session-view-row" style="display:none;" id="courseblock-'.$coursesInfo['real_id'].'">';
1237
                    foreach ($listCourse['sessionCatList'] as $listCategorySession) {
1238
                        // add session category
1239
                        $htmlSessionCategory .= self::getHtmlSessionCategory(
1240
                            $listCategorySession['catSessionId'],
1241
                            $listCategorySession['catSessionName']
1242
                        );
1243
                        // list of session
1244
                        $htmlSession = ''; // start
1245
                        foreach ($listCategorySession['sessionList'] as $listSession) {
1246
                            // add session
1247
                            $htmlSession .= '<div class="session-view-row">';
1248
                            $htmlSession .= self::getHtmlForSession(
1249
                                $listSession['sessionId'],
1250
                                $listSession['sessionName'],
1251
                                $listCategorySession['catSessionId'],
1252
                                $coursesInfo
1253
                            );
1254
                            $htmlSession .= '</div>';
1255
                            $sessionCount++;
1256
                        }
1257
                        $htmlSession .= ''; // end session block
1258
                        $htmlSessionCategory .= $htmlSession;
1259
                    }
1260
                    $htmlSessionCategory .= '</div>'; // end session cat block
1261
                    $htmlCategory .= $htmlSessionCategory.'</div></div>';
1262
                    $htmlCategory .= ''; // end course block
1263
                }
1264
                $userCategoryHtml .= $htmlCategory;
1265
            }
1266
1267
            // look for courses in this userCat in not in session courses : $listCoursesInfo
1268
            // if course not already added
1269
            $htmlCategory = '';
1270
            foreach ($listCoursesInfo as $i => $listCourse) {
1271
                if ($listCourse['userCatId'] == $userCategoryId &&
1272
                    !isset($listCoursesAlreadyDisplayed[$listCourse['id']])
1273
                ) {
1274
                    if ($userCategoryId != 0) {
1275
                        $htmlCategory .= '<div class="panel panel-default">';
1276
                    } else {
1277
                        $htmlCategory .= '<div class="panel panel-default">';
1278
                    }
1279
1280
                    $htmlCategory .= '<div class="panel-body">';
1281
                    $htmlCategory .= self::getHtmlForCourse(
1282
                        $listCourse['course'],
1283
                        $userCategoryId,
1284
                        0,
1285
                        $loadDirs
1286
                    );
1287
                    $htmlCategory .= '</div></div>';
1288
                }
1289
            }
1290
            $htmlCategory .= '';
1291
            $userCategoryHtml .= $htmlCategory; // end user cat block
1292
            if ($userCategoryId != 0) {
1293
                $userCategoryHtml .= '</div>';
1294
            }
1295
            $html .= $userCategoryHtml;
1296
        }
1297
        $html .= '</div>';
1298
1299
        return [
1300
            'html' => $html,
1301
            'sessions' => $session_categories,
1302
            'courses' => $listCoursesInfo,
1303
            'session_count' => $sessionCount,
1304
            'course_count' => $courseCount,
1305
        ];
1306
    }
1307
1308
    /**
1309
     * @param int $userId
1310
     *
1311
     * @return array
1312
     */
1313
    public function returnCourseCategoryListFromUser($userId)
1314
    {
1315
        $sessionCount = 0;
1316
        $courseList = CourseManager::get_courses_list_by_user_id($userId);
1317
        $categoryCodes = CourseManager::getCourseCategoriesFromCourseList($courseList);
1318
        $categories = [];
1319
        foreach ($categoryCodes as $categoryCode) {
1320
            $categories[] = CourseCategory::getCategory($categoryCode);
1321
        }
1322
1323
        $template = new Template('', false, false, false, true, false, false);
1324
        $layout = $template->get_template('user_portal/course_categories.tpl');
1325
        $template->assign('course_categories', $categories);
1326
1327
        return [
1328
            'courses' => $courseList,
1329
            'html' => $template->fetch($layout),
1330
            'course_count' => count($courseList),
1331
            'session_count' => $sessionCount,
1332
        ];
1333
    }
1334
1335
    /**
1336
     * Set grade book dependency progress bar see BT#13099.
1337
     *
1338
     * @param $userId
1339
     *
1340
     * @return bool
1341
     */
1342
    public function setGradeBookDependencyBar($userId)
1343
    {
1344
        $allow = api_get_configuration_value('gradebook_dependency');
1345
1346
        if (api_is_anonymous()) {
1347
            return false;
1348
        }
1349
1350
        if ($allow) {
1351
            $courseAndSessions = $this->returnCoursesAndSessions(
1352
                $userId,
1353
                false,
1354
                '',
1355
                false,
1356
                false
1357
            );
1358
1359
            $courseList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
1360
            $courseList = isset($courseList['courses']) ? $courseList['courses'] : [];
1361
            $mandatoryCourse = [];
1362
            if (!empty($courseList)) {
1363
                foreach ($courseList as $courseId) {
1364
                    $courseInfo = api_get_course_info_by_id($courseId);
1365
                    $mandatoryCourse[] = $courseInfo['code'];
1366
                }
1367
            }
1368
1369
            // @todo improve calls of course info
1370
            $subscribedCourses = !empty($courseAndSessions['courses']) ? $courseAndSessions['courses'] : [];
1371
            $mainCategoryList = [];
1372
            foreach ($subscribedCourses as $courseInfo) {
1373
                $courseCode = $courseInfo['code'];
1374
                $categories = Category::load(null, null, $courseCode);
1375
                /** @var Category $category */
1376
                $category = !empty($categories[0]) ? $categories[0] : [];
1377
                if (!empty($category)) {
1378
                    $mainCategoryList[] = $category;
1379
                }
1380
            }
1381
1382
            $result20 = 0;
1383
            $result80 = 0;
1384
            $countCoursesPassedNoDependency = 0;
1385
            /** @var Category $category */
1386
            foreach ($mainCategoryList as $category) {
1387
                $userFinished = Category::userFinishedCourse(
1388
                    $userId,
1389
                    $category,
1390
                    true
1391
                );
1392
1393
                if ($userFinished) {
1394
                    if (in_array($category->get_course_code(), $mandatoryCourse)) {
1395
                        if ($result20 < 20) {
1396
                            $result20 += 10;
1397
                        }
1398
                    } else {
1399
                        $countCoursesPassedNoDependency++;
1400
                        if ($result80 < 80) {
1401
                            $result80 += 10;
1402
                        }
1403
                    }
1404
                }
1405
            }
1406
1407
            $finalResult = $result20 + $result80;
1408
1409
            $gradeBookList = api_get_configuration_value('gradebook_badge_sidebar');
1410
            $gradeBookList = isset($gradeBookList['gradebooks']) ? $gradeBookList['gradebooks'] : [];
1411
            $badgeList = [];
1412
            foreach ($gradeBookList as $id) {
1413
                $categories = Category::load($id);
1414
                /** @var Category $category */
1415
                $category = !empty($categories[0]) ? $categories[0] : [];
1416
                $badgeList[$id]['name'] = $category->get_name();
1417
                $badgeList[$id]['finished'] = false;
1418
                $badgeList[$id]['skills'] = [];
1419
                if (!empty($category)) {
1420
                    $minToValidate = $category->getMinimumToValidate();
1421
                    $dependencies = $category->getCourseListDependency();
1422
                    $gradeBooksToValidateInDependence = $category->getGradeBooksToValidateInDependence();
1423
                    $countDependenciesPassed = 0;
1424
                    foreach ($dependencies as $courseId) {
1425
                        $courseInfo = api_get_course_info_by_id($courseId);
1426
                        $courseCode = $courseInfo['code'];
1427
                        $categories = Category::load(null, null, $courseCode);
1428
                        $subCategory = !empty($categories[0]) ? $categories[0] : null;
1429
                        if (!empty($subCategory)) {
1430
                            $score = Category::userFinishedCourse(
1431
                                $userId,
1432
                                $subCategory,
1433
                                true
1434
                            );
1435
                            if ($score) {
1436
                                $countDependenciesPassed++;
1437
                            }
1438
                        }
1439
                    }
1440
1441
                    $userFinished =
1442
                        $countDependenciesPassed >= $gradeBooksToValidateInDependence &&
1443
                        $countCoursesPassedNoDependency >= $minToValidate;
1444
1445
                    if ($userFinished) {
1446
                        $badgeList[$id]['finished'] = true;
1447
                    }
1448
1449
                    $objSkill = new Skill();
1450
                    $skills = $category->get_skills();
1451
                    $skillList = [];
1452
                    foreach ($skills as $skill) {
1453
                        $skillList[] = $objSkill->get($skill['id']);
1454
                    }
1455
                    $badgeList[$id]['skills'] = $skillList;
1456
                }
1457
            }
1458
1459
            $this->tpl->assign(
1460
                'grade_book_sidebar',
1461
                true
1462
            );
1463
1464
            $this->tpl->assign(
1465
                'grade_book_progress',
1466
                $finalResult
1467
            );
1468
            $this->tpl->assign('grade_book_badge_list', $badgeList);
1469
1470
            return true;
1471
        }
1472
1473
        return false;
1474
    }
1475
1476
    /**
1477
     * Prints the session and course list (user_portal.php).
1478
     *
1479
     * @param int    $user_id
1480
     * @param bool   $showSessions
1481
     * @param string $categoryCodeFilter
1482
     * @param bool   $useUserLanguageFilterIfAvailable
1483
     * @param bool   $loadHistory
1484
     *
1485
     * @return array
1486
     */
1487
    public function returnCoursesAndSessions(
1488
        $user_id,
1489
        $showSessions = true,
1490
        $categoryCodeFilter = '',
1491
        $useUserLanguageFilterIfAvailable = true,
1492
        $loadHistory = false
1493
    ) {
1494
        $gameModeIsActive = api_get_setting('gamification_mode');
1495
        $viewGridCourses = api_get_configuration_value('view_grid_courses');
1496
        $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info');
1497
        $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl';
1498
        $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl';
1499
        $showAllSessions = api_get_configuration_value('show_all_sessions_on_my_course_page') === true;
1500
1501
        if ($loadHistory) {
1502
            // Load sessions in category in *history*
1503
            $session_categories = UserManager::get_sessions_by_category($user_id, true);
1504
        } else {
1505
            // Load sessions in category
1506
            $session_categories = UserManager::get_sessions_by_category($user_id, false);
1507
        }
1508
1509
        $sessionCount = 0;
1510
        $courseCount = 0;
1511
1512
        // Student info code check (shows student progress information on
1513
        // courses list
1514
        $studentInfo = api_get_configuration_value('course_student_info');
1515
1516
        $studentInfoProgress = !empty($studentInfo['progress']) && $studentInfo['progress'] === true;
1517
        $studentInfoScore = !empty($studentInfo['score']) && $studentInfo['score'] === true;
1518
        $studentInfoCertificate = !empty($studentInfo['certificate']) && $studentInfo['certificate'] === true;
1519
        $courseCompleteList = [];
1520
        $coursesInCategoryCount = 0;
1521
        $coursesNotInCategoryCount = 0;
1522
        $listCourse = '';
1523
        $specialCourseList = '';
1524
1525
        // If we're not in the history view...
1526
        if ($loadHistory === false) {
1527
            // Display special courses.
1528
            $specialCourses = CourseManager::returnSpecialCourses(
1529
                $user_id,
1530
                $this->load_directories_preview,
1531
                $useUserLanguageFilterIfAvailable
1532
            );
1533
1534
            // Display courses.
1535
            $courses = CourseManager::returnCourses(
1536
                $user_id,
1537
                $this->load_directories_preview,
1538
                $useUserLanguageFilterIfAvailable
1539
            );
1540
1541
            // Course option (show student progress)
1542
            // This code will add new variables (Progress, Score, Certificate)
1543
            if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) {
1544
                if (!empty($specialCourses)) {
1545
                    foreach ($specialCourses as $key => $specialCourseInfo) {
1546
                        if ($studentInfoProgress) {
1547
                            $progress = Tracking::get_avg_student_progress(
1548
                                $user_id,
1549
                                $specialCourseInfo['course_code']
1550
                            );
1551
                            $specialCourses[$key]['student_info']['progress'] = $progress === false ? null : $progress;
1552
                        }
1553
1554
                        if ($studentInfoScore) {
1555
                            $percentage_score = Tracking::get_avg_student_score(
1556
                                $user_id,
1557
                                $specialCourseInfo['course_code'],
1558
                                []
1559
                            );
1560
                            $specialCourses[$key]['student_info']['score'] = $percentage_score;
1561
                        }
1562
1563
                        if ($studentInfoCertificate) {
1564
                            $category = Category::load(
1565
                                null,
1566
                                null,
1567
                                $specialCourseInfo['course_code'],
1568
                                null,
1569
                                null,
1570
                                null
1571
                            );
1572
                            $specialCourses[$key]['student_info']['certificate'] = null;
1573
                            if (isset($category[0])) {
1574
                                if ($category[0]->is_certificate_available($user_id)) {
1575
                                    $specialCourses[$key]['student_info']['certificate'] = Display::label(
1576
                                        get_lang('Yes'),
1577
                                        'success'
1578
                                    );
1579
                                } else {
1580
                                    $specialCourses[$key]['student_info']['certificate'] = Display::label(
1581
                                        get_lang('No'),
1582
                                        'danger'
1583
                                    );
1584
                                }
1585
                            }
1586
                        }
1587
                    }
1588
                }
1589
1590
                if (isset($courses['in_category'])) {
1591
                    foreach ($courses['in_category'] as $key1 => $value) {
1592
                        if (isset($courses['in_category'][$key1]['courses'])) {
1593
                            foreach ($courses['in_category'][$key1]['courses'] as $key2 => $courseInCatInfo) {
1594
                                $courseCode = $courseInCatInfo['course_code'];
1595
                                if ($studentInfoProgress) {
1596
                                    $progress = Tracking::get_avg_student_progress(
1597
                                        $user_id,
1598
                                        $courseCode
1599
                                    );
1600
                                    $courses['in_category'][$key1]['courses'][$key2]['student_info']['progress'] = $progress === false ? null : $progress;
1601
                                }
1602
1603
                                if ($studentInfoScore) {
1604
                                    $percentage_score = Tracking::get_avg_student_score(
1605
                                        $user_id,
1606
                                        $courseCode,
1607
                                        []
1608
                                    );
1609
                                    $courses['in_category'][$key1]['courses'][$key2]['student_info']['score'] = $percentage_score;
1610
                                }
1611
1612
                                if ($studentInfoCertificate) {
1613
                                    $category = Category::load(
1614
                                        null,
1615
                                        null,
1616
                                        $courseCode,
1617
                                        null,
1618
                                        null,
1619
                                        null
1620
                                    );
1621
                                    $courses['in_category'][$key1]['student_info']['certificate'] = null;
1622
                                    $isCertificateAvailable = $category[0]->is_certificate_available($user_id);
1623
                                    if (isset($category[0])) {
1624
                                        if ($viewGridCourses) {
1625
                                            if ($isCertificateAvailable) {
1626
                                                $courses['in_category'][$key1]['student_info']['certificate'] = get_lang(
1627
                                                    'Yes'
1628
                                                );
1629
                                            } else {
1630
                                                $courses['in_category'][$key1]['student_info']['certificate'] = get_lang(
1631
                                                    'No'
1632
                                                );
1633
                                            }
1634
                                        } else {
1635
                                            if ($isCertificateAvailable) {
1636
                                                $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
1637
                                                    get_lang('Yes'),
1638
                                                    'success'
1639
                                                );
1640
                                            } else {
1641
                                                $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
1642
                                                    get_lang('No'),
1643
                                                    'danger'
1644
                                                );
1645
                                            }
1646
                                        }
1647
                                    }
1648
                                }
1649
                            }
1650
                        }
1651
                    }
1652
                }
1653
1654
                if (isset($courses['not_category'])) {
1655
                    foreach ($courses['not_category'] as $key => $courseNotInCatInfo) {
1656
                        $courseCode = $courseNotInCatInfo['course_code'];
1657
                        if ($studentInfoProgress) {
1658
                            $progress = Tracking::get_avg_student_progress(
1659
                                $user_id,
1660
                                $courseCode
1661
                            );
1662
                            $courses['not_category'][$key]['student_info']['progress'] = $progress === false ? null : $progress;
1663
                        }
1664
1665
                        if ($studentInfoScore) {
1666
                            $percentage_score = Tracking::get_avg_student_score(
1667
                                $user_id,
1668
                                $courseCode,
1669
                                []
1670
                            );
1671
                            $courses['not_category'][$key]['student_info']['score'] = $percentage_score;
1672
                        }
1673
1674
                        if ($studentInfoCertificate) {
1675
                            $category = Category::load(
1676
                                null,
1677
                                null,
1678
                                $courseCode,
1679
                                null,
1680
                                null,
1681
                                null
1682
                            );
1683
                            $courses['not_category'][$key]['student_info']['certificate'] = null;
1684
1685
                            if (isset($category[0])) {
1686
                                $certificateAvailable = $category[0]->is_certificate_available($user_id);
1687
                                if ($viewGridCourses) {
1688
                                    if ($certificateAvailable) {
1689
                                        $courses['not_category'][$key]['student_info']['certificate'] = get_lang('Yes');
1690
                                    } else {
1691
                                        $courses['not_category'][$key]['student_info']['certificate'] = get_lang('No');
1692
                                    }
1693
                                } else {
1694
                                    if ($certificateAvailable) {
1695
                                        $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
1696
                                            get_lang('Yes'),
1697
                                            'success'
1698
                                        );
1699
                                    } else {
1700
                                        $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
1701
                                            get_lang('No'),
1702
                                            'danger'
1703
                                        );
1704
                                    }
1705
                                }
1706
                            }
1707
                        }
1708
                    }
1709
                }
1710
            }
1711
1712
            if ($viewGridCourses) {
1713
                $coursesWithoutCategoryTemplate = '/user_portal/grid_courses_without_category.tpl';
1714
                $coursesWithCategoryTemplate = '/user_portal/grid_courses_with_category.tpl';
1715
            }
1716
1717
            if ($specialCourses) {
1718
                if ($categoryCodeFilter) {
1719
                    $specialCourses = self::filterByCategory($specialCourses, $categoryCodeFilter);
1720
                }
1721
                $this->tpl->assign('courses', $specialCourses);
1722
                $specialCourseList = $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate));
1723
                $courseCompleteList = array_merge($courseCompleteList, $specialCourses);
1724
            }
1725
1726
            if ($courses['in_category'] || $courses['not_category']) {
1727
                foreach ($courses['in_category'] as $courseData) {
1728
                    if (!empty($courseData['courses'])) {
1729
                        $coursesInCategoryCount += count($courseData['courses']);
1730
                        $courseCompleteList = array_merge($courseCompleteList, $courseData['courses']);
1731
                    }
1732
                }
1733
1734
                $coursesNotInCategoryCount += count($courses['not_category']);
1735
                $courseCompleteList = array_merge($courseCompleteList, $courses['not_category']);
1736
1737
                if ($categoryCodeFilter) {
1738
                    $courses['in_category'] = self::filterByCategory(
1739
                        $courses['in_category'],
1740
                        $categoryCodeFilter
1741
                    );
1742
                    $courses['not_category'] = self::filterByCategory(
1743
                        $courses['not_category'],
1744
                        $categoryCodeFilter
1745
                    );
1746
                }
1747
1748
                $this->tpl->assign('courses', $courses['not_category']);
1749
                $this->tpl->assign('categories', $courses['in_category']);
1750
1751
                $listCourse = $this->tpl->fetch($this->tpl->get_template($coursesWithCategoryTemplate));
1752
                $listCourse .= $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate));
1753
            }
1754
1755
            $courseCount = count($specialCourses) + $coursesInCategoryCount + $coursesNotInCategoryCount;
1756
        }
1757
1758
        $sessions_with_category = '';
1759
        $sessions_with_no_category = '';
1760
        $collapsable = api_get_configuration_value('allow_user_session_collapsable');
1761
        $collapsableLink = '';
1762
        if ($collapsable) {
1763
            $collapsableLink = api_get_path(WEB_PATH).'user_portal.php?action=collapse_session';
1764
        }
1765
1766
        $extraFieldValue = new ExtraFieldValue('session');
1767
        if ($showSessions) {
1768
            $coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link');
1769
            $coursesListSessionStyle = $coursesListSessionStyle === false ? 1 : $coursesListSessionStyle;
1770
            if (api_is_drh()) {
1771
                $coursesListSessionStyle = 1;
1772
            }
1773
1774
            $portalShowDescription = api_get_setting('show_session_description') === 'true';
1775
1776
            // Declared listSession variable
1777
            $listSession = [];
1778
            // Get timestamp in UTC to compare to DB values (in UTC by convention)
1779
            $session_now = strtotime(api_get_utc_datetime(time()));
1780
            if (is_array($session_categories)) {
1781
                foreach ($session_categories as $session_category) {
1782
                    $session_category_id = $session_category['session_category']['id'];
1783
                    // Sessions and courses that are not in a session category
1784
                    if (empty($session_category_id) &&
1785
                        isset($session_category['sessions'])
1786
                    ) {
1787
                        // Independent sessions
1788
                        foreach ($session_category['sessions'] as $session) {
1789
                            $session_id = $session['session_id'];
1790
1791
                            // Don't show empty sessions.
1792
                            if (count($session['courses']) < 1) {
1793
                                continue;
1794
                            }
1795
1796
                            // Courses inside the current session.
1797
                            $date_session_start = $session['access_start_date'];
1798
                            $date_session_end = $session['access_end_date'];
1799
                            $coachAccessStartDate = $session['coach_access_start_date'];
1800
                            $coachAccessEndDate = $session['coach_access_end_date'];
1801
                            $count_courses_session = 0;
1802
1803
                            // Loop course content
1804
                            $html_courses_session = [];
1805
                            $atLeastOneCourseIsVisible = false;
1806
                            $markAsOld = false;
1807
                            $markAsFuture = false;
1808
1809
                            foreach ($session['courses'] as $course) {
1810
                                $is_coach_course = api_is_coach($session_id, $course['real_id']);
1811
                                $allowed_time = 0;
1812
                                $allowedEndTime = true;
1813
1814
                                if (!empty($date_session_start)) {
1815
                                    if ($is_coach_course) {
1816
                                        $allowed_time = api_strtotime($coachAccessStartDate);
1817
                                    } else {
1818
                                        $allowed_time = api_strtotime($date_session_start);
1819
                                    }
1820
1821
                                    $endSessionToTms = null;
1822
                                    if (!isset($_GET['history'])) {
1823
                                        if (!empty($date_session_end)) {
1824
                                            if ($is_coach_course) {
1825
                                                // if coach end date is empty we use the default end date
1826
                                                if (empty($coachAccessEndDate)) {
1827
                                                    $endSessionToTms = api_strtotime($date_session_end);
1828
                                                    if ($session_now > $endSessionToTms) {
1829
                                                        $allowedEndTime = false;
1830
                                                    }
1831
                                                } else {
1832
                                                    $endSessionToTms = api_strtotime($coachAccessEndDate);
1833
                                                    if ($session_now > $endSessionToTms) {
1834
                                                        $allowedEndTime = false;
1835
                                                    }
1836
                                                }
1837
                                            } else {
1838
                                                $endSessionToTms = api_strtotime($date_session_end);
1839
                                                if ($session_now > $endSessionToTms) {
1840
                                                    $allowedEndTime = false;
1841
                                                }
1842
                                            }
1843
                                        }
1844
                                    }
1845
                                }
1846
1847
                                if ($showAllSessions) {
1848
                                    if ($allowed_time < $session_now && $allowedEndTime === false) {
1849
                                        $markAsOld = true;
1850
                                    }
1851
                                    if ($allowed_time > $session_now && $endSessionToTms > $session_now) {
1852
                                        $markAsFuture = true;
1853
                                    }
1854
                                    $allowedEndTime = true;
1855
                                    $allowed_time = 0;
1856
                                }
1857
1858
                                if ($session_now >= $allowed_time && $allowedEndTime) {
1859
                                    // Read only and accessible.
1860
                                    $atLeastOneCourseIsVisible = true;
1861
                                    if (api_get_setting('hide_courses_in_sessions') === 'false') {
1862
                                        $courseUserHtml = CourseManager::get_logged_user_course_html(
1863
                                            $course,
1864
                                            $session_id,
1865
                                            'session_course_item',
1866
                                            true,
1867
                                            $this->load_directories_preview
1868
                                        );
1869
                                        if (isset($courseUserHtml[1])) {
1870
                                            $course_session = $courseUserHtml[1];
1871
                                            $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
1872
1873
                                            // Course option (show student progress)
1874
                                            // This code will add new variables (Progress, Score, Certificate)
1875
                                            if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) {
1876
                                                if ($studentInfoProgress) {
1877
                                                    $progress = Tracking::get_avg_student_progress(
1878
                                                        $user_id,
1879
                                                        $course['course_code'],
1880
                                                        [],
1881
                                                        $session_id
1882
                                                    );
1883
                                                    $course_session['student_info']['progress'] = $progress === false ? null : $progress;
1884
                                                }
1885
1886
                                                if ($studentInfoScore) {
1887
                                                    $percentage_score = Tracking::get_avg_student_score(
1888
                                                        $user_id,
1889
                                                        $course['course_code'],
1890
                                                        [],
1891
                                                        $session_id
1892
                                                    );
1893
                                                    $course_session['student_info']['score'] = $percentage_score;
1894
                                                }
1895
1896
                                                if ($studentInfoCertificate) {
1897
                                                    $category = Category::load(
1898
                                                        null,
1899
                                                        null,
1900
                                                        $course['course_code'],
1901
                                                        null,
1902
                                                        null,
1903
                                                        $session_id
1904
                                                    );
1905
                                                    $course_session['student_info']['certificate'] = null;
1906
                                                    if (isset($category[0])) {
1907
                                                        if ($category[0]->is_certificate_available($user_id)) {
1908
                                                            $course_session['student_info']['certificate'] = Display::label(
1909
                                                                get_lang('Yes'),
1910
                                                                'success'
1911
                                                            );
1912
                                                        } else {
1913
                                                            $course_session['student_info']['certificate'] = Display::label(
1914
                                                                get_lang('No')
1915
                                                            );
1916
                                                        }
1917
                                                    }
1918
                                                }
1919
                                            }
1920
                                            $html_courses_session[] = $course_session;
1921
                                        }
1922
                                    }
1923
                                    $count_courses_session++;
1924
                                }
1925
                            }
1926
1927
                            // No courses to show.
1928
                            if ($atLeastOneCourseIsVisible === false) {
1929
                                if (empty($html_courses_session)) {
1930
                                    continue;
1931
                                }
1932
                            }
1933
1934
                            if ($count_courses_session > 0) {
1935
                                $params = [
1936
                                    'id' => $session_id,
1937
                                ];
1938
                                $session_box = Display::getSessionTitleBox($session_id);
1939
                                $coachId = $session_box['id_coach'];
1940
                                $imageField = $extraFieldValue->get_values_by_handler_and_field_variable(
1941
                                    $session_id,
1942
                                    'image'
1943
                                );
1944
1945
                                $params['category_id'] = $session_box['category_id'];
1946
                                $params['title'] = $session_box['title'];
1947
                                $params['id_coach'] = $coachId;
1948
                                $params['coach_url'] = api_get_path(WEB_AJAX_PATH).
1949
                                    'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId;
1950
                                $params['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
1951
                                $params['coach_avatar'] = UserManager::getUserPicture(
1952
                                    $coachId,
1953
                                    USER_IMAGE_SIZE_SMALL
1954
                                );
1955
                                $params['date'] = $session_box['dates'];
1956
                                $params['image'] = isset($imageField['value']) ? $imageField['value'] : null;
1957
                                $params['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
1958
                                $params['show_actions'] = SessionManager::cantEditSession($session_id);
1959
1960
                                if ($collapsable) {
1961
                                    $collapsableData = SessionManager::getCollapsableData(
1962
                                        $user_id,
1963
                                        $session_id,
1964
                                        $extraFieldValue,
1965
                                        $collapsableLink
1966
                                    );
1967
                                    $params['collapsed'] = $collapsableData['collapsed'];
1968
                                    $params['collapsable_link'] = $collapsableData['collapsable_link'];
1969
                                }
1970
1971
                                $params['show_description'] = $session_box['show_description'] == 1 && $portalShowDescription;
1972
                                $params['description'] = $session_box['description'];
1973
                                $params['visibility'] = $session_box['visibility'];
1974
                                $params['show_simple_session_info'] = $showSimpleSessionInfo;
1975
                                $params['course_list_session_style'] = $coursesListSessionStyle;
1976
                                $params['num_users'] = $session_box['num_users'];
1977
                                $params['num_courses'] = $session_box['num_courses'];
1978
                                $params['course_categories'] = CourseManager::getCourseCategoriesFromCourseList(
1979
                                    $html_courses_session
1980
                                );
1981
                                $params['courses'] = $html_courses_session;
1982
                                $params['is_old'] = $markAsOld;
1983
                                $params['is_future'] = $markAsFuture;
1984
1985
                                if ($showSimpleSessionInfo) {
1986
                                    $params['subtitle'] = self::getSimpleSessionDetails(
1987
                                        $session_box['coach'],
1988
                                        $session_box['dates'],
1989
                                        isset($session_box['duration']) ? $session_box['duration'] : null
1990
                                    );
1991
                                }
1992
1993
                                if ($gameModeIsActive) {
1994
                                    $params['stars'] = GamificationUtils::getSessionStars(
1995
                                        $params['id'],
1996
                                        $this->user_id
1997
                                    );
1998
                                    $params['progress'] = GamificationUtils::getSessionProgress(
1999
                                        $params['id'],
2000
                                        $this->user_id
2001
                                    );
2002
                                    $params['points'] = GamificationUtils::getSessionPoints(
2003
                                        $params['id'],
2004
                                        $this->user_id
2005
                                    );
2006
                                }
2007
                                $listSession[] = $params;
2008
                                $sessionCount++;
2009
                            }
2010
                        }
2011
                    } else {
2012
                        // All sessions included in
2013
                        $count_courses_session = 0;
2014
                        $html_sessions = '';
2015
                        if (isset($session_category['sessions'])) {
2016
                            foreach ($session_category['sessions'] as $session) {
2017
                                $session_id = $session['session_id'];
2018
2019
                                // Don't show empty sessions.
2020
                                if (count($session['courses']) < 1) {
2021
                                    continue;
2022
                                }
2023
2024
                                $date_session_start = $session['access_start_date'];
2025
                                $date_session_end = $session['access_end_date'];
2026
                                $coachAccessStartDate = $session['coach_access_start_date'];
2027
                                $coachAccessEndDate = $session['coach_access_end_date'];
2028
                                $html_courses_session = [];
2029
                                $count = 0;
2030
                                $markAsOld = false;
2031
                                $markAsFuture = false;
2032
2033
                                foreach ($session['courses'] as $course) {
2034
                                    $is_coach_course = api_is_coach($session_id, $course['real_id']);
2035
                                    $allowed_time = 0;
2036
                                    $allowedEndTime = true;
2037
2038
                                    if (!empty($date_session_start)) {
2039
                                        if ($is_coach_course) {
2040
                                            $allowed_time = api_strtotime($coachAccessStartDate);
2041
                                        } else {
2042
                                            $allowed_time = api_strtotime($date_session_start);
2043
                                        }
2044
2045
                                        if (!isset($_GET['history'])) {
2046
                                            if (!empty($date_session_end)) {
2047
                                                if ($is_coach_course) {
2048
                                                    // if coach end date is empty we use the default end date
2049
                                                    if (empty($coachAccessEndDate)) {
2050
                                                        $endSessionToTms = api_strtotime($date_session_end);
2051
                                                        if ($session_now > $endSessionToTms) {
2052
                                                            $allowedEndTime = false;
2053
                                                        }
2054
                                                    } else {
2055
                                                        $endSessionToTms = api_strtotime($coachAccessEndDate);
2056
                                                        if ($session_now > $endSessionToTms) {
2057
                                                            $allowedEndTime = false;
2058
                                                        }
2059
                                                    }
2060
                                                } else {
2061
                                                    $endSessionToTms = api_strtotime($date_session_end);
2062
                                                    if ($session_now > $endSessionToTms) {
2063
                                                        $allowedEndTime = false;
2064
                                                    }
2065
                                                }
2066
                                            }
2067
                                        }
2068
                                    }
2069
2070
                                    if ($showAllSessions) {
2071
                                        if ($allowed_time < $session_now && $allowedEndTime == false) {
2072
                                            $markAsOld = true;
2073
                                        }
2074
                                        if ($allowed_time > $session_now && $endSessionToTms > $session_now) {
2075
                                            $markAsFuture = true;
2076
                                        }
2077
                                        $allowedEndTime = true;
2078
                                        $allowed_time = 0;
2079
                                    }
2080
2081
                                    if ($session_now >= $allowed_time && $allowedEndTime) {
2082
                                        if (api_get_setting('hide_courses_in_sessions') === 'false') {
2083
                                            $c = CourseManager::get_logged_user_course_html(
2084
                                                $course,
2085
                                                $session_id,
2086
                                                'session_course_item'
2087
                                            );
2088
                                            if (isset($c[1])) {
2089
                                                $html_courses_session[] = $c[1];
2090
                                            }
2091
                                        }
2092
                                        $count_courses_session++;
2093
                                        $count++;
2094
                                    }
2095
                                }
2096
2097
                                $sessionParams = [];
2098
                                // Category
2099
                                if ($count > 0) {
2100
                                    $session_box = Display::getSessionTitleBox($session_id);
2101
                                    $sessionParams[0]['id'] = $session_id;
2102
                                    $sessionParams[0]['date'] = $session_box['dates'];
2103
                                    $sessionParams[0]['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
2104
                                    $sessionParams[0]['course_list_session_style'] = $coursesListSessionStyle;
2105
                                    $sessionParams[0]['title'] = $session_box['title'];
2106
                                    $sessionParams[0]['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
2107
                                    $sessionParams[0]['show_actions'] = SessionManager::cantEditSession($session_id);
2108
                                    $sessionParams[0]['courses'] = $html_courses_session;
2109
                                    $sessionParams[0]['show_simple_session_info'] = $showSimpleSessionInfo;
2110
                                    $sessionParams[0]['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
2111
                                    $sessionParams[0]['is_old'] = $markAsOld;
2112
                                    $sessionParams[0]['is_future'] = $markAsFuture;
2113
2114
                                    if ($collapsable) {
2115
                                        $collapsableData = SessionManager::getCollapsableData(
2116
                                            $user_id,
2117
                                            $session_id,
2118
                                            $extraFieldValue,
2119
                                            $collapsableLink
2120
                                        );
2121
                                        $sessionParams[0]['collapsable_link'] = $collapsableData['collapsable_link'];
2122
                                        $sessionParams[0]['collapsed'] = $collapsableData['collapsed'];
2123
                                    }
2124
2125
                                    if ($showSimpleSessionInfo) {
2126
                                        $sessionParams[0]['subtitle'] = self::getSimpleSessionDetails(
2127
                                            $session_box['coach'],
2128
                                            $session_box['dates'],
2129
                                            isset($session_box['duration']) ? $session_box['duration'] : null
2130
                                        );
2131
                                    }
2132
2133
                                    $this->tpl->assign('session', $sessionParams);
2134
                                    $this->tpl->assign('show_tutor', api_get_setting('show_session_coach') === 'true');
2135
                                    $this->tpl->assign('gamification_mode', $gameModeIsActive);
2136
                                    $this->tpl->assign(
2137
                                        'remove_session_url',
2138
                                        api_get_configuration_value('remove_session_url')
2139
                                    );
2140
                                    $this->tpl->assign(
2141
                                        'hide_session_dates_in_user_portal',
2142
                                        api_get_configuration_value('hide_session_dates_in_user_portal')
2143
                                    );
2144
2145
                                    if ($viewGridCourses) {
2146
                                        $html_sessions .= $this->tpl->fetch(
2147
                                            $this->tpl->get_template('/user_portal/grid_session.tpl')
2148
                                        );
2149
                                    } else {
2150
                                        $html_sessions .= $this->tpl->fetch(
2151
                                            $this->tpl->get_template('user_portal/classic_session.tpl')
2152
                                        );
2153
                                    }
2154
                                    $sessionCount++;
2155
                                }
2156
                            }
2157
                        }
2158
2159
                        if ($count_courses_session > 0) {
2160
                            $categoryParams = [
2161
                                'id' => $session_category['session_category']['id'],
2162
                                'title' => $session_category['session_category']['name'],
2163
                                'show_actions' => api_is_platform_admin(),
2164
                                'subtitle' => '',
2165
                                'sessions' => $html_sessions,
2166
                            ];
2167
2168
                            $session_category_start_date = $session_category['session_category']['date_start'];
2169
                            $session_category_end_date = $session_category['session_category']['date_end'];
2170
                            if ($session_category_start_date == '0000-00-00') {
2171
                                $session_category_start_date = '';
2172
                            }
2173
2174
                            if ($session_category_end_date == '0000-00-00') {
2175
                                $session_category_end_date = '';
2176
                            }
2177
2178
                            if (!empty($session_category_start_date) &&
2179
                                !empty($session_category_end_date)
2180
                            ) {
2181
                                $categoryParams['subtitle'] = sprintf(
2182
                                    get_lang('FromDateXToDateY'),
2183
                                    $session_category_start_date,
2184
                                    $session_category_end_date
2185
                                );
2186
                            } else {
2187
                                if (!empty($session_category_start_date)) {
2188
                                    $categoryParams['subtitle'] = get_lang('From').' '.$session_category_start_date;
2189
                                }
2190
2191
                                if (!empty($session_category_end_date)) {
2192
                                    $categoryParams['subtitle'] = get_lang('Until').' '.$session_category_end_date;
2193
                                }
2194
                            }
2195
2196
                            $this->tpl->assign('session_category', $categoryParams);
2197
                            $sessions_with_category .= $this->tpl->fetch(
2198
                                $this->tpl->get_template('user_portal/session_category.tpl')
2199
                            );
2200
                        }
2201
                    }
2202
                }
2203
2204
                $allCoursesInSessions = [];
2205
                foreach ($listSession as $currentSession) {
2206
                    $coursesInSessions = $currentSession['courses'];
2207
                    unset($currentSession['courses']);
2208
                    foreach ($coursesInSessions as $coursesInSession) {
2209
                        $coursesInSession['session'] = $currentSession;
2210
                        $allCoursesInSessions[] = $coursesInSession;
2211
                    }
2212
                }
2213
2214
                $this->tpl->assign('all_courses', $allCoursesInSessions);
2215
                $this->tpl->assign('session', $listSession);
2216
                $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false));
2217
                $this->tpl->assign('gamification_mode', $gameModeIsActive);
2218
                $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url'));
2219
                $this->tpl->assign(
2220
                    'hide_session_dates_in_user_portal',
2221
                    api_get_configuration_value('hide_session_dates_in_user_portal')
2222
                );
2223
2224
                if ($viewGridCourses) {
2225
                    $sessions_with_no_category = $this->tpl->fetch(
2226
                        $this->tpl->get_template('/user_portal/grid_session.tpl')
2227
                    );
2228
                } else {
2229
                    $sessions_with_no_category = $this->tpl->fetch(
2230
                        $this->tpl->get_template('user_portal/classic_session.tpl')
2231
                    );
2232
                }
2233
            }
2234
        }
2235
2236
        return [
2237
            'courses' => $courseCompleteList,
2238
            'sessions' => $session_categories,
2239
            'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse),
2240
            'session_count' => $sessionCount,
2241
            'course_count' => $courseCount,
2242
        ];
2243
    }
2244
2245
    /**
2246
     * @param $listA
2247
     * @param $listB
2248
     *
2249
     * @return int
2250
     */
2251
    private static function compareByCourse($listA, $listB)
2252
    {
2253
        if ($listA['userCatTitle'] == $listB['userCatTitle']) {
2254
            if ($listA['title'] == $listB['title']) {
2255
                return 0;
2256
            }
2257
2258
            if ($listA['title'] > $listB['title']) {
2259
                return 1;
2260
            }
2261
2262
            return -1;
2263
        }
2264
2265
        if ($listA['userCatTitle'] > $listB['userCatTitle']) {
2266
            return 1;
2267
        }
2268
2269
        return -1;
2270
    }
2271
2272
    /**
2273
     * Generate the HTML code for items when displaying the right-side blocks.
2274
     *
2275
     * @return string
2276
     */
2277
    private static function returnRightBlockItems(array $items)
2278
    {
2279
        $my_account_content = '';
2280
        foreach ($items as $item) {
2281
            if (empty($item['link']) && empty($item['title'])) {
2282
                continue;
2283
            }
2284
2285
            $my_account_content .= '<li class="list-group-item '.(empty($item['class']) ? '' : $item['class']).'">'
2286
                .(empty($item['icon']) ? '' : '<span class="item-icon">'.$item['icon'].'</span>')
2287
                .'<a href="'.$item['link'].'">'.$item['title'].'</a>'
2288
                .'</li>';
2289
        }
2290
2291
        return '<ul class="list-group">'.$my_account_content.'</ul>';
2292
    }
2293
2294
    /**
2295
     * Return HTML code for personal user course category.
2296
     *
2297
     * @param $id
2298
     * @param $title
2299
     *
2300
     * @return string
2301
     */
2302
    private static function getHtmlForUserCategory($id, $title)
2303
    {
2304
        if ($id == 0) {
2305
            return '';
2306
        }
2307
        $icon = Display::return_icon(
2308
            'folder_yellow.png',
2309
            $title,
2310
            ['class' => 'sessionView'],
2311
            ICON_SIZE_LARGE
2312
        );
2313
2314
        return "<div class='session-view-user-category'>$icon<span>$title</span></div>";
2315
    }
2316
2317
    /**
2318
     * return HTML code for course display in session view.
2319
     *
2320
     * @param array $courseInfo
2321
     * @param       $userCategoryId
2322
     * @param bool  $displayButton
2323
     * @param       $loadDirs
2324
     *
2325
     * @return string
2326
     */
2327
    private static function getHtmlForCourse(
2328
        $courseInfo,
2329
        $userCategoryId,
2330
        $displayButton = false,
2331
        $loadDirs
2332
    ) {
2333
        if (empty($courseInfo)) {
2334
            return '';
2335
        }
2336
2337
        $id = $courseInfo['real_id'];
2338
        $title = $courseInfo['title'];
2339
        $code = $courseInfo['code'];
2340
2341
        $class = 'session-view-lvl-6';
2342
        if ($userCategoryId != 0 && !$displayButton) {
2343
            $class = 'session-view-lvl-7';
2344
        }
2345
2346
        $class2 = 'session-view-lvl-6';
2347
        if ($displayButton || $userCategoryId != 0) {
2348
            $class2 = 'session-view-lvl-7';
2349
        }
2350
2351
        $button = '';
2352
        if ($displayButton) {
2353
            $button = '<input id="session-view-button-'.intval(
2354
                    $id
2355
                ).'" class="btn btn-default btn-sm" type="button" onclick="hideUnhide(\'courseblock-'.intval(
2356
                    $id
2357
                ).'\', \'session-view-button-'.intval($id).'\', \'+\', \'-\')" value="+" />';
2358
        }
2359
2360
        $icon = Display::return_icon(
2361
            'blackboard.png',
2362
            $title,
2363
            ['class' => 'sessionView'],
2364
            ICON_SIZE_LARGE
2365
        );
2366
2367
        $courseLink = $courseInfo['course_public_url'].'?id_session=0';
2368
2369
        // get html course params
2370
        $courseParams = CourseManager::getCourseParamsForDisplay($id, $loadDirs);
2371
        $teachers = '';
2372
        $rightActions = '';
2373
2374
        // teacher list
2375
        if (!empty($courseParams['teachers'])) {
2376
            $teachers = '<p class="'.$class2.' view-by-session-teachers">'.$courseParams['teachers'].'</p>';
2377
        }
2378
2379
        // notification
2380
        if (!empty($courseParams['right_actions'])) {
2381
            $rightActions = '<div class="pull-right">'.$courseParams['right_actions'].'</div>';
2382
        }
2383
2384
        $notifications = isset($courseParams['notifications']) ? $courseParams['notifications'] : '';
2385
2386
        return "<div>
2387
                    $button
2388
                    <span class='$class'>$icon
2389
                        <a class='sessionView' href='$courseLink'>$title</a>
2390
                    </span>
2391
                    $notifications
2392
                    $rightActions
2393
                </div>
2394
                $teachers";
2395
    }
2396
2397
    /**
2398
     * return HTML code for session category.
2399
     *
2400
     * @param $id
2401
     * @param $title
2402
     *
2403
     * @return string
2404
     */
2405
    private static function getHtmlSessionCategory($id, $title)
2406
    {
2407
        if ($id == 0) {
2408
            return '';
2409
        }
2410
2411
        $icon = Display::return_icon(
2412
            'folder_blue.png',
2413
            $title,
2414
            ['class' => 'sessionView'],
2415
            ICON_SIZE_LARGE
2416
        );
2417
2418
        return "<div class='session-view-session-category'>
2419
                <span class='session-view-lvl-2'>
2420
                    $icon
2421
                    <span>$title</span>
2422
                </span>
2423
                </div>";
2424
    }
2425
2426
    /**
2427
     * return HTML code for session.
2428
     *
2429
     * @param int    $id                session id
2430
     * @param string $title             session title
2431
     * @param int    $categorySessionId
2432
     * @param array  $courseInfo
2433
     *
2434
     * @return string
2435
     */
2436
    private static function getHtmlForSession($id, $title, $categorySessionId, $courseInfo)
2437
    {
2438
        $html = '';
2439
        if ($categorySessionId == 0) {
2440
            $class1 = 'session-view-lvl-2'; // session
2441
            $class2 = 'session-view-lvl-4'; // got to course in session link
2442
        } else {
2443
            $class1 = 'session-view-lvl-3'; // session
2444
            $class2 = 'session-view-lvl-5'; // got to course in session link
2445
        }
2446
2447
        $icon = Display::return_icon(
2448
            'session.png',
2449
            $title,
2450
            ['class' => 'sessionView'],
2451
            ICON_SIZE_LARGE
2452
        );
2453
        $courseLink = $courseInfo['course_public_url'].'?id_session='.intval($id);
2454
2455
        $html .= "<span class='$class1 session-view-session'>$icon$title</span>";
2456
        $html .= '<div class="'.$class2.' session-view-session-go-to-course-in-session">
2457
                  <a class="" href="'.$courseLink.'">'.get_lang('GoToCourseInsideSession').'</a></div>';
2458
2459
        return '<div>'.$html.'</div>';
2460
    }
2461
2462
    /**
2463
     * Filter the course list by category code.
2464
     *
2465
     * @param array  $courseList   course list
2466
     * @param string $categoryCode
2467
     *
2468
     * @return array
2469
     */
2470
    private static function filterByCategory($courseList, $categoryCode)
2471
    {
2472
        return array_filter(
2473
            $courseList,
2474
            function ($courseInfo) use ($categoryCode) {
2475
                if (isset($courseInfo['category_code']) &&
2476
                    $courseInfo['category_code'] === $categoryCode
2477
                ) {
2478
                    return true;
2479
                }
2480
2481
                return false;
2482
            }
2483
        );
2484
    }
2485
2486
    /**
2487
     * Get the session coach name, duration or dates
2488
     * when $_configuration['show_simple_session_info'] is enabled.
2489
     *
2490
     * @param string      $coachName
2491
     * @param string      $dates
2492
     * @param string|null $duration  Optional
2493
     *
2494
     * @return string
2495
     */
2496
    private static function getSimpleSessionDetails($coachName, $dates, $duration = null)
2497
    {
2498
        $strDetails = [];
2499
        if (!empty($coachName)) {
2500
            $strDetails[] = $coachName;
2501
        }
2502
2503
        $strDetails[] = !empty($duration) ? $duration : $dates;
2504
2505
        return implode(' | ', $strDetails);
2506
    }
2507
}
2508