Passed
Push — master ( a84711...82b6df )
by Julito
09:21
created

get_tabs()   F

Complexity

Conditions 21
Paths 960

Size

Total Lines 123
Code Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 21
eloc 80
nc 960
nop 1
dl 0
loc 123
rs 0.0555
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B accessToWhoIsOnline() 0 13 8
C returnNotificationMenu() 0 50 15
A return_logo() 0 10 1

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
/* For licensing terms, see /license.txt */
3
4
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
5
use ChamiloSession as Session;
6
7
/**
8
 * Code.
9
 *
10
 * @todo use globals or parameters or add this file in the template
11
 *
12
 * @package chamilo.include
13
 */
14
15
/**
16
 * This function returns the custom tabs.
17
 *
18
 * @return array
19
 */
20
function getCustomTabs()
21
{
22
    $urlId = api_get_current_access_url_id();
23
    $tableSettingsCurrent = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
24
    $sql = "SELECT * FROM $tableSettingsCurrent
25
            WHERE 
26
                variable = 'show_tabs' AND
27
                subkey LIKE 'custom_tab_%' AND access_url = $urlId ";
28
    $result = Database::query($sql);
29
    $customTabs = [];
30
    while ($row = Database::fetch_assoc($result)) {
31
        $shouldAdd = true;
32
        if (strpos($row['subkey'], Plugin::TAB_FILTER_NO_STUDENT) !== false && api_is_student()) {
33
            $shouldAdd = false;
34
        } elseif (strpos($row['subkey'], Plugin::TAB_FILTER_ONLY_STUDENT) !== false && !api_is_student()) {
35
            $shouldAdd = false;
36
        }
37
38
        if ($shouldAdd) {
39
            $customTabs[] = $row;
40
        }
41
    }
42
43
    return $customTabs;
44
}
45
46
/**
47
 * Return the active logo of the portal, based on a series of settings.
48
 *
49
 * @param string $theme The name of the theme folder from web/css/themes/
50
 *
51
 * @return string HTML string with logo as an HTML element
52
 */
53
function return_logo($theme = '')
54
{
55
    $siteName = api_get_setting('siteName');
56
57
    return ChamiloApi::getPlatformLogo(
58
        $theme,
59
        [
60
            'title' => $siteName,
61
            'class' => 'img-responsive',
62
            'id' => 'header-logo',
63
        ]
64
    );
65
}
66
67
/**
68
 * Check if user have access to "who is online" page.
69
 *
70
 * @return bool
71
 */
72
function accessToWhoIsOnline()
73
{
74
    $user_id = api_get_user_id();
75
    $course_id = api_get_course_int_id();
76
    $access = false;
77
    if ((api_get_setting('showonline', 'world') === 'true' && !$user_id) ||
78
        (api_get_setting('showonline', 'users') === 'true' && $user_id) ||
79
        (api_get_setting('showonline', 'course') === 'true' && $user_id && $course_id)
80
    ) {
81
        $access = true;
82
    }
83
84
    return $access;
85
}
86
87
/**
88
 * Return HTML string of a list as <li> items.
89
 *
90
 * @return string
91
 */
92
function returnNotificationMenu()
93
{
94
    $courseInfo = api_get_course_info();
95
    $user_id = api_get_user_id();
96
    $sessionId = api_get_session_id();
97
    $html = '';
98
99
    if (accessToWhoIsOnline()) {
100
        $number = getOnlineUsersCount();
101
        $number_online_in_course = getOnlineUsersInCourseCount($user_id, $courseInfo);
102
103
        // Display the who's online of the platform
104
        if ($number &&
0 ignored issues
show
introduced by
Consider adding parentheses for clarity. Current Interpretation: ($number && api_get_sett...) == 'true' && $user_id, Probably Intended Meaning: $number && (api_get_sett... == 'true' && $user_id)
Loading history...
105
            (api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
106
            (api_get_setting('showonline', 'users') == 'true' && $user_id)
107
        ) {
108
            $html .= '<li class="user-online"><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_self" title="'
109
                .get_lang('UsersOnline').'" >'
110
                .Display::return_icon('user.png', get_lang('UsersOnline'), [], ICON_SIZE_TINY)
111
                .' '.$number.'</a></li>';
112
        }
113
114
        // Display the who's online for the course
115
        if ($number_online_in_course &&
116
            (
117
                is_array($courseInfo) &&
118
                api_get_setting('showonline', 'course') == 'true' && isset($courseInfo['sysCode'])
119
            )
120
        ) {
121
            $html .= '<li class="user-online-course"><a href="'.api_get_path(WEB_PATH).'whoisonline.php?cidReq='.$courseInfo['sysCode']
122
                .'" target="_self">'
123
                .Display::return_icon('course.png', get_lang('UsersOnline').' '.get_lang('InThisCourse'), [], ICON_SIZE_TINY)
124
                .' '.$number_online_in_course.' </a></li>';
125
        }
126
127
        if (!empty($sessionId)) {
128
            $allow = api_is_platform_admin(true) ||
129
                api_is_coach($sessionId, null, false) ||
130
                SessionManager::isUserSubscribedAsStudent($sessionId, api_get_user_id());
131
            if ($allow) {
132
                $numberOnlineInSession = getOnlineUsersInSessionCount($sessionId);
133
                $html .= '<li class="user-online-session">
134
                            <a href="'.api_get_path(WEB_PATH).'whoisonlinesession.php" target="_self">'
135
                            .Display::return_icon('session.png', get_lang('UsersConnectedToMySessions'), [], ICON_SIZE_TINY)
136
                            .' '.$numberOnlineInSession.'</a></li>';
137
            }
138
        }
139
    }
140
141
    return $html;
142
}
143
144
/**
145
 * Return an array with different navigation mennu elements.
146
 *
147
 * @return array [menu_navigation[], navigation[], possible_tabs[]]
148
 */
149
function return_navigation_array()
150
{
151
    $navigation = [];
152
    $menu_navigation = [];
153
    $possible_tabs = get_tabs();
0 ignored issues
show
Bug introduced by
The function get_tabs 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

153
    $possible_tabs = /** @scrutinizer ignore-call */ get_tabs();
Loading history...
154
155
    $tabs = api_get_setting('show_tabs');
156
157
    // Campus Homepage
158
    if (in_array('campus_homepage', $tabs)) {
159
        $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
160
    } else {
161
        $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
162
    }
163
164
    if (api_get_setting('course_catalog_published') == 'true' && api_is_anonymous()) {
165
        $navigation[SECTION_CATALOG] = $possible_tabs[SECTION_CATALOG];
166
    }
167
168
    if (api_get_user_id() && !api_is_anonymous()) {
169
        // My Courses
170
        if (in_array('my_courses', $tabs)) {
171
            $navigation['mycourses'] = $possible_tabs['mycourses'];
172
        } else {
173
            $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
174
        }
175
176
        // My Profile
177
        if (in_array('my_profile', $tabs) &&
178
            api_get_setting('allow_social_tool') != 'true'
179
        ) {
180
            $navigation['myprofile'] = $possible_tabs['myprofile'];
181
        } else {
182
            $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
183
        }
184
185
        // My Agenda
186
        if (in_array('my_agenda', $tabs)) {
187
            $navigation['myagenda'] = $possible_tabs['myagenda'];
188
        } else {
189
            $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
190
        }
191
192
        // Gradebook
193
        if (api_get_setting('gradebook_enable') == 'true') {
194
            if (in_array('my_gradebook', $tabs)) {
195
                $navigation['mygradebook'] = $possible_tabs['mygradebook'];
196
            } else {
197
                $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
198
            }
199
        }
200
201
        // Reporting
202
        if (in_array('reporting', $tabs)) {
203
            if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
204
                $navigation['session_my_space'] = $possible_tabs['session_my_space'];
205
            } else {
206
                $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
207
            }
208
        } else {
209
            if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
210
                $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
211
            } else {
212
                $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
213
            }
214
        }
215
216
        // Social Networking
217
        if (in_array('social', $tabs)) {
218
            if (api_get_setting('allow_social_tool') == 'true') {
219
                $navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
220
            }
221
        } else {
222
            $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
223
        }
224
225
        // Dashboard
226
        if (in_array('dashboard', $tabs)) {
227
            if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
228
                $navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
229
            }
230
        } else {
231
            $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
232
        }
233
234
        ///if (api_is_student()) {
235
        if (true) {
236
            $params = ['variable = ? AND subkey = ?' => ['status', 'studentfollowup']];
237
            $result = api_get_settings_params_simple($params);
238
            $plugin = StudentFollowUpPlugin::create();
239
            if (!empty($result) && $result['selected_value'] === 'installed') {
240
                // Students
241
                $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php';
242
                if (api_is_platform_admin() || api_is_drh() || api_is_teacher()) {
243
                    $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/my_students.php';
244
                }
245
                $navigation['follow_up']['url'] = $url;
246
                $navigation['follow_up']['title'] = $plugin->get_lang('CareDetailView');
247
                $navigation['follow_up']['key'] = 'homepage';
248
                $navigation['follow_up']['icon'] = 'homepage.png';
249
            }
250
        }
251
252
        // Administration
253
        if (api_is_platform_admin(true)) {
254
            if (in_array('platform_administration', $tabs)) {
255
                $navigation['platform_admin'] = $possible_tabs['platform_admin'];
256
            } else {
257
                $menu_navigation['platform_admin'] = $possible_tabs['platform_admin'];
258
            }
259
        }
260
261
        // Custom tabs
262
        $customTabs = getCustomTabs();
263
        if (!empty($customTabs)) {
264
            foreach ($customTabs as $tab) {
265
                if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
266
                    isset($possible_tabs[$tab['subkey']])
267
                ) {
268
                    $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
269
                    $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
270
                } else {
271
                    if (isset($possible_tabs[$tab['subkey']])) {
272
                        $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
273
                        $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
274
                    }
275
                }
276
            }
277
        }
278
    } else {
279
        // Show custom tabs that are specifically marked as public
280
        $customTabs = getCustomTabs();
281
        if (!empty($customTabs)) {
282
            foreach ($customTabs as $tab) {
283
                if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
284
                    isset($possible_tabs[$tab['subkey']]) &&
285
                    api_get_plugin_setting(strtolower(str_replace('Tabs', '', $tab['subkeytext'])), 'public_main_menu_tab') == 'true'
286
                ) {
287
                    $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
288
                    $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
289
                } else {
290
                    if (isset($possible_tabs[$tab['subkey']])) {
291
                        $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
292
                        $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
293
                    }
294
                }
295
            }
296
        }
297
    }
298
299
    return [
300
        'menu_navigation' => $menu_navigation,
301
        'navigation' => $navigation,
302
        'possible_tabs' => $possible_tabs,
303
    ];
304
}
305
306
/**
307
 * Return the breadcrumb menu elements as an array of <li> items.
308
 *
309
 * @param array  $interbreadcrumb The elements to add to the breadcrumb
310
 * @param string $language_file   Deprecated
311
 * @param string $nameTools       The name of the current tool (not linked)
312
 *
313
 * @return string HTML string of <li> items
314
 */
315
function return_breadcrumb($interbreadcrumb, $language_file, $nameTools)
0 ignored issues
show
Unused Code introduced by
The parameter $language_file 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

315
function return_breadcrumb($interbreadcrumb, /** @scrutinizer ignore-unused */ $language_file, $nameTools)

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...
316
{
317
    $courseInfo = api_get_course_info();
318
    $user_id = api_get_user_id();
319
    $additionalBlocks = '';
320
321
    /*  Plugins for banner section */
322
    $web_course_path = api_get_path(WEB_COURSE_PATH);
323
324
    /* If the user is a coach he can see the users who are logged in its session */
325
    $navigation = [];
326
327
    $sessionId = api_get_session_id();
328
    // part 1: Course Homepage. If we are in a course then the first breadcrumb
329
    // is a link to the course homepage
330
    if (!empty($courseInfo) && !isset($_GET['hide_course_breadcrumb'])) {
331
        $sessionName = '';
332
        if (!empty($sessionId)) {
333
            /** @var \Chamilo\CoreBundle\Entity\Session $session */
334
            $session = Database::getManager()->find('ChamiloCoreBundle:Session', $sessionId);
335
            $sessionName = $session ? ' ('.cut($session->getName(), MAX_LENGTH_BREADCRUMB).')' : '';
0 ignored issues
show
introduced by
$session is of type Chamilo\CoreBundle\Entity\Session, thus it always evaluated to true. If $session can have other possible types, add them to main/inc/lib/banner.lib.php:333
Loading history...
336
        }
337
338
        $courseInfo['name'] = api_htmlentities($courseInfo['name']);
339
        $course_title = cut($courseInfo['name'], MAX_LENGTH_BREADCRUMB);
340
341
        switch (api_get_setting('breadcrumbs_course_homepage')) {
342
            case 'get_lang':
343
                $itemTitle = Display::return_icon(
344
                    'home.png',
345
                    get_lang('CourseHomepageLink'),
346
                    [],
347
                    ICON_SIZE_TINY
348
                );
349
                break;
350
            case 'course_code':
351
                $itemTitle = Display::return_icon(
352
                    'home.png',
353
                    $courseInfo['official_code'],
354
                    [],
355
                    ICON_SIZE_TINY
356
                )
357
                .' '.$courseInfo['official_code'];
358
                break;
359
            case 'session_name_and_course_title':
360
            default:
361
                $itemTitle = Display::return_icon(
362
                    'home.png',
363
                    $courseInfo['name'].$sessionName,
364
                    [],
365
                    ICON_SIZE_TINY
366
                )
367
                .' '.$course_title.$sessionName;
368
369
                if (!empty($sessionId) && ($session->getDuration() && !api_is_allowed_to_edit())) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $session does not seem to be defined for all execution paths leading up to this point.
Loading history...
370
                    $daysLeft = SessionManager::getDayLeftInSession(
371
                        ['id' => $session->getId(), 'duration' => $session->getDuration()],
372
                        $user_id
373
                    );
374
375
                    if ($daysLeft >= 0) {
376
                        $additionalBlocks .= Display::return_message(
377
                            sprintf(get_lang('SessionDurationXDaysLeft'), $daysLeft),
378
                            'information'
379
                        );
380
                    } else {
381
                        $additionalBlocks .= Display::return_message(
382
                            get_lang('YourSessionTimeHasExpired'),
383
                            'warning'
384
                        );
385
                    }
386
                }
387
                break;
388
        }
389
390
        /**
391
         * @todo could be useful adding the My courses in the breadcrumb
392
         * $navigation_item_my_courses['title'] = get_lang('MyCourses');
393
         * $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php';
394
         * $navigation[] = $navigation_item_my_courses;
395
         */
396
        $navigation[] = [
397
            'url' => $web_course_path.$courseInfo['path'].'/index.php?id_session='.$sessionId,
398
            'title' => $itemTitle,
399
        ];
400
    }
401
402
    /* part 2: Interbreadcrumbs. If there is an array $interbreadcrumb
403
    defined then these have to appear before the last breadcrumb
404
    (which is the tool itself)*/
405
    if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
406
        foreach ($interbreadcrumb as $breadcrumb_step) {
407
            if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
408
                continue;
409
            }
410
            if ($breadcrumb_step['url'] != '#') {
411
                $sep = strrchr($breadcrumb_step['url'], '?') ? '&' : '?';
412
                $courseParams = strpos($breadcrumb_step['url'], 'cidReq') === false ? api_get_cidreq() : '';
413
                $navigation_item['url'] = $breadcrumb_step['url'].$sep.$courseParams;
414
            } else {
415
                $navigation_item['url'] = '#';
416
            }
417
            $navigation_item['title'] = $breadcrumb_step['name'];
418
            // titles for shared folders
419
            if ($breadcrumb_step['name'] == 'shared_folder') {
420
                $navigation_item['title'] = get_lang('UserFolders');
421
            } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
422
                $navigation_item['title'] = get_lang('UserFolders');
423
            } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) {
424
                $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
425
                $navigation_item['title'] = $userinfo['complete_name'];
426
            } elseif ($breadcrumb_step['name'] == 'chat_files') {
427
                $navigation_item['title'] = get_lang('ChatFiles');
428
            } elseif ($breadcrumb_step['name'] == 'images') {
429
                $navigation_item['title'] = get_lang('Images');
430
            } elseif ($breadcrumb_step['name'] == 'video') {
431
                $navigation_item['title'] = get_lang('Video');
432
            } elseif ($breadcrumb_step['name'] == 'audio') {
433
                $navigation_item['title'] = get_lang('Audio');
434
            } elseif ($breadcrumb_step['name'] == 'flash') {
435
                $navigation_item['title'] = get_lang('Flash');
436
            } elseif ($breadcrumb_step['name'] == 'gallery') {
437
                $navigation_item['title'] = get_lang('Gallery');
438
            }
439
            // Fixes breadcrumb title now we applied the Security::remove_XSS and
440
            // we cut the string depending of the MAX_LENGTH_BREADCRUMB value
441
            $navigation_item['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
442
            $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
443
444
            $navigation[] = $navigation_item;
445
        }
446
    }
447
448
    $navigation_right = [];
449
    if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
450
        foreach ($interbreadcrumb as $breadcrumb_step) {
451
            if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
452
                if ($breadcrumb_step['url'] != '#') {
453
                    $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
454
                    $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
455
                } else {
456
                    $navigation_item['url'] = '#';
457
                }
458
                $breadcrumb_step['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
459
                $breadcrumb_step['title'] = Security::remove_XSS($navigation_item['title']);
460
                $navigation_right[] = $breadcrumb_step;
461
            }
462
        }
463
    }
464
465
    // part 3: The tool itself. If we are on the course homepage we do not want
466
    // to display the title of the course because this
467
    // is the same as the first part of the breadcrumbs (see part 1)
468
    if (isset($nameTools)) {
469
        $navigation_item['url'] = '#';
470
        $navigation_item['title'] = $nameTools;
471
        $navigation[] = $navigation_item;
472
    }
473
474
    $final_navigation = [];
475
    $counter = 0;
476
    foreach ($navigation as $index => $navigation_info) {
477
        if (!empty($navigation_info['title'])) {
478
            if ($navigation_info['url'] == '#') {
479
                $final_navigation[$index] = $navigation_info['title'];
480
            } else {
481
                $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
482
            }
483
            $counter++;
484
        }
485
    }
486
487
    $html = '';
488
489
    /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
490
    $view_as_student_link = null;
491
    if ($user_id && !empty($courseInfo)) {
492
        if ((
493
                api_is_course_admin() ||
494
                api_is_platform_admin() ||
495
                api_is_coach(null, null, false)
496
            ) &&
497
            api_get_setting('student_view_enabled') === 'true' && api_get_course_info()
498
        ) {
499
            $view_as_student_link = api_display_tool_view_option();
500
501
            // Only show link if LP can be editable
502
            /** @var learnpath $learnPath */
503
            $learnPath = Session::read('oLP');
504
            if (!empty($learnPath) && !empty($view_as_student_link)) {
505
                if ((int) $learnPath->get_lp_session_id() != (int) api_get_session_id()) {
506
                    $view_as_student_link = '';
507
                }
508
            }
509
        }
510
    }
511
512
    if (!empty($final_navigation)) {
513
        $lis = '';
514
        $i = 0;
515
        $final_navigation_count = count($final_navigation);
516
        if (!empty($final_navigation)) {
517
            // $home_link.= '<span class="divider">/</span>';
518
            if (!empty($home_link)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $home_link seems to never exist and therefore empty should always be true.
Loading history...
519
                $lis .= Display::tag('li', $home_link);
520
            }
521
522
            foreach ($final_navigation as $bread) {
523
                $bread_check = trim(strip_tags($bread));
524
                if (!empty($bread_check)) {
525
                    if ($final_navigation_count - 1 > $i) {
526
                        $bread .= '';
527
                    }
528
                    $lis .= Display::tag('li', $bread, ['class' => 'active']);
529
                    $i++;
530
                }
531
            }
532
        } else {
533
            if (!empty($home_link)) {
534
                $lis .= Display::tag('li', $home_link);
535
            }
536
        }
537
538
        // View as student/teacher link
539
        if (!empty($view_as_student_link)) {
540
            $html .= Display::tag('div', $view_as_student_link, ['id' => 'view_as_link', 'class' => 'pull-right']);
541
        }
542
543
        if (!empty($navigation_right)) {
544
            foreach ($navigation_right as $item) {
545
                $extra_class = isset($item['class']) ? $item['class'] : null;
546
                $lis .= Display::tag(
547
                    'li',
548
                    $item['title'],
549
                    ['class' => $extra_class.' pull-right']
550
                );
551
            }
552
        }
553
554
        if (!empty($lis)) {
555
            $html .= Display::tag('ul', $lis, ['class' => 'breadcrumb']);
556
        }
557
    }
558
559
    return $html.$additionalBlocks;
560
}
561
562
/**
563
 * Helper function to get the number of users online, using cache if available.
564
 *
565
 * @return int The number of users currently online
566
 */
567
function getOnlineUsersCount()
568
{
569
    $number = 0;
570
    $cacheAvailable = api_get_configuration_value('apc');
571
    if ($cacheAvailable === true) {
572
        $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple';
573
        if (apcu_exists($apcVar)) {
574
            $number = apcu_fetch($apcVar);
575
        } else {
576
            $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
577
            apcu_store($apcVar, $number, 15);
578
        }
579
    } else {
580
        $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
581
    }
582
583
    return $number;
584
}
585
586
/**
587
 * Helper function to get the number of users online in a course, using cache if available.
588
 *
589
 * @param int   $userId     The user ID
590
 * @param array $courseInfo The course details
591
 *
592
 * @return int The number of users currently online
593
 */
594
function getOnlineUsersInCourseCount($userId, $courseInfo)
595
{
596
    $cacheAvailable = api_get_configuration_value('apc');
597
    $numberOnlineInCourse = 0;
598
    if (!empty($courseInfo['id'])) {
599
        if ($cacheAvailable === true) {
600
            $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple_'.$courseInfo['id'];
601
            if (apcu_exists($apcVar)) {
602
                $numberOnlineInCourse = apcu_fetch($apcVar);
603
            } else {
604
                $numberOnlineInCourse = who_is_online_in_this_course_count(
605
                    $userId,
606
                    api_get_setting('time_limit_whosonline'),
607
                    $courseInfo['id']
608
                );
609
                apcu_store(
610
                    $apcVar,
611
                    $numberOnlineInCourse,
612
                    15
613
                );
614
            }
615
        } else {
616
            $numberOnlineInCourse = who_is_online_in_this_course_count(
617
                $userId,
618
                api_get_setting('time_limit_whosonline'),
619
                $courseInfo['id']
620
            );
621
        }
622
    }
623
624
    return $numberOnlineInCourse;
625
}
626
627
/**
628
 * Helper function to get the number of users online in a session, using cache if available.
629
 *
630
 * @param int $sessionId The session ID
631
 *
632
 * @return int The number of users currently online
633
 */
634
function getOnlineUsersInSessionCount($sessionId)
635
{
636
    $cacheAvailable = api_get_configuration_value('apc');
637
638
    if (!$sessionId) {
639
        return 0;
640
    }
641
642
    if ($cacheAvailable === true) {
643
        $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_session_count_simple_'.$sessionId;
644
645
        if (apcu_exists($apcVar)) {
646
            return apcu_fetch($apcVar);
647
        }
648
649
        $numberOnlineInCourse = whoIsOnlineInThisSessionCount(
650
            api_get_setting('time_limit_whosonline'),
651
            $sessionId
652
        );
653
        apcu_store($apcVar, $numberOnlineInCourse, 15);
654
655
        return $numberOnlineInCourse;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $numberOnlineInCourse returns the type boolean which is incompatible with the documented return type integer.
Loading history...
656
    }
657
658
    return whoIsOnlineInThisSessionCount(
0 ignored issues
show
Bug Best Practice introduced by
The expression return whoIsOnlineInThis...osonline'), $sessionId) returns the type boolean which is incompatible with the documented return type integer.
Loading history...
659
        api_get_setting('time_limit_whosonline'),
660
        $sessionId
661
    );
662
}
663