Passed
Push — master ( f5688d...87bc65 )
by Julito
09:49
created

PageController::show_right_block()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Framework;
5
6
use ChamiloSession as Session;
7
use CourseManager;
8
use Display;
9
use Pagerfanta\Adapter\FixedAdapter;
10
use Pagerfanta\Pagerfanta;
11
use Pagerfanta\View\TwitterBootstrapView;
12
use SystemAnnouncementManager;
13
use UserManager;
14
15
/**
16
 * Class PageController
17
 * Controller for pages presentation in general.
18
 *
19
 * @package chamilo.page.controller
20
 *
21
 * @author Julio Montoya <[email protected]>
22
 *
23
 * @todo move functions in the Template class, remove this class.
24
 */
25
class PageController
26
{
27
    public $maxPerPage = 5;
28
29
    /**
30
     * Returns an online help block read from the home/home_menu_[lang].html
31
     * file.
32
     *
33
     * @return string HTML block
34
     */
35
    public function returnHelp()
36
    {
37
        $home = api_get_home_path();
38
        $user_selected_language = api_get_language_isocode();
39
        $sys_path = api_get_path(SYS_PATH);
40
        $platformLanguage = api_get_setting('language.platform_language');
41
42
        if (!isset($user_selected_language)) {
43
            $user_selected_language = $platformLanguage;
44
        }
45
        $home_menu = @(string) file_get_contents($sys_path.$home.'home_menu_'.$user_selected_language.'.html');
46
        if (!empty($home_menu)) {
47
            $home_menu_content = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
48
            $this->show_right_block(
49
                get_lang('MenuGeneral'),
50
                null,
51
                'help_block',
52
                ['content' => $home_menu_content]
53
            );
54
        }
55
    }
56
57
    /**
58
     * Returns an HTML block with links to the skills tools.
59
     *
60
     * @return string HTML <div> block
61
     */
62
    public function returnSkillsLinks()
63
    {
64
        if (api_get_setting('skill.allow_skills_tool') == 'true') {
65
            $content = [];
66
            $content[] = [
67
                'title' => get_lang('MySkills'),
68
                'href' => api_get_path(WEB_CODE_PATH).'social/skills_wheel.php',
69
            ];
70
71
            if (api_get_setting('skill.allow_hr_skills_management') == 'true'
72
                || api_is_platform_admin()) {
73
                $content[] = [
74
                    'title' => get_lang('ManageSkills'),
75
                    'href' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php',
76
                ];
77
            }
78
            $this->show_right_block(get_lang("Skills"), $content, 'skill_block');
79
        }
80
    }
81
82
    /**
83
     * Returns an HTML block with the notice, as found in the
84
     * home/home_notice_[lang].html file.
85
     *
86
     * @return string HTML <div> block
87
     */
88
    public function returnNotice()
89
    {
90
        $sys_path = api_get_path(SYS_PATH);
91
        $user_selected_language = api_get_language_isocode();
92
        $home = api_get_home_path();
93
94
        // Notice
95
        $home_notice = @(string) file_get_contents($sys_path.$home.'home_notice_'.$user_selected_language.'.html');
96
        if (empty($home_notice)) {
97
            $home_notice = @(string) file_get_contents($sys_path.$home.'home_notice.html');
98
        }
99
100
        if (!empty($home_notice)) {
101
            $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
102
            $home_notice = Display::div($home_notice, ['class' => 'homepage_notice']);
103
104
            $this->show_right_block(get_lang('Notice'), null, 'notice_block', ['content' => $home_notice]);
105
        }
106
    }
107
108
    /**
109
     * Returns the received content packaged in <div> block, with the title as
110
     * <h4>.
111
     *
112
     * @param string Title to include as h4
113
     * @param string Longer content to show (usually a <ul> list)
114
     * @param string ID to be added to the HTML attributes for the block
115
     * @param array Array of attributes to add to the HTML block
116
     *
117
     * @return string HTML <div> block
118
     *
119
     * @todo use the menu builder
120
     */
121
    public function show_right_block($title, $content, $id, $params = null)
122
    {
123
        if (!empty($id)) {
124
            $params['id'] = $id;
125
        }
126
        $block_menu = [
127
            'id' => $params['id'],
128
            'title' => $title,
129
            'elements' => $content,
130
            'content' => isset($params['content']) ? $params['content'] : null,
131
        ];
132
133
        //$app['template']->assign($id, $block_menu);
134
    }
135
136
    /**
137
     * Returns a content search form in an HTML <div>, pointing at the
138
     * main/search/ directory. If search_enabled is not set, then it returns
139
     * an empty string.
140
     *
141
     * @return string HTML <div> block showing the search form, or an empty string if search not enabled
142
     */
143
    public function return_search_block()
144
    {
145
        $html = '';
146
        if (api_get_setting('search.search_enabled') == 'true') {
147
            $html .= '<div class="searchbox">';
148
            $search_btn = get_lang('Search');
149
            $search_content = '<br />
150
                <form action="main/search/" method="post">
151
                <input type="text" id="query" class="span2" name="query" value="" />
152
                <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
153
                </form></div>';
154
            $html .= $this->show_right_block(get_lang('Search'), $search_content, 'search_block');
155
        }
156
157
        return $html;
158
    }
159
160
    /**
161
     * Return the homepage, including announcements.
162
     *
163
     * @return string The portal's homepage as an HTML string
164
     */
165
    public function returnHomePage()
166
    {
167
        // Including the page for the news
168
        $html = null;
169
        $home = api_get_path(SYS_DATA_PATH).api_get_home_path();
0 ignored issues
show
Bug introduced by
The constant Chamilo\CoreBundle\Framework\SYS_DATA_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
170
        $home_top_temp = null;
171
172
        if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
173
            $open = @(string) file_get_contents(api_get_path(SYS_PATH).$home.$_GET['include']);
174
            $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
175
        } else {
176
            $user_selected_language = api_get_user_language();
0 ignored issues
show
Bug introduced by
The function api_get_user_language was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

176
            $user_selected_language = /** @scrutinizer ignore-call */ api_get_user_language();
Loading history...
177
178
            if (!file_exists($home.'home_news_'.$user_selected_language.'.html')) {
179
                if (file_exists($home.'home_top.html')) {
180
                    $home_top_temp = file($home.'home_top.html');
181
                } else {
182
                    //$home_top_temp = file('home/'.'home_top.html');
183
                }
184
                if (!empty($home_top_temp)) {
185
                    $home_top_temp = implode('', $home_top_temp);
186
                }
187
            } else {
188
                if (file_exists($home.'home_top_'.$user_selected_language.'.html')) {
189
                    $home_top_temp = file_get_contents($home.'home_top_'.$user_selected_language.'.html');
190
                } else {
191
                    $home_top_temp = file_get_contents($home.'home_top.html');
192
                }
193
            }
194
195
            if (empty($home_top_temp) && api_is_platform_admin()) {
196
                $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
197
            }
198
            $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
199
            if (!empty($open)) {
200
                $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
201
            }
202
        }
203
204
        return $html;
205
    }
206
207
    /**
208
     * Returns an HTML block with classes (if show_groups_to_users is true).
209
     *
210
     * @return string A list of links to users classes tools, or an empty string if show_groups_to_users is disabled
211
     */
212
    public function return_classes_block()
213
    {
214
        $html = '';
215
        if (api_get_setting('show_groups_to_users') == 'true') {
216
            $usergroup = new Usergroup();
0 ignored issues
show
Bug introduced by
The type Chamilo\CoreBundle\Framework\Usergroup was not found. Did you mean Usergroup? If so, make sure to prefix the type with \.
Loading history...
217
            $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
218
            $classes = '';
219
            if (!empty($usergroup_list)) {
220
                foreach ($usergroup_list as $group_id) {
221
                    $data = $usergroup->get($group_id);
222
                    $data['name'] = Display::url(
223
                        $data['name'],
224
                        api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']
225
                    );
226
                    $classes .= Display::tag('li', $data['name']);
227
                }
228
            }
229
            if (api_is_platform_admin()) {
230
                $classes .= Display::tag(
231
                    'li',
232
                    Display::url(get_lang('AddClasses'), api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add')
233
                );
234
            }
235
            if (!empty($classes)) {
236
                $classes = Display::tag('ul', $classes, ['class' => 'nav nav-list']);
237
                $html .= $this->show_right_block(get_lang('Classes'), $classes, 'classes_block');
238
            }
239
        }
240
241
        return $html;
242
    }
243
244
    /**
245
     * Prepares a block with all the pending exercises in all courses.
246
     *
247
     * @param array Array of courses (arrays) of the user
248
     */
249
    public function return_exercise_block($personal_course_list, $tpl)
250
    {
251
        $exercise_list = [];
252
        if (!empty($personal_course_list)) {
253
            foreach ($personal_course_list as $course_item) {
254
                $course_code = $course_item['c'];
255
                $session_id = $course_item['id_session'];
256
257
                $exercises = ExerciseLib::get_exercises_to_be_taken($course_code, $session_id);
0 ignored issues
show
Bug introduced by
The type Chamilo\CoreBundle\Framework\ExerciseLib was not found. Did you mean ExerciseLib? If so, make sure to prefix the type with \.
Loading history...
258
259
                foreach ($exercises as $exercise_item) {
260
                    $exercise_item['course_code'] = $course_code;
261
                    $exercise_item['session_id'] = $session_id;
262
                    $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC');
263
264
                    $exercise_list[] = $exercise_item;
265
                }
266
            }
267
            if (!empty($exercise_list)) {
268
                $exercise_list = ArrayClass::msort($exercise_list, 'tms');
269
                $my_exercise = $exercise_list[0];
270
                $url = Display::url(
271
                    $my_exercise['title'],
272
                    api_get_path(
273
                        WEB_CODE_PATH
274
                    ).'exercise/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']
275
                );
276
                $tpl->assign('exercise_url', $url);
277
                $tpl->assign(
278
                    'exercise_end_date',
279
                    api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT)
280
                );
281
            }
282
        }
283
    }
284
285
    /**
286
     * Display list of courses in a category.
287
     * (for anonymous users).
288
     *
289
     * @version 1.1
290
     *
291
     * @author Patrick Cool <[email protected]>, Ghent University - refactoring and code cleaning
292
     * @author Julio Montoya <[email protected]>, Beeznest template modifs
293
     */
294
    public function return_courses_in_categories()
295
    {
296
        $result = '';
297
        $stok = Security::get_token();
0 ignored issues
show
Bug introduced by
The type Chamilo\CoreBundle\Framework\Security was not found. Did you mean Security? If so, make sure to prefix the type with \.
Loading history...
298
299
        // Initialization.
300
        $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
301
        $web_course_path = api_get_path(WEB_COURSE_PATH);
302
        $category = Database::escape_string($_GET['category']);
0 ignored issues
show
Bug introduced by
The type Chamilo\CoreBundle\Framework\Database was not found. Did you mean Database? If so, make sure to prefix the type with \.
Loading history...
303
        $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
304
305
        // Database table definitions.
306
        $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
307
        $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
308
309
        // Get list of courses in category $category.
310
        $sql_get_course_list = "SELECT * FROM $main_course_table cours
311
                                    WHERE category_code = '".Database::escape_string($_GET['category'])."'
312
                                    ORDER BY title, UPPER(visual_code)";
313
314
        // Showing only the courses of the current access_url_id.
315
        if (api_is_multiple_url_enabled()) {
316
            $url_access_id = api_get_current_access_url_id();
317
            if ($url_access_id != -1) {
318
                $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
319
                $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
320
                        ON (url_rel_course.c_id = course.id)
321
                        WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string(
322
                    $_GET['category']
323
                )."' ORDER BY title, UPPER(visual_code)";
324
            }
325
        }
326
327
        // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
328
        $sql_result_courses = Database::query($sql_get_course_list);
329
330
        while ($course_result = Database::fetch_array($sql_result_courses)) {
331
            $course_list[] = $course_result;
332
        }
333
334
        $platform_visible_courses = '';
335
        // $setting_show_also_closed_courses
336
        if ($user_identified) {
337
            if ($setting_show_also_closed_courses) {
338
                $platform_visible_courses = '';
339
            } else {
340
                $platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
341
            }
342
        } else {
343
            if ($setting_show_also_closed_courses) {
344
                $platform_visible_courses = '';
345
            } else {
346
                $platform_visible_courses = "  AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
347
            }
348
        }
349
        $sqlGetSubCatList = "
350
                    SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
351
                    FROM $main_category_table t1
352
                    LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
353
                    LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
354
                    WHERE t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
355
                    GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
356
357
        // Showing only the category of courses of the current access_url_id
358
        if (api_is_multiple_url_enabled()) {
359
            $url_access_id = api_get_current_access_url_id();
360
            if ($url_access_id != -1) {
361
                $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
362
                $sqlGetSubCatList = "
363
                    SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
364
                    FROM $main_category_table t1
365
                    LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
366
                    LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
367
                    INNER JOIN $tbl_url_rel_course as url_rel_course
368
                        ON (url_rel_course.c_id = t3.id)
369
                    WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
370
                    GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
371
            }
372
        }
373
374
        $resCats = Database::query($sqlGetSubCatList);
375
        $thereIsSubCat = false;
376
        if (Database::num_rows($resCats) > 0) {
377
            $htmlListCat = Display::page_header(get_lang('CatList'));
378
            $htmlListCat .= '<ul>';
379
            while ($catLine = Database::fetch_array($resCats)) {
380
                if ($catLine['code'] != $category) {
381
                    $category_has_open_courses = $this->category_has_open_courses($catLine['code']);
0 ignored issues
show
Bug introduced by
The method category_has_open_courses() does not exist on Chamilo\CoreBundle\Framework\PageController. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

381
                    /** @scrutinizer ignore-call */ 
382
                    $category_has_open_courses = $this->category_has_open_courses($catLine['code']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
382
                    if ($category_has_open_courses) {
383
                        // The category contains courses accessible to anonymous visitors.
384
                        $htmlListCat .= '<li>';
385
                        $htmlListCat .= '<a href="'.api_get_self(
386
                        ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
387
                        if (api_get_setting('show_number_of_courses') == 'true') {
388
                            $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
389
                        }
390
                        $htmlListCat .= "</li>";
391
                        $thereIsSubCat = true;
392
                    } elseif ($catLine['children_count'] > 0) {
393
                        // The category has children, subcategories.
394
                        $htmlListCat .= '<li>';
395
                        $htmlListCat .= '<a href="'.api_get_self(
396
                        ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
397
                        $htmlListCat .= "</li>";
398
                        $thereIsSubCat = true;
399
                    } elseif (api_get_setting('show_empty_course_categories') == 'true') {
400
                        /* End changed code to eliminate the (0 courses) after empty categories. */
401
                        $htmlListCat .= '<li>';
402
                        $htmlListCat .= $catLine['name'];
403
                        $htmlListCat .= "</li>";
404
                        $thereIsSubCat = true;
405
                    } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
406
                } else {
407
                    $htmlTitre = '<p>';
408
                    if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
409
                        $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
410
                    }
411
                    if (!is_null($catLine['parent_id']) ||
412
                        (api_get_setting('show_back_link_on_top_of_tree') != 'true' &&
413
                        !is_null($catLine['code']))
414
                    ) {
415
                        $htmlTitre .= '<a href="'.api_get_self(
416
                        ).'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
417
                    }
418
                    $htmlTitre .= "</p>";
419
                    if ($category != "" && !is_null($catLine['code'])) {
420
                        $htmlTitre .= '<h3>'.$catLine['name']."</h3>";
421
                    } else {
422
                        $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>";
423
                    }
424
                }
425
            }
426
            $htmlListCat .= "</ul>";
427
        }
428
        $result .= $htmlTitre;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $htmlTitre does not seem to be defined for all execution paths leading up to this point.
Loading history...
429
        if ($thereIsSubCat) {
430
            $result .= $htmlListCat;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $htmlListCat does not seem to be defined for all execution paths leading up to this point.
Loading history...
431
        }
432
        while ($categoryName = Database::fetch_array($resCats)) {
433
            $result .= '<h3>'.$categoryName['name']."</h3>\n";
434
        }
435
        $numrows = Database::num_rows($sql_result_courses);
436
        $courses_list_string = '';
437
        $courses_shown = 0;
438
        if ($numrows > 0) {
439
            $courses_list_string .= Display::page_header(get_lang('CourseList'));
440
            $courses_list_string .= "<ul>";
441
442
            if (api_get_user_id()) {
443
                $courses_of_user = $this->get_courses_of_user(api_get_user_id());
0 ignored issues
show
Bug introduced by
The method get_courses_of_user() does not exist on Chamilo\CoreBundle\Framework\PageController. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

443
                /** @scrutinizer ignore-call */ 
444
                $courses_of_user = $this->get_courses_of_user(api_get_user_id());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
444
            }
445
446
            foreach ($course_list as $course) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $course_list does not seem to be defined for all execution paths leading up to this point.
Loading history...
447
                // $setting_show_also_closed_courses
448
                if (!$setting_show_also_closed_courses) {
449
                    // If we do not show the closed courses
450
                    // we only show the courses that are open to the world (to everybody)
451
                    // and the courses that are open to the platform (if the current user is a registered user.
452
                    if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
453
                        $courses_shown++;
454
                        $courses_list_string .= "<li>\n";
455
                        $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
456
                        $course_details = [];
457
                        if (api_get_setting('course.display_coursecode_in_courselist') ==
458
                            'true') {
459
                            $course_details[] = $course['visual_code'];
460
                        }
461
                        if (api_get_setting('course.display_teacher_in_courselist') ==
462
                            'true') {
463
                            $course_details[] = $course['tutor_name'];
464
                        }
465
                        if (api_get_setting('display.show_different_course_language') ==
466
                            'true' && $course['course_language'] != api_get_setting(
467
                                'language.platform_language'
468
                            )
469
                        ) {
470
                            $course_details[] = $course['course_language'];
471
                        }
472
                        $courses_list_string .= implode(' - ', $course_details);
473
                        $courses_list_string .= "</li>\n";
474
                    }
475
                } else {
476
                    // We DO show the closed courses.
477
                    // The course is accessible if (link to the course homepage):
478
                    // 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);
479
                    // 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);
480
                    // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
481
                    // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
482
                    // 5. the user is the platform admin api_is_platform_admin().
483
                    //
484
                    $courses_shown++;
485
                    $courses_list_string .= "<li>\n";
486
                    if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
487
                        || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
488
                        || ($user_identified && key_exists(
489
                            $course['code'],
490
                            $courses_of_user
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $courses_of_user does not seem to be defined for all execution paths leading up to this point.
Loading history...
491
                        ) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
492
                        || $courses_of_user[$course['code']]['status'] == '1'
493
                        || api_is_platform_admin()
494
                    ) {
495
                        $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
496
                    }
497
                    $courses_list_string .= $course['title'];
498
                    if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
499
                        || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
500
                        || ($user_identified && key_exists(
501
                            $course['code'],
502
                            $courses_of_user
503
                        ) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
504
                        || $courses_of_user[$course['code']]['status'] == '1'
505
                        || api_is_platform_admin()
506
                    ) {
507
                        $courses_list_string .= '</a><br />';
508
                    }
509
                    $course_details = [];
510
                    if (api_get_setting('course.display_coursecode_in_courselist') == 'true') {
511
                        $course_details[] = $course['visual_code'];
512
                    }
513
                    if (api_get_setting('course.display_teacher_in_courselist') == 'true') {
514
                        $course_details[] = $course['tutor_name'];
515
                    }
516
                    if (api_get_setting(
517
                            'display.show_different_course_language'
518
                        ) == 'true' && $course['course_language'] != api_get_setting(
519
                            'language.platform_language'
520
                        )
521
                    ) {
522
                        $course_details[] = $course['course_language'];
523
                    }
524
                    if (api_get_setting(
525
                        'show_different_course_language'
526
                        ) == 'true' && $course['course_language'] != api_get_setting(
527
                            'language.platform_language'
528
                        )
529
                    ) {
530
                        $course_details[] = $course['course_language'];
531
                    }
532
533
                    $courses_list_string .= implode(' - ', $course_details);
534
                    // We display a subscription link if:
535
                    // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
536
                    // 2.
537
                    if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
538
                        if ($course['subscribe'] == '1') {
539
                            $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS(
540
                                $_GET['category']
541
                            ).'" method="post">';
542
                            $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
543
                            $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
544
                            $courses_list_string .= '<input type="image" name="unsub" src="'.api_get_path(WEB_IMG_PATH).'enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'
545
                            </form>';
546
                        } else {
547
                            $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
548
                        }
549
                    }
550
                    $courses_list_string .= "</li>";
551
                } //end else
552
            } // end foreach
553
            $courses_list_string .= "</ul>";
554
        }
555
        if ($courses_shown > 0) {
556
            // Only display the list of courses and categories if there was more than
557
            // 0 courses visible to the world (we're in the anonymous list here).
558
            $result .= $courses_list_string;
559
        }
560
        if ($category != '') {
561
            $result .= '<p><a href="'.api_get_self().'"> '.Display :: return_icon('back.png', get_lang('BackToHomePage')).get_lang('BackToHomePage').'</a></p>';
562
        }
563
564
        return $result;
565
    }
566
567
    /**
568
     * @param int    $user_id
569
     * @param string $filter
570
     * @param int    $page
571
     *
572
     * @return bool
573
     */
574
    public function returnMyCourseCategories($user_id, $filter, $page)
575
    {
576
        if (empty($user_id)) {
577
            return false;
578
        }
579
        $loadDirs = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
580
        $start = ($page - 1) * $this->maxPerPage;
581
582
        $nbResults = (int) CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, true);
0 ignored issues
show
Bug introduced by
The method displayPersonalCourseCategories() does not exist on CourseManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

582
        $nbResults = (int) CourseManager::/** @scrutinizer ignore-call */ displayPersonalCourseCategories($user_id, $filter, $loadDirs, true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
583
584
        $html = CourseManager::displayPersonalCourseCategories(
585
            $user_id,
586
            $filter,
587
            $loadDirs,
588
            false,
589
            $start,
590
            $this->maxPerPage
591
        );
592
593
        $adapter = new FixedAdapter($nbResults, []);
594
        $pagerfanta = new Pagerfanta($adapter);
595
        $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
596
        $pagerfanta->setCurrentPage($page); // 1 by default
597
598
        $this->app['pagerfanta.view.router.name'] = 'userportal';
0 ignored issues
show
Bug Best Practice introduced by
The property app does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
599
        $this->app['pagerfanta.view.router.params'] = [
600
            'filter' => $filter,
601
            'type' => 'courses',
602
            'page' => $page,
603
        ];
604
        $this->app['template']->assign('pagination', $pagerfanta);
605
606
        return $html;
607
    }
608
609
    public function returnSpecialCourses($user_id, $filter, $page)
610
    {
611
        if (empty($user_id)) {
612
            return false;
613
        }
614
615
        $loadDirs = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
616
        $start = ($page - 1) * $this->maxPerPage;
617
618
        $nbResults = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, true);
0 ignored issues
show
Bug introduced by
The method displaySpecialCourses() does not exist on CourseManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

618
        /** @scrutinizer ignore-call */ 
619
        $nbResults = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
619
620
        $html = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
621
        if (!empty($html)) {
622
            $adapter = new FixedAdapter($nbResults, []);
623
            $pagerfanta = new Pagerfanta($adapter);
624
            $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
625
            $pagerfanta->setCurrentPage($page); // 1 by default
626
            $this->app['pagerfanta.view.router.name'] = 'userportal';
0 ignored issues
show
Bug Best Practice introduced by
The property app does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
627
            $this->app['pagerfanta.view.router.params'] = [
628
                'filter' => $filter,
629
                'type' => 'courses',
630
                'page' => $page,
631
            ];
632
            $this->app['template']->assign('pagination', $pagerfanta);
633
        }
634
635
        return $html;
636
    }
637
638
    /**
639
     * The most important function here, prints the session and course list (user_portal.php).
640
     *
641
     * @param int    $user_id
642
     * @param string $filter
643
     * @param int    $page
644
     *
645
     * @return string HTML list of sessions and courses
646
     */
647
    public function returnCourses($user_id, $filter, $page)
0 ignored issues
show
Unused Code introduced by
The parameter $filter is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

647
    public function returnCourses($user_id, /** @scrutinizer ignore-unused */ $filter, $page)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
648
    {
649
        if (empty($user_id)) {
650
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
651
        }
652
653
        $loadDirs = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
654
        $start = ($page - 1) * $this->maxPerPage;
655
656
        return;
657
        $nbResults = CourseManager::displayCourses(
0 ignored issues
show
Unused Code introduced by
$nbResults = CourseManag...ilter, $loadDirs, true) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
658
            $user_id,
659
            $filter,
660
            $loadDirs,
661
            true
662
        );
663
664
        $html = CourseManager::displayCourses(
665
            $user_id,
666
            $filter,
667
            $loadDirs,
668
            false,
669
            $start,
670
            $this->maxPerPage
671
        );
672
673
        if (!empty($html)) {
674
            $adapter = new FixedAdapter($nbResults, []);
675
            $pagerfanta = new Pagerfanta($adapter);
676
            $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
677
            $pagerfanta->setCurrentPage($page); // 1 by default
678
679
            /*
680
            Original pagination construction
681
            $view = new TwitterBootstrapView();
682
            $routeGenerator = function($page) use ($app, $filter) {
683
                return $app['url_generator']->generate('userportal', array(
684
                    'filter' => $filter,
685
                    'type' => 'courses',
686
                    'page' => $page)
687
                );
688
            };
689
            $pagination = $view->render($pagerfanta, $routeGenerator, array(
690
                'proximity' => 3,
691
            ));
692
            */
693
            //Pagination using the pagerfanta silex service provider
694
            /*$this->app['pagerfanta.view.router.name']   = 'userportal';
695
            $this->app['pagerfanta.view.router.params'] = array(
696
                'filter' => $filter,
697
                'type'   => 'courses',
698
                'page'   => $page
699
            );
700
            $this->app['template']->assign('pagination', $pagerfanta);*/
701
            // {{ pagerfanta(my_pager, 'twitter_bootstrap3') }}
702
        }
703
704
        return $html;
705
    }
706
707
    public function returnSessionsCategories($user_id, $filter, $page)
708
    {
709
        if (empty($user_id)) {
710
            return false;
711
        }
712
713
        $load_history = (isset($filter) && $filter == 'history') ? true : false;
714
715
        $start = ($page - 1) * $this->maxPerPage;
716
717
        $nbResults = UserManager::getCategories($user_id, false, true, true);
0 ignored issues
show
Bug introduced by
The method getCategories() does not exist on UserManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

717
        /** @scrutinizer ignore-call */ 
718
        $nbResults = UserManager::getCategories($user_id, false, true, true);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
718
        $session_categories = UserManager::getCategories(
719
            $user_id,
720
            false,
721
            false,
722
            true,
723
            $start,
724
            $this->maxPerPage
725
        );
726
727
        $html = null;
728
        //Showing history title
729
        if ($load_history) {
730
            $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
731
            if (empty($session_categories)) {
732
                $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
733
            }
734
        }
735
736
        $load_directories_preview = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
737
        $sessions_with_category = $html;
738
739
        if (isset($session_categories) && !empty($session_categories)) {
740
            foreach ($session_categories as $session_category) {
741
                $session_category_id = $session_category['session_category']['id'];
742
743
                // All sessions included in
744
                $count_courses_session = 0;
745
                $html_sessions = '';
746
                foreach ($session_category['sessions'] as $session) {
747
                    $session_id = $session['session_id'];
748
749
                    // Don't show empty sessions.
750
                    if (count($session['courses']) < 1) {
751
                        continue;
752
                    }
753
754
                    $html_courses_session = '';
755
                    $count = 0;
756
                    foreach ($session['courses'] as $course) {
757
                        if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
758
                            $html_courses_session .= CourseManager::get_logged_user_course_html($course, $session_id);
759
                        }
760
                        $count_courses_session++;
761
                        $count++;
762
                    }
763
764
                    $params = [];
765
                    if ($count > 0) {
766
                        $params['icon'] = Display::return_icon(
767
                            'window_list.png',
768
                            $session['session_name'],
769
                            ['id' => 'session_img_'.$session_id],
770
                            ICON_SIZE_LARGE
771
                        );
772
773
                        //Default session name
774
                        $session_link = $session['session_name'];
775
                        $params['link'] = null;
776
777
                        if (api_get_setting('session.session_page_enabled') == 'true' && !api_is_drh()) {
778
                            //session name with link
779
                            $session_link = Display::tag(
780
                                'a',
781
                                $session['session_name'],
782
                                ['href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id]
783
                            );
784
                            $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
785
                        }
786
787
                        $params['title'] = $session_link;
788
789
                        $moved_status = \SessionManager::getSessionChangeUserReason(
790
                            isset($session['moved_status']) ? $session['moved_status'] : ''
0 ignored issues
show
Bug introduced by
It seems like IssetNode ? $session['moved_status'] : '' can also be of type string; however, parameter $id of SessionManager::getSessionChangeUserReason() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

790
                            /** @scrutinizer ignore-type */ isset($session['moved_status']) ? $session['moved_status'] : ''
Loading history...
791
                        );
792
                        $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
793
794
                        $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
795
                        $params['dates'] = \SessionManager::parseSessionDates(
796
                            $session
797
                        );
798
799
                        if (api_is_platform_admin()) {
800
                            $params['right_actions'] = '<a href="'.api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session_id.'">'.Display::return_icon(
801
                                'edit.png',
802
                                get_lang('Edit'),
803
                                ['align' => 'absmiddle'],
804
                                ICON_SIZE_SMALL
805
                            ).'</a>';
806
                        }
807
                        $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
0 ignored issues
show
Bug introduced by
The method course_item_html() does not exist on CourseManager. Did you maybe mean course_item_html_no_icon()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

807
                        $html_sessions .= CourseManager::/** @scrutinizer ignore-call */ course_item_html($params, true).$html_courses_session;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
808
                    }
809
                }
810
811
                if ($count_courses_session > 0) {
812
                    $params = [];
813
                    $params['icon'] = Display::return_icon(
814
                        'folder_blue.png',
815
                        $session_category['session_category']['name'],
816
                        [],
817
                        ICON_SIZE_LARGE
818
                    );
819
820
                    if (api_is_platform_admin()) {
821
                        $params['right_actions'] = '<a href="'.api_get_path(
822
                            WEB_CODE_PATH
823
                        ).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon(
824
                            'edit.png',
825
                            get_lang('Edit'),
826
                            [],
827
                            ICON_SIZE_SMALL
828
                        ).'</a>';
829
                    }
830
831
                    $params['title'] = $session_category['session_category']['name'];
832
833
                    if (api_is_platform_admin()) {
834
                        $params['link'] = api_get_path(
835
                            WEB_CODE_PATH
836
                        ).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
837
                    }
838
839
                    $session_category_start_date = $session_category['session_category']['date_start'];
840
                    $session_category_end_date = $session_category['session_category']['date_end'];
841
842
                    if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
843
                        $params['subtitle'] = sprintf(
844
                            get_lang('FromDateXToDateY'),
845
                            $session_category['session_category']['date_start'],
846
                            $session_category['session_category']['date_end']
847
                        );
848
                    } else {
849
                        if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
850
                            $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
851
                        }
852
                        if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
853
                            $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
854
                        }
855
                    }
856
                    $sessions_with_category .= CourseManager::course_item_parent(
0 ignored issues
show
Bug introduced by
The method course_item_parent() does not exist on CourseManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

856
                    $sessions_with_category .= CourseManager::/** @scrutinizer ignore-call */ course_item_parent(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
857
                        CourseManager::course_item_html($params, true),
858
                        $html_sessions
859
                    );
860
                }
861
            }
862
863
            //Pagination
864
            $adapter = new FixedAdapter($nbResults, []);
865
            $pagerfanta = new Pagerfanta($adapter);
866
            $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
867
            $pagerfanta->setCurrentPage($page); // 1 by default
868
869
            $this->app['pagerfanta.view.router.name'] = 'userportal';
0 ignored issues
show
Bug Best Practice introduced by
The property app does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
870
            $this->app['pagerfanta.view.router.params'] = [
871
                'filter' => $filter,
872
                'type' => 'sessioncategories',
873
                'page' => $page,
874
            ];
875
            $this->app['template']->assign('pagination', $pagerfanta);
876
        }
877
878
        return $sessions_with_category;
879
    }
880
881
    /**
882
     * @param int    $user_id
883
     * @param string $filter  current|history
884
     * @param int    $page
885
     *
886
     * @return bool|null|string
887
     */
888
    public function returnSessions($user_id, $filter, $page)
889
    {
890
        if (empty($user_id)) {
891
            return false;
892
        }
893
894
        $loadHistory = (isset($filter) && $filter == 'history') ? true : false;
895
896
        /*$app['session_menu'] = function ($app) use ($loadHistory) {
897
            $menu = $app['knp_menu.factory']->createItem(
898
                'root',
899
                array(
900
                    'childrenAttributes' => array(
901
                        'class'        => 'nav nav-tabs',
902
                        'currentClass' => 'active'
903
                    )
904
                )
905
            );
906
907
            $current = $menu->addChild(
908
                get_lang('Current'),
909
                array(
910
                    'route'           => 'userportal',
911
                    'routeParameters' => array(
912
                        'filter' => 'current',
913
                        'type'   => 'sessions'
914
                    )
915
                )
916
            );
917
            $history = $menu->addChild(
918
                get_lang('HistoryTrainingSession'),
919
                array(
920
                    'route'           => 'userportal',
921
                    'routeParameters' => array(
922
                        'filter' => 'history',
923
                        'type'   => 'sessions'
924
                    )
925
                )
926
            );
927
            //@todo use URIVoter
928
            if ($loadHistory) {
929
                $history->setCurrent(true);
930
            } else {
931
                $current->setCurrent(true);
932
            }
933
934
            return $menu;
935
        };*/
936
937
        //@todo move this in template
938
        //$app['knp_menu.menus'] = array('actions_menu' => 'session_menu');
939
940
        $start = ($page - 1) * $this->maxPerPage;
941
942
        if ($loadHistory) {
943
            // Load sessions in category in *history*.
944
            $nbResults = (int) UserManager::get_sessions_by_category(
945
                $user_id,
946
                true,
947
                true,
948
                true,
949
                null,
950
                null,
951
                'no_category'
952
            );
953
954
            $session_categories = UserManager::get_sessions_by_category(
955
                $user_id,
956
                true,
957
                false,
958
                true,
959
                $start,
960
                $this->maxPerPage,
961
                'no_category'
962
            );
963
        } else {
964
            // Load sessions in category.
965
            $nbResults = (int) UserManager::get_sessions_by_category(
966
                $user_id,
967
                false,
968
                true,
969
                false,
970
                null,
971
                null,
972
                'no_category'
973
            );
974
975
            $session_categories = UserManager::get_sessions_by_category(
976
                $user_id,
977
                false,
978
                false,
979
                false,
980
                $start,
981
                $this->maxPerPage,
982
                'no_category'
983
            );
984
        }
985
986
        $html = null;
987
988
        // Showing history title
989
        if ($loadHistory) {
990
            // $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
991
            if (empty($session_categories)) {
992
                $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
993
            }
994
        }
995
996
        $load_directories_preview = api_get_setting('document.show_documents_preview') === 'true' ? true : false;
997
        $sessions_with_no_category = $html;
998
999
        if (isset($session_categories) && !empty($session_categories)) {
1000
            foreach ($session_categories as $session_category) {
1001
                $session_category_id = $session_category['session_category']['id'];
1002
1003
                // Sessions does not belong to a session category
1004
                if ($session_category_id == 0) {
1005
                    // Independent sessions
1006
                    if (isset($session_category['sessions'])) {
1007
                        foreach ($session_category['sessions'] as $session) {
1008
                            $session_id = $session['session_id'];
1009
1010
                            // Don't show empty sessions.
1011
                            if (count($session['courses']) < 1) {
1012
                                continue;
1013
                            }
1014
1015
                            // Courses inside the current session.
1016
                            $date_session_start = $session['access_start_date'];
1017
                            $date_session_end = $session['access_end_date'];
1018
                            $coachAccessStartDate = $session['coach_access_start_date'];
1019
                            $coachAccessEndDate = $session['coach_access_end_date'];
1020
1021
                            $session_now = time();
1022
                            $count_courses_session = 0;
1023
                            $count_courses_session = 0;
1024
1025
                            // Loop course content
1026
                            $html_courses_session = [];
1027
                            $atLeastOneCourseIsVisible = false;
1028
1029
                            foreach ($session['courses'] as $course) {
1030
                                $is_coach_course = api_is_coach($session_id, $course['real_id']);
1031
                                $allowed_time = 0;
1032
1033
                                // Read only and accessible
1034
                                if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
1035
                                    $courseUserHtml = CourseManager::get_logged_user_course_html(
1036
                                        $course,
1037
                                        $session_id,
1038
                                        $load_directories_preview
1039
                                    );
1040
1041
                                    if (isset($courseUserHtml[1])) {
1042
                                        $course_session = $courseUserHtml[1];
1043
                                        $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
1044
                                        $html_courses_session[] = $course_session;
1045
                                    }
1046
                                }
1047
                                $count_courses_session++;
1048
                            }
1049
1050
                            if ($count_courses_session > 0) {
1051
                                $params = [];
1052
1053
                                $params['icon'] = Display::return_icon(
1054
                                    'window_list.png',
1055
                                    $session['session_name'],
1056
                                    ['id' => 'session_img_'.$session_id],
1057
                                    ICON_SIZE_LARGE
1058
                                );
1059
                                $params['is_session'] = true;
1060
                                //Default session name
1061
                                $session_link = $session['session_name'];
1062
                                $params['link'] = null;
1063
1064
                                if (api_get_setting('session.session_page_enabled') == 'true' && !api_is_drh()) {
1065
                                    //session name with link
1066
                                    $session_link = Display::tag(
1067
                                        'a',
1068
                                        $session['session_name'],
1069
                                        [
1070
                                            'href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id,
1071
                                        ]
1072
                                    );
1073
                                    $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
1074
                                }
1075
1076
                                $params['title'] = $session_link;
1077
1078
                                $moved_status = \SessionManager::getSessionChangeUserReason(
1079
                                    $session['moved_status'] ?? ''
0 ignored issues
show
Bug introduced by
It seems like $session['moved_status'] ?? '' can also be of type string; however, parameter $id of SessionManager::getSessionChangeUserReason() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1079
                                    /** @scrutinizer ignore-type */ $session['moved_status'] ?? ''
Loading history...
1080
                                );
1081
                                $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
1082
1083
                                $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
1084
                                //$params['dates'] = $session['date_message'];
1085
1086
                                $params['dates'] = \SessionManager::parseSessionDates($session);
1087
                                $params['right_actions'] = '';
1088
                                if (api_is_platform_admin()) {
1089
                                    $params['right_actions'] .=
1090
                                        Display::url(
1091
                                            Display::return_icon(
1092
                                                'edit.png',
1093
                                                get_lang('Edit'),
1094
                                                ['align' => 'absmiddle'],
1095
                                                ICON_SIZE_SMALL
1096
                                            ),
1097
                                            api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session_id
1098
                                        );
1099
                                }
1100
1101
                                if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
1102
                                    //    $params['extra'] .=  $html_courses_session;
1103
                                }
1104
                                $courseDataToString = CourseManager::parseCourseListData($html_courses_session);
0 ignored issues
show
Bug introduced by
The method parseCourseListData() does not exist on CourseManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1104
                                /** @scrutinizer ignore-call */ 
1105
                                $courseDataToString = CourseManager::parseCourseListData($html_courses_session);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1105
                                $sessions_with_no_category .= CourseManager::course_item_parent(
1106
                                    CourseManager::course_item_html($params, true),
1107
                                    $courseDataToString
1108
                                );
1109
                            }
1110
                        }
1111
                    }
1112
                }
1113
            }
1114
1115
            /*$adapter = new FixedAdapter($nbResults, array());
1116
            $pagerfanta = new Pagerfanta($adapter);
1117
            $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
1118
            $pagerfanta->setCurrentPage($page); // 1 by default
1119
1120
            $this->app['pagerfanta.view.router.name']   = 'userportal';
1121
            $this->app['pagerfanta.view.router.params'] = array(
1122
                'filter' => $filter,
1123
                'type'   => 'sessions',
1124
                'page'   => $page
1125
            );
1126
            $this->app['template']->assign('pagination', $pagerfanta);*/
1127
        }
1128
1129
        return $sessions_with_no_category;
1130
    }
1131
1132
    /**
1133
     * Shows a welcome message when the user doesn't have any content in
1134
     * the course list.
1135
     *
1136
     * @param object A Template object used to declare variables usable in the given template
1137
     */
1138
    public function return_welcome_to_course_block($tpl)
1139
    {
1140
        if (empty($tpl)) {
1141
            return false;
1142
        }
1143
        $count_courses = CourseManager::count_courses();
1144
1145
        $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
1146
        $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
1147
1148
        $tpl->assign('course_catalog_url', $course_catalog_url);
1149
        $tpl->assign('course_list_url', $course_list_url);
1150
        $tpl->assign('course_catalog_link', Display::url(get_lang('here'), $course_catalog_url));
1151
        $tpl->assign('course_list_link', Display::url(get_lang('here'), $course_list_url));
1152
        $tpl->assign('count_courses', $count_courses);
1153
        $tpl->assign('welcome_to_course_block', 1);
1154
    }
1155
1156
    /**
1157
     * @param array
1158
     */
1159
    public function returnNavigationLinks($items)
1160
    {
1161
        // Main navigation section.
1162
        // Tabs that are deactivated are added here.
1163
        if (!empty($items)) {
1164
            $content = '<ul class="nav nav-list">';
1165
            foreach ($items as $section => $navigation_info) {
1166
                $current = isset($GLOBALS['this_section']) && $section == $GLOBALS['this_section'] ? ' id="current"' : '';
1167
                $content .= '<li '.$current.'>';
1168
                $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
1169
                $content .= '</li>';
1170
            }
1171
            $content .= '</ul>';
1172
            $this->show_right_block(get_lang('MainNavigation'), null, 'navigation_block', ['content' => $content]);
1173
        }
1174
    }
1175
}
1176