Passed
Push — master ( 568d8b...72684c )
by Julito
09:38
created

accessToWhoIsOnline()   C

Complexity

Conditions 13
Paths 12

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 18
nc 12
nop 0
dl 0
loc 28
rs 6.6166
c 0
b 0
f 0

How to fix   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
 * @param bool   $responsive add class img-responsive
51
 *
52
 * @return string HTML string with logo as an HTML element
53
 */
54
function return_logo($theme = '', $responsive = true)
55
{
56
    $siteName = api_get_setting('siteName');
57
    $class = 'img-fluid';
58
    if (!$responsive) {
59
        $class = '';
60
    }
61
62
    return ChamiloApi::getPlatformLogo(
63
        $theme,
64
        [
65
            'title' => $siteName,
66
            'class' => $class,
67
            'id' => 'header-logo',
68
        ]
69
    );
70
}
71
72
/**
73
 * Check if user have access to "who is online" page.
74
 *
75
 * @return bool
76
 */
77
function accessToWhoIsOnline()
78
{
79
    $user_id = api_get_user_id();
80
    $course_id = api_get_course_int_id();
81
    $access = false;
82
    if ((api_get_setting('showonline', 'world') === 'true' && !$user_id) ||
83
        (api_get_setting('showonline', 'users') === 'true' && $user_id) ||
84
        (api_get_setting('showonline', 'course') === 'true' && $user_id && $course_id)
85
    ) {
86
        $access = true;
87
    }
88
89
    if ($access === true) {
90
        $profileList = api_get_configuration_value('allow_online_users_by_status');
91
        if (!empty($profileList) && isset($profileList['status'])) {
92
            $userInfo = api_get_user_info();
93
            if ($userInfo['is_admin']) {
94
                $userInfo['status'] = PLATFORM_ADMIN;
95
            }
96
            $profileList = $profileList['status'];
97
            $access = false;
98
            if (in_array($userInfo['status'], $profileList)) {
99
                $access = true;
100
            }
101
        }
102
    }
103
104
    return $access;
105
}
106
107
/**
108
 * Return HTML string of a list as <li> items.
109
 *
110
 * @return string
111
 */
112
function returnNotificationMenu()
113
{
114
    $courseInfo = api_get_course_info();
115
    $user_id = api_get_user_id();
116
    $sessionId = api_get_session_id();
117
    $html = '';
118
119
    if (accessToWhoIsOnline()) {
120
        $number = getOnlineUsersCount();
121
        $number_online_in_course = getOnlineUsersInCourseCount($user_id, $courseInfo);
122
123
        // Display the who's online of the platform
124
        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...
125
            (api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
126
            (api_get_setting('showonline', 'users') == 'true' && $user_id)
127
        ) {
128
            $html .= '<li class="user-online"><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_self" title="'
129
                .get_lang('UsersOnline').'" >'
130
                .Display::return_icon('user.png', get_lang('UsersOnline'), [], ICON_SIZE_TINY)
131
                .' '.$number.'</a></li>';
132
        }
133
134
        // Display the who's online for the course
135
        if ($number_online_in_course &&
136
            (
137
                is_array($courseInfo) &&
138
                api_get_setting('showonline', 'course') == 'true' && isset($courseInfo['sysCode'])
139
            )
140
        ) {
141
            $html .= '<li class="user-online-course"><a href="'.api_get_path(WEB_PATH).'whoisonline.php?cidReq='.$courseInfo['sysCode']
142
                .'" target="_self">'
143
                .Display::return_icon('course.png', get_lang('UsersOnline').' '.get_lang('InThisCourse'), [], ICON_SIZE_TINY)
144
                .' '.$number_online_in_course.' </a></li>';
145
        }
146
147
        if (!empty($sessionId)) {
148
            $allow = api_is_platform_admin(true) ||
149
                api_is_coach($sessionId, null, false) ||
150
                SessionManager::isUserSubscribedAsStudent($sessionId, api_get_user_id());
151
            if ($allow) {
152
                $numberOnlineInSession = getOnlineUsersInSessionCount($sessionId);
153
                $html .= '<li class="user-online-session">
154
                            <a href="'.api_get_path(WEB_PATH).'whoisonlinesession.php" target="_self">'
155
                            .Display::return_icon('session.png', get_lang('UsersConnectedToMySessions'), [], ICON_SIZE_TINY)
156
                            .' '.$numberOnlineInSession.'</a></li>';
157
            }
158
        }
159
    }
160
161
    return $html;
162
}
163
164
/**
165
 * Return an array with different navigation mennu elements.
166
 *
167
 * @return array [menu_navigation[], navigation[], possible_tabs[]]
168
 */
169
function return_navigation_array()
170
{
171
    $navigation = [];
172
    $menu_navigation = [];
173
    $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

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

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