return_navigation_array()   F
last analyzed

Complexity

Conditions 50
Paths > 20000

Size

Total Lines 154
Code Lines 94

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 50
eloc 94
nc 230408
nop 0
dl 0
loc 154
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

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

172
    $possible_tabs = /** @scrutinizer ignore-call */ get_tabs();
Loading history...
173
174
    $tabs = api_get_setting('show_tabs');
175
176
    // Campus Homepage
177
    if (in_array('campus_homepage', $tabs)) {
178
        $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
179
    } else {
180
        $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
181
    }
182
183
    if ('true' == api_get_setting('course_catalog_published') && api_is_anonymous()) {
184
        $navigation[SECTION_CATALOG] = $possible_tabs[SECTION_CATALOG];
185
    }
186
187
    if (api_get_user_id() && !api_is_anonymous()) {
188
        // My Courses
189
        if (in_array('my_courses', $tabs)) {
190
            $navigation['mycourses'] = $possible_tabs['mycourses'];
191
        } else {
192
            $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
193
        }
194
195
        // My Profile
196
        if (in_array('my_profile', $tabs) &&
197
            'true' != api_get_setting('allow_social_tool')
198
        ) {
199
            $navigation['myprofile'] = $possible_tabs['myprofile'];
200
        } else {
201
            $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
202
        }
203
204
        // My Agenda
205
        if (in_array('my_agenda', $tabs)) {
206
            $navigation['myagenda'] = $possible_tabs['myagenda'];
207
        } else {
208
            $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
209
        }
210
211
        // Gradebook
212
        if ('true' == api_get_setting('gradebook_enable')) {
213
            if (in_array('my_gradebook', $tabs)) {
214
                $navigation['mygradebook'] = $possible_tabs['mygradebook'];
215
            } else {
216
                $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
217
            }
218
        }
219
220
        // Reporting
221
        if (in_array('reporting', $tabs)) {
222
            if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
223
                $navigation['session_my_space'] = $possible_tabs['session_my_space'];
224
            } else {
225
                $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
226
            }
227
        } else {
228
            if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
229
                $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
230
            } else {
231
                $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
232
            }
233
        }
234
235
        // Social Networking
236
        if (in_array('social', $tabs)) {
237
            if ('true' == api_get_setting('allow_social_tool')) {
238
                $navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
239
            }
240
        } else {
241
            $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
242
        }
243
244
        // Dashboard
245
        if (in_array('dashboard', $tabs)) {
246
            if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
247
                $navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
248
            }
249
        } else {
250
            $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
251
        }
252
253
        ///if (api_is_student()) {
254
        if (true) {
255
            $params = ['variable = ? AND subkey = ?' => ['status', 'studentfollowup']];
256
            $result = api_get_settings_params_simple($params);
257
            $plugin = StudentFollowUpPlugin::create();
258
            if (!empty($result) && 'installed' === $result['selected_value']) {
259
                // Students
260
                $url = api_get_path(WEB_PLUGIN_PATH).'StudentFollowUp/posts.php';
261
                if (api_is_platform_admin() || api_is_drh() || api_is_teacher()) {
262
                    $url = api_get_path(WEB_PLUGIN_PATH).'StudentFollowUp/my_students.php';
263
                }
264
                $navigation['follow_up']['url'] = $url;
265
                $navigation['follow_up']['title'] = $plugin->get_lang('Student care detail view');
266
                $navigation['follow_up']['key'] = 'homepage';
267
                $navigation['follow_up']['icon'] = 'homepage.png';
268
            }
269
        }
270
271
        // Administration
272
        if (api_is_platform_admin(true)) {
273
            if (in_array('platform_administration', $tabs)) {
274
                $navigation['platform_admin'] = $possible_tabs['platform_admin'];
275
            } else {
276
                $menu_navigation['platform_admin'] = $possible_tabs['platform_admin'];
277
            }
278
        }
279
280
        // Custom tabs
281
        $customTabs = getCustomTabs();
282
        if (!empty($customTabs)) {
283
            foreach ($customTabs as $tab) {
284
                if ('true' == api_get_setting($tab['variable'], $tab['subkey']) &&
285
                    isset($possible_tabs[$tab['subkey']])
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
    } else {
298
        // Show custom tabs that are specifically marked as public
299
        $customTabs = getCustomTabs();
300
        if (!empty($customTabs)) {
301
            foreach ($customTabs as $tab) {
302
                if ('true' == api_get_setting($tab['variable'], $tab['subkey']) &&
303
                    isset($possible_tabs[$tab['subkey']]) &&
304
                    'true' == api_get_plugin_setting(strtolower(str_replace('Tabs', '', $tab['subkeytext'])), 'public_main_menu_tab')
305
                ) {
306
                    $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
307
                    $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
308
                } else {
309
                    if (isset($possible_tabs[$tab['subkey']])) {
310
                        $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
311
                        $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
312
                    }
313
                }
314
            }
315
        }
316
    }
317
318
    return [
319
        'menu_navigation' => $menu_navigation,
320
        'navigation' => $navigation,
321
        'possible_tabs' => $possible_tabs,
322
    ];
323
}
324
325
/**
326
 * Return the breadcrumb menu elements as an array of <li> items.
327
 *
328
 * @param array  $interbreadcrumb The elements to add to the breadcrumb
329
 * @param string $language_file   Deprecated
330
 * @param string $nameTools       The name of the current tool (not linked)
331
 *
332
 * @return string HTML string of <li> items
333
 */
334
function return_breadcrumb($interbreadcrumb, $language_file, $nameTools)
335
{
336
    $courseInfo = api_get_course_info();
337
    $user_id = api_get_user_id();
338
    $additionalBlocks = '';
339
340
    /*  Plugins for banner section */
341
    $web_course_path = api_get_path(WEB_COURSE_PATH);
342
343
    /* If the user is a coach he can see the users who are logged in its session */
344
    $navigation = [];
345
346
    $sessionId = api_get_session_id();
347
    // part 1: Course Homepage. If we are in a course then the first breadcrumb
348
    // is a link to the course homepage
349
    if (!empty($courseInfo) && !isset($_GET['hide_course_breadcrumb'])) {
350
        $sessionName = '';
351
        if (!empty($sessionId)) {
352
            $session = api_get_session_entity($sessionId);
353
            $sessionName = $session ? ' ('.cut($session->getTitle(), MAX_LENGTH_BREADCRUMB).')' : '';
354
        }
355
356
        $courseInfo['name'] = api_htmlentities($courseInfo['name']);
357
        $course_title = cut($courseInfo['name'], MAX_LENGTH_BREADCRUMB);
358
359
        switch (api_get_setting('breadcrumbs_course_homepage')) {
360
            case 'get_lang':
361
                $itemTitle = Display::getMdiIcon(ObjectIcon::HOME, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Course home'));
362
                break;
363
            case 'course_code':
364
                $itemTitle = Display::getMdiIcon(
365
                    ObjectIcon::HOME,
366
                    'ch-tool-icon',
367
                    null,
368
                    ICON_SIZE_TINY,
369
                    $courseInfo['official_code']
370
                )
371
                .' '.$courseInfo['official_code'];
372
                break;
373
            case 'session_name_and_course_title':
374
            default:
375
                $itemTitle = Display::getMdiIcon(
376
                    ObjectIcon::HOME,
377
                    'ch-tool-icon',
378
                    null,
379
                    ICON_SIZE_TINY,
380
                    $courseInfo['title'].$sessionName
381
                )
382
                .' '.$course_title.$sessionName;
383
384
                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...
385
                    $daysLeft = SessionManager::getDayLeftInSession(
386
                        ['id' => $session->getId(), 'duration' => $session->getDuration()],
387
                        $user_id
388
                    );
389
390
                    if ($daysLeft >= 0) {
391
                        $additionalBlocks .= Display::return_message(
392
                            sprintf(get_lang('This session has a maximum duration. Only %s days to go.'), $daysLeft),
393
                            'information'
394
                        );
395
                    } else {
396
                        $additionalBlocks .= Display::return_message(
397
                            get_lang('You are already registered but your allowed access time has expired.'),
398
                            'warning'
399
                        );
400
                    }
401
                }
402
                break;
403
        }
404
405
        /**
406
         * @todo could be useful adding the My courses in the breadcrumb
407
         * $navigation_item_my_courses['title'] = get_lang('My courses');
408
         * $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php';
409
         * $navigation[] = $navigation_item_my_courses;
410
         */
411
        $navigation[] = [
412
            'url' => $web_course_path.$courseInfo['path'].'/index.php?id_session='.$sessionId,
413
            'title' => $itemTitle,
414
        ];
415
    }
416
417
    /* part 2: Interbreadcrumbs. If there is an array $interbreadcrumb
418
    defined then these have to appear before the last breadcrumb
419
    (which is the tool itself)*/
420
    if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
421
        foreach ($interbreadcrumb as $breadcrumb_step) {
422
            if (isset($breadcrumb_step['type']) && 'right' == $breadcrumb_step['type']) {
423
                continue;
424
            }
425
            if ('#' != $breadcrumb_step['url']) {
426
                $sep = strrchr($breadcrumb_step['url'], '?') ? '&' : '?';
427
                $courseParams = false === strpos($breadcrumb_step['url'], 'cidReq') ? api_get_cidreq() : '';
428
                $navigation_item['url'] = $breadcrumb_step['url'].$sep.$courseParams;
429
            } else {
430
                $navigation_item['url'] = '#';
431
            }
432
            $navigation_item['title'] = $breadcrumb_step['name'];
433
            // titles for shared folders
434
            if ('shared_folder' == $breadcrumb_step['name']) {
435
                $navigation_item['title'] = get_lang('Folders of users');
436
            } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
437
                $navigation_item['title'] = get_lang('Folders of users');
438
            } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) {
439
                $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
440
                $navigation_item['title'] = $userinfo['complete_name'];
441
            } elseif ('chat_files' == $breadcrumb_step['name']) {
442
                $navigation_item['title'] = get_lang('Chat conversations history');
443
            } elseif ('images' == $breadcrumb_step['name']) {
444
                $navigation_item['title'] = get_lang('Images');
445
            } elseif ('video' == $breadcrumb_step['name']) {
446
                $navigation_item['title'] = get_lang('Video');
447
            } elseif ('audio' == $breadcrumb_step['name']) {
448
                $navigation_item['title'] = get_lang('Audio');
449
            } elseif ('flash' == $breadcrumb_step['name']) {
450
                $navigation_item['title'] = get_lang('Flash');
451
            } elseif ('gallery' == $breadcrumb_step['name']) {
452
                $navigation_item['title'] = get_lang('Gallery');
453
            }
454
            // Fixes breadcrumb title now we applied the Security::remove_XSS and
455
            // we cut the string depending of the MAX_LENGTH_BREADCRUMB value
456
            $navigation_item['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
457
            $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
458
459
            $navigation[] = $navigation_item;
460
        }
461
    }
462
463
    $navigation_right = [];
464
    if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
465
        foreach ($interbreadcrumb as $breadcrumb_step) {
466
            if (isset($breadcrumb_step['type']) && 'right' == $breadcrumb_step['type']) {
467
                if ('#' != $breadcrumb_step['url']) {
468
                    $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
469
                    $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
470
                } else {
471
                    $navigation_item['url'] = '#';
472
                }
473
                $breadcrumb_step['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
474
                $breadcrumb_step['title'] = Security::remove_XSS($navigation_item['title']);
475
                $navigation_right[] = $breadcrumb_step;
476
            }
477
        }
478
    }
479
480
    // part 3: The tool itself. If we are on the course homepage we do not want
481
    // to display the title of the course because this
482
    // is the same as the first part of the breadcrumbs (see part 1)
483
    if (isset($nameTools)) {
484
        $navigation_item['url'] = '#';
485
        $navigation_item['title'] = $nameTools;
486
        $navigation[] = $navigation_item;
487
    }
488
489
    $final_navigation = [];
490
    $counter = 0;
491
    foreach ($navigation as $index => $navigation_info) {
492
        if (!empty($navigation_info['title'])) {
493
            if ('#' == $navigation_info['url']) {
494
                $final_navigation[$index] = $navigation_info['title'];
495
            } else {
496
                $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
497
            }
498
            $counter++;
499
        }
500
    }
501
502
    $html = '';
503
504
    /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
505
    $view_as_student_link = null;
506
    if ($user_id && !empty($courseInfo)) {
507
        if ((
508
                api_is_course_admin() ||
509
                api_is_platform_admin() ||
510
                api_is_coach(null, null, false)
511
            ) &&
512
            'true' === api_get_setting('student_view_enabled') && api_get_course_info()
513
        ) {
514
            $view_as_student_link = api_display_tool_view_option();
515
516
            // Only show link if LP can be editable
517
            /** @var learnpath $learnPath */
518
            $learnPath = Session::read('oLP');
519
            if (!empty($learnPath) && !empty($view_as_student_link)) {
520
                if ((int) $learnPath->get_lp_session_id() != (int) api_get_session_id()) {
521
                    $view_as_student_link = '';
522
                }
523
            }
524
        }
525
    }
526
527
    if (!empty($final_navigation)) {
528
        $lis = '';
529
        $i = 0;
530
        $final_navigation_count = count($final_navigation);
531
        if (!empty($final_navigation)) {
532
            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...
533
                $lis .= Display::tag('li', $home_link);
534
            }
535
536
            foreach ($final_navigation as $bread) {
537
                $bread_check = trim(strip_tags($bread));
538
                if (!empty($bread_check)) {
539
                    if ($final_navigation_count - 1 > $i) {
540
                        $bread .= '';
541
                    }
542
                    $lis .= Display::tag('li', $bread, ['class' => 'active']);
543
                    $i++;
544
                }
545
            }
546
        } else {
547
            if (!empty($home_link)) {
548
                $lis .= Display::tag('li', $home_link);
549
            }
550
        }
551
552
        // View as student/teacher link
553
        if (!empty($view_as_student_link)) {
554
            $html .= Display::tag('div', $view_as_student_link, ['id' => 'view_as_link', 'class' => 'pull-right']);
555
        }
556
557
        if (!empty($navigation_right)) {
558
            foreach ($navigation_right as $item) {
559
                $extra_class = isset($item['class']) ? $item['class'] : null;
560
                $lis .= Display::tag(
561
                    'li',
562
                    $item['title'],
563
                    ['class' => $extra_class.' pull-right']
564
                );
565
            }
566
        }
567
568
        if (!empty($lis)) {
569
            $html .= Display::tag('ul', $lis, ['class' => 'breadcrumb']);
570
        }
571
    }
572
573
    return $html.$additionalBlocks;
574
}
575
576
/**
577
 * Helper function to get the number of users online, using cache if available.
578
 *
579
 * @return int The number of users currently online
580
 */
581
function getOnlineUsersCount()
582
{
583
    $number = 0;
584
    $cacheAvailable = api_get_configuration_value('apc');
585
    if (true === $cacheAvailable) {
586
        $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple';
587
        if (apcu_exists($apcVar)) {
588
            $number = apcu_fetch($apcVar);
589
        } else {
590
            $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
591
            apcu_store($apcVar, $number, 15);
592
        }
593
    } else {
594
        $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
595
    }
596
597
    return $number;
598
}
599
600
/**
601
 * Helper function to get the number of users online in a course, using cache if available.
602
 *
603
 * @param int   $userId     The user ID
604
 * @param array $courseInfo The course details
605
 *
606
 * @return int The number of users currently online
607
 */
608
function getOnlineUsersInCourseCount($userId, $courseInfo)
609
{
610
    $cacheAvailable = api_get_configuration_value('apc');
611
    $numberOnlineInCourse = 0;
612
    if (!empty($courseInfo['id'])) {
613
        if (true === $cacheAvailable) {
614
            $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple_'.$courseInfo['id'];
615
            if (apcu_exists($apcVar)) {
616
                $numberOnlineInCourse = apcu_fetch($apcVar);
617
            } else {
618
                $numberOnlineInCourse = who_is_online_in_this_course_count(
619
                    $userId,
620
                    api_get_setting('time_limit_whosonline'),
621
                    $courseInfo['id']
622
                );
623
                apcu_store(
624
                    $apcVar,
625
                    $numberOnlineInCourse,
626
                    15
627
                );
628
            }
629
        } else {
630
            $numberOnlineInCourse = who_is_online_in_this_course_count(
631
                $userId,
632
                api_get_setting('time_limit_whosonline'),
633
                $courseInfo['id']
634
            );
635
        }
636
    }
637
638
    return $numberOnlineInCourse;
639
}
640
641
/**
642
 * Helper function to get the number of users online in a session, using cache if available.
643
 *
644
 * @param int $sessionId The session ID
645
 *
646
 * @return int The number of users currently online
647
 */
648
function getOnlineUsersInSessionCount($sessionId)
649
{
650
    $cacheAvailable = api_get_configuration_value('apc');
651
652
    if (!$sessionId) {
653
        return 0;
654
    }
655
656
    if (true === $cacheAvailable) {
657
        $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_session_count_simple_'.$sessionId;
658
659
        if (apcu_exists($apcVar)) {
660
            return apcu_fetch($apcVar);
661
        }
662
663
        $numberOnlineInCourse = whoIsOnlineInThisSessionCount(
664
            api_get_setting('time_limit_whosonline'),
665
            $sessionId
666
        );
667
        apcu_store($apcVar, $numberOnlineInCourse, 15);
668
669
        return $numberOnlineInCourse;
670
    }
671
672
    return whoIsOnlineInThisSessionCount(
673
        api_get_setting('time_limit_whosonline'),
674
        $sessionId
675
    );
676
}
677