banner.lib.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
  4. use ChamiloSession as Session;
  5. /**
  6. * Code.
  7. *
  8. * @todo use globals or parameters or add this file in the template
  9. *
  10. * @package chamilo.include
  11. */
  12. /**
  13. * This function returns the custom tabs.
  14. *
  15. * @return array
  16. */
  17. function getCustomTabs()
  18. {
  19. $urlId = api_get_current_access_url_id();
  20. $tableSettingsCurrent = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  21. $sql = "SELECT * FROM $tableSettingsCurrent
  22. WHERE
  23. variable = 'show_tabs' AND
  24. subkey LIKE 'custom_tab_%' AND access_url = $urlId ";
  25. $result = Database::query($sql);
  26. $customTabs = [];
  27. while ($row = Database::fetch_assoc($result)) {
  28. $shouldAdd = true;
  29. if (strpos($row['subkey'], Plugin::TAB_FILTER_NO_STUDENT) !== false && api_is_student()) {
  30. $shouldAdd = false;
  31. } elseif (strpos($row['subkey'], Plugin::TAB_FILTER_ONLY_STUDENT) !== false && !api_is_student()) {
  32. $shouldAdd = false;
  33. }
  34. if ($shouldAdd) {
  35. $customTabs[] = $row;
  36. }
  37. }
  38. return $customTabs;
  39. }
  40. /**
  41. * Return the active logo of the portal, based on a series of settings.
  42. *
  43. * @param string $theme The name of the theme folder from web/css/themes/
  44. * @param bool $responsive add class img-responsive
  45. *
  46. * @return string HTML string with logo as an HTML element
  47. */
  48. function return_logo($theme = '', $responsive = true)
  49. {
  50. $siteName = api_get_setting('siteName');
  51. $class = 'img-fluid';
  52. if (!$responsive) {
  53. $class = '';
  54. }
  55. return ChamiloApi::getPlatformLogo(
  56. $theme,
  57. [
  58. 'title' => $siteName,
  59. 'class' => $class,
  60. 'id' => 'header-logo',
  61. ]
  62. );
  63. }
  64. /**
  65. * Check if user have access to "who is online" page.
  66. *
  67. * @return bool
  68. */
  69. function accessToWhoIsOnline()
  70. {
  71. $user_id = api_get_user_id();
  72. $course_id = api_get_course_int_id();
  73. $access = false;
  74. if ((api_get_setting('showonline', 'world') === 'true' && !$user_id) ||
  75. (api_get_setting('showonline', 'users') === 'true' && $user_id) ||
  76. (api_get_setting('showonline', 'course') === 'true' && $user_id && $course_id)
  77. ) {
  78. $access = true;
  79. }
  80. if ($access === true) {
  81. $profileList = api_get_configuration_value('allow_online_users_by_status');
  82. if (!empty($profileList) && isset($profileList['status'])) {
  83. $userInfo = api_get_user_info();
  84. if ($userInfo['is_admin']) {
  85. $userInfo['status'] = PLATFORM_ADMIN;
  86. }
  87. $profileList = $profileList['status'];
  88. $access = false;
  89. if (in_array($userInfo['status'], $profileList)) {
  90. $access = true;
  91. }
  92. }
  93. }
  94. return $access;
  95. }
  96. /**
  97. * Return HTML string of a list as <li> items.
  98. *
  99. * @return string
  100. */
  101. function returnNotificationMenu()
  102. {
  103. $courseInfo = api_get_course_info();
  104. $user_id = api_get_user_id();
  105. $sessionId = api_get_session_id();
  106. $html = '';
  107. if (accessToWhoIsOnline()) {
  108. $number = getOnlineUsersCount();
  109. $number_online_in_course = getOnlineUsersInCourseCount($user_id, $courseInfo);
  110. // Display the who's online of the platform
  111. if ($number &&
  112. (api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
  113. (api_get_setting('showonline', 'users') == 'true' && $user_id)
  114. ) {
  115. $html .= '<li class="user-online"><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_self" title="'
  116. .get_lang('Users online').'" >'
  117. .Display::return_icon('user.png', get_lang('Users online'), [], ICON_SIZE_TINY)
  118. .' '.$number.'</a></li>';
  119. }
  120. // Display the who's online for the course
  121. if ($number_online_in_course &&
  122. (
  123. is_array($courseInfo) &&
  124. api_get_setting('showonline', 'course') == 'true' && isset($courseInfo['sysCode'])
  125. )
  126. ) {
  127. $html .= '<li class="user-online-course"><a href="'.api_get_path(WEB_PATH).'whoisonline.php?cidReq='.$courseInfo['sysCode']
  128. .'" target="_self">'
  129. .Display::return_icon('course.png', get_lang('Users online').' '.get_lang('in this course'), [], ICON_SIZE_TINY)
  130. .' '.$number_online_in_course.' </a></li>';
  131. }
  132. if (!empty($sessionId)) {
  133. $allow = api_is_platform_admin(true) ||
  134. api_is_coach($sessionId, null, false) ||
  135. SessionManager::isUserSubscribedAsStudent($sessionId, api_get_user_id());
  136. if ($allow) {
  137. $numberOnlineInSession = getOnlineUsersInSessionCount($sessionId);
  138. $html .= '<li class="user-online-session">
  139. <a href="'.api_get_path(WEB_PATH).'whoisonlinesession.php" target="_self">'
  140. .Display::return_icon('session.png', get_lang('Online in my sessions'), [], ICON_SIZE_TINY)
  141. .' '.$numberOnlineInSession.'</a></li>';
  142. }
  143. }
  144. }
  145. return $html;
  146. }
  147. /**
  148. * Return an array with different navigation mennu elements.
  149. *
  150. * @return array [menu_navigation[], navigation[], possible_tabs[]]
  151. */
  152. function return_navigation_array()
  153. {
  154. $navigation = [];
  155. $menu_navigation = [];
  156. $possible_tabs = get_tabs();
  157. $tabs = api_get_setting('show_tabs');
  158. // Campus Homepage
  159. if (in_array('campus_homepage', $tabs)) {
  160. $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  161. } else {
  162. $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
  163. }
  164. if (api_get_setting('course_catalog_published') == 'true' && api_is_anonymous()) {
  165. $navigation[SECTION_CATALOG] = $possible_tabs[SECTION_CATALOG];
  166. }
  167. if (api_get_user_id() && !api_is_anonymous()) {
  168. // My Courses
  169. if (in_array('my_courses', $tabs)) {
  170. $navigation['mycourses'] = $possible_tabs['mycourses'];
  171. } else {
  172. $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
  173. }
  174. // My Profile
  175. if (in_array('my_profile', $tabs) &&
  176. api_get_setting('allow_social_tool') != 'true'
  177. ) {
  178. $navigation['myprofile'] = $possible_tabs['myprofile'];
  179. } else {
  180. $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
  181. }
  182. // My Agenda
  183. if (in_array('my_agenda', $tabs)) {
  184. $navigation['myagenda'] = $possible_tabs['myagenda'];
  185. } else {
  186. $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
  187. }
  188. // Gradebook
  189. if (api_get_setting('gradebook_enable') == 'true') {
  190. if (in_array('my_gradebook', $tabs)) {
  191. $navigation['mygradebook'] = $possible_tabs['mygradebook'];
  192. } else {
  193. $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
  194. }
  195. }
  196. // Reporting
  197. if (in_array('reporting', $tabs)) {
  198. if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
  199. $navigation['session_my_space'] = $possible_tabs['session_my_space'];
  200. } else {
  201. $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  202. }
  203. } else {
  204. if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
  205. $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
  206. } else {
  207. $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
  208. }
  209. }
  210. // Social Networking
  211. if (in_array('social', $tabs)) {
  212. if (api_get_setting('allow_social_tool') == 'true') {
  213. $navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  214. }
  215. } else {
  216. $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
  217. }
  218. // Dashboard
  219. if (in_array('dashboard', $tabs)) {
  220. if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
  221. $navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  222. }
  223. } else {
  224. $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
  225. }
  226. ///if (api_is_student()) {
  227. if (true) {
  228. $params = ['variable = ? AND subkey = ?' => ['status', 'studentfollowup']];
  229. $result = api_get_settings_params_simple($params);
  230. $plugin = StudentFollowUpPlugin::create();
  231. if (!empty($result) && $result['selected_value'] === 'installed') {
  232. // Students
  233. $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php';
  234. if (api_is_platform_admin() || api_is_drh() || api_is_teacher()) {
  235. $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/my_students.php';
  236. }
  237. $navigation['follow_up']['url'] = $url;
  238. $navigation['follow_up']['title'] = $plugin->get_lang('Student care detail view');
  239. $navigation['follow_up']['key'] = 'homepage';
  240. $navigation['follow_up']['icon'] = 'homepage.png';
  241. }
  242. }
  243. // Administration
  244. if (api_is_platform_admin(true)) {
  245. if (in_array('platform_administration', $tabs)) {
  246. $navigation['platform_admin'] = $possible_tabs['platform_admin'];
  247. } else {
  248. $menu_navigation['platform_admin'] = $possible_tabs['platform_admin'];
  249. }
  250. }
  251. // Custom tabs
  252. $customTabs = getCustomTabs();
  253. if (!empty($customTabs)) {
  254. foreach ($customTabs as $tab) {
  255. if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
  256. isset($possible_tabs[$tab['subkey']])
  257. ) {
  258. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  259. $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  260. } else {
  261. if (isset($possible_tabs[$tab['subkey']])) {
  262. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  263. $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  264. }
  265. }
  266. }
  267. }
  268. } else {
  269. // Show custom tabs that are specifically marked as public
  270. $customTabs = getCustomTabs();
  271. if (!empty($customTabs)) {
  272. foreach ($customTabs as $tab) {
  273. if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
  274. isset($possible_tabs[$tab['subkey']]) &&
  275. api_get_plugin_setting(strtolower(str_replace('Tabs', '', $tab['subkeytext'])), 'public_main_menu_tab') == 'true'
  276. ) {
  277. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  278. $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  279. } else {
  280. if (isset($possible_tabs[$tab['subkey']])) {
  281. $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
  282. $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
  283. }
  284. }
  285. }
  286. }
  287. }
  288. return [
  289. 'menu_navigation' => $menu_navigation,
  290. 'navigation' => $navigation,
  291. 'possible_tabs' => $possible_tabs,
  292. ];
  293. }
  294. /**
  295. * Return the breadcrumb menu elements as an array of <li> items.
  296. *
  297. * @param array $interbreadcrumb The elements to add to the breadcrumb
  298. * @param string $language_file Deprecated
  299. * @param string $nameTools The name of the current tool (not linked)
  300. *
  301. * @return string HTML string of <li> items
  302. */
  303. function return_breadcrumb($interbreadcrumb, $language_file, $nameTools)
  304. {
  305. $courseInfo = api_get_course_info();
  306. $user_id = api_get_user_id();
  307. $additionalBlocks = '';
  308. /* Plugins for banner section */
  309. $web_course_path = api_get_path(WEB_COURSE_PATH);
  310. /* If the user is a coach he can see the users who are logged in its session */
  311. $navigation = [];
  312. $sessionId = api_get_session_id();
  313. // part 1: Course Homepage. If we are in a course then the first breadcrumb
  314. // is a link to the course homepage
  315. if (!empty($courseInfo) && !isset($_GET['hide_course_breadcrumb'])) {
  316. $sessionName = '';
  317. if (!empty($sessionId)) {
  318. /** @var \Chamilo\CoreBundle\Entity\Session $session */
  319. $session = Database::getManager()->find('ChamiloCoreBundle:Session', $sessionId);
  320. $sessionName = $session ? ' ('.cut($session->getName(), MAX_LENGTH_BREADCRUMB).')' : '';
  321. }
  322. $courseInfo['name'] = api_htmlentities($courseInfo['name']);
  323. $course_title = cut($courseInfo['name'], MAX_LENGTH_BREADCRUMB);
  324. switch (api_get_setting('breadcrumbs_course_homepage')) {
  325. case 'get_lang':
  326. $itemTitle = Display::return_icon(
  327. 'home.png',
  328. get_lang('Course home'),
  329. [],
  330. ICON_SIZE_TINY
  331. );
  332. break;
  333. case 'course_code':
  334. $itemTitle = Display::return_icon(
  335. 'home.png',
  336. $courseInfo['official_code'],
  337. [],
  338. ICON_SIZE_TINY
  339. )
  340. .' '.$courseInfo['official_code'];
  341. break;
  342. case 'session_name_and_course_title':
  343. default:
  344. $itemTitle = Display::return_icon(
  345. 'home.png',
  346. $courseInfo['name'].$sessionName,
  347. [],
  348. ICON_SIZE_TINY
  349. )
  350. .' '.$course_title.$sessionName;
  351. if (!empty($sessionId) && ($session->getDuration() && !api_is_allowed_to_edit())) {
  352. $daysLeft = SessionManager::getDayLeftInSession(
  353. ['id' => $session->getId(), 'duration' => $session->getDuration()],
  354. $user_id
  355. );
  356. if ($daysLeft >= 0) {
  357. $additionalBlocks .= Display::return_message(
  358. sprintf(get_lang('This session has a maximum duration. Only %s days to go.'), $daysLeft),
  359. 'information'
  360. );
  361. } else {
  362. $additionalBlocks .= Display::return_message(
  363. get_lang('You are already registered but your allowed access time has expired.'),
  364. 'warning'
  365. );
  366. }
  367. }
  368. break;
  369. }
  370. /**
  371. * @todo could be useful adding the My courses in the breadcrumb
  372. * $navigation_item_my_courses['title'] = get_lang('My courses');
  373. * $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php';
  374. * $navigation[] = $navigation_item_my_courses;
  375. */
  376. $navigation[] = [
  377. 'url' => $web_course_path.$courseInfo['path'].'/index.php?id_session='.$sessionId,
  378. 'title' => $itemTitle,
  379. ];
  380. }
  381. /* part 2: Interbreadcrumbs. If there is an array $interbreadcrumb
  382. defined then these have to appear before the last breadcrumb
  383. (which is the tool itself)*/
  384. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  385. foreach ($interbreadcrumb as $breadcrumb_step) {
  386. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  387. continue;
  388. }
  389. if ($breadcrumb_step['url'] != '#') {
  390. $sep = strrchr($breadcrumb_step['url'], '?') ? '&' : '?';
  391. $courseParams = strpos($breadcrumb_step['url'], 'cidReq') === false ? api_get_cidreq() : '';
  392. $navigation_item['url'] = $breadcrumb_step['url'].$sep.$courseParams;
  393. } else {
  394. $navigation_item['url'] = '#';
  395. }
  396. $navigation_item['title'] = $breadcrumb_step['name'];
  397. // titles for shared folders
  398. if ($breadcrumb_step['name'] == 'shared_folder') {
  399. $navigation_item['title'] = get_lang('Folders of users');
  400. } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
  401. $navigation_item['title'] = get_lang('Folders of users');
  402. } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) {
  403. $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
  404. $navigation_item['title'] = $userinfo['complete_name'];
  405. } elseif ($breadcrumb_step['name'] == 'chat_files') {
  406. $navigation_item['title'] = get_lang('Chat conversations history');
  407. } elseif ($breadcrumb_step['name'] == 'images') {
  408. $navigation_item['title'] = get_lang('Images');
  409. } elseif ($breadcrumb_step['name'] == 'video') {
  410. $navigation_item['title'] = get_lang('Video');
  411. } elseif ($breadcrumb_step['name'] == 'audio') {
  412. $navigation_item['title'] = get_lang('Audio');
  413. } elseif ($breadcrumb_step['name'] == 'flash') {
  414. $navigation_item['title'] = get_lang('Flash');
  415. } elseif ($breadcrumb_step['name'] == 'gallery') {
  416. $navigation_item['title'] = get_lang('Gallery');
  417. }
  418. // Fixes breadcrumb title now we applied the Security::remove_XSS and
  419. // we cut the string depending of the MAX_LENGTH_BREADCRUMB value
  420. $navigation_item['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  421. $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
  422. $navigation[] = $navigation_item;
  423. }
  424. }
  425. $navigation_right = [];
  426. if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
  427. foreach ($interbreadcrumb as $breadcrumb_step) {
  428. if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
  429. if ($breadcrumb_step['url'] != '#') {
  430. $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
  431. $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
  432. } else {
  433. $navigation_item['url'] = '#';
  434. }
  435. $breadcrumb_step['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
  436. $breadcrumb_step['title'] = Security::remove_XSS($navigation_item['title']);
  437. $navigation_right[] = $breadcrumb_step;
  438. }
  439. }
  440. }
  441. // part 3: The tool itself. If we are on the course homepage we do not want
  442. // to display the title of the course because this
  443. // is the same as the first part of the breadcrumbs (see part 1)
  444. if (isset($nameTools)) {
  445. $navigation_item['url'] = '#';
  446. $navigation_item['title'] = $nameTools;
  447. $navigation[] = $navigation_item;
  448. }
  449. $final_navigation = [];
  450. $counter = 0;
  451. foreach ($navigation as $index => $navigation_info) {
  452. if (!empty($navigation_info['title'])) {
  453. if ($navigation_info['url'] == '#') {
  454. $final_navigation[$index] = $navigation_info['title'];
  455. } else {
  456. $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  457. }
  458. $counter++;
  459. }
  460. }
  461. $html = '';
  462. /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
  463. $view_as_student_link = null;
  464. if ($user_id && !empty($courseInfo)) {
  465. if ((
  466. api_is_course_admin() ||
  467. api_is_platform_admin() ||
  468. api_is_coach(null, null, false)
  469. ) &&
  470. api_get_setting('student_view_enabled') === 'true' && api_get_course_info()
  471. ) {
  472. $view_as_student_link = api_display_tool_view_option();
  473. // Only show link if LP can be editable
  474. /** @var learnpath $learnPath */
  475. $learnPath = Session::read('oLP');
  476. if (!empty($learnPath) && !empty($view_as_student_link)) {
  477. if ((int) $learnPath->get_lp_session_id() != (int) api_get_session_id()) {
  478. $view_as_student_link = '';
  479. }
  480. }
  481. }
  482. }
  483. if (!empty($final_navigation)) {
  484. $lis = '';
  485. $i = 0;
  486. $final_navigation_count = count($final_navigation);
  487. if (!empty($final_navigation)) {
  488. if (!empty($home_link)) {
  489. $lis .= Display::tag('li', $home_link);
  490. }
  491. foreach ($final_navigation as $bread) {
  492. $bread_check = trim(strip_tags($bread));
  493. if (!empty($bread_check)) {
  494. if ($final_navigation_count - 1 > $i) {
  495. $bread .= '';
  496. }
  497. $lis .= Display::tag('li', $bread, ['class' => 'active']);
  498. $i++;
  499. }
  500. }
  501. } else {
  502. if (!empty($home_link)) {
  503. $lis .= Display::tag('li', $home_link);
  504. }
  505. }
  506. // View as student/teacher link
  507. if (!empty($view_as_student_link)) {
  508. $html .= Display::tag('div', $view_as_student_link, ['id' => 'view_as_link', 'class' => 'pull-right']);
  509. }
  510. if (!empty($navigation_right)) {
  511. foreach ($navigation_right as $item) {
  512. $extra_class = isset($item['class']) ? $item['class'] : null;
  513. $lis .= Display::tag(
  514. 'li',
  515. $item['title'],
  516. ['class' => $extra_class.' pull-right']
  517. );
  518. }
  519. }
  520. if (!empty($lis)) {
  521. $html .= Display::tag('ul', $lis, ['class' => 'breadcrumb']);
  522. }
  523. }
  524. return $html.$additionalBlocks;
  525. }
  526. /**
  527. * Helper function to get the number of users online, using cache if available.
  528. *
  529. * @return int The number of users currently online
  530. */
  531. function getOnlineUsersCount()
  532. {
  533. $number = 0;
  534. $cacheAvailable = api_get_configuration_value('apc');
  535. if ($cacheAvailable === true) {
  536. $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple';
  537. if (apcu_exists($apcVar)) {
  538. $number = apcu_fetch($apcVar);
  539. } else {
  540. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  541. apcu_store($apcVar, $number, 15);
  542. }
  543. } else {
  544. $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
  545. }
  546. return $number;
  547. }
  548. /**
  549. * Helper function to get the number of users online in a course, using cache if available.
  550. *
  551. * @param int $userId The user ID
  552. * @param array $courseInfo The course details
  553. *
  554. * @return int The number of users currently online
  555. */
  556. function getOnlineUsersInCourseCount($userId, $courseInfo)
  557. {
  558. $cacheAvailable = api_get_configuration_value('apc');
  559. $numberOnlineInCourse = 0;
  560. if (!empty($courseInfo['id'])) {
  561. if ($cacheAvailable === true) {
  562. $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple_'.$courseInfo['id'];
  563. if (apcu_exists($apcVar)) {
  564. $numberOnlineInCourse = apcu_fetch($apcVar);
  565. } else {
  566. $numberOnlineInCourse = who_is_online_in_this_course_count(
  567. $userId,
  568. api_get_setting('time_limit_whosonline'),
  569. $courseInfo['id']
  570. );
  571. apcu_store(
  572. $apcVar,
  573. $numberOnlineInCourse,
  574. 15
  575. );
  576. }
  577. } else {
  578. $numberOnlineInCourse = who_is_online_in_this_course_count(
  579. $userId,
  580. api_get_setting('time_limit_whosonline'),
  581. $courseInfo['id']
  582. );
  583. }
  584. }
  585. return $numberOnlineInCourse;
  586. }
  587. /**
  588. * Helper function to get the number of users online in a session, using cache if available.
  589. *
  590. * @param int $sessionId The session ID
  591. *
  592. * @return int The number of users currently online
  593. */
  594. function getOnlineUsersInSessionCount($sessionId)
  595. {
  596. $cacheAvailable = api_get_configuration_value('apc');
  597. if (!$sessionId) {
  598. return 0;
  599. }
  600. if ($cacheAvailable === true) {
  601. $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_session_count_simple_'.$sessionId;
  602. if (apcu_exists($apcVar)) {
  603. return apcu_fetch($apcVar);
  604. }
  605. $numberOnlineInCourse = whoIsOnlineInThisSessionCount(
  606. api_get_setting('time_limit_whosonline'),
  607. $sessionId
  608. );
  609. apcu_store($apcVar, $numberOnlineInCourse, 15);
  610. return $numberOnlineInCourse;
  611. }
  612. return whoIsOnlineInThisSessionCount(
  613. api_get_setting('time_limit_whosonline'),
  614. $sessionId
  615. );
  616. }