userportal.lib.php 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class IndexManager.
  5. */
  6. class IndexManager
  7. {
  8. const VIEW_BY_DEFAULT = 0;
  9. const VIEW_BY_SESSION = 1;
  10. // An instance of the template engine
  11. // No need to initialize because IndexManager is not static,
  12. // and the constructor immediately instantiates a Template
  13. public $tpl;
  14. public $name = '';
  15. public $home = '';
  16. public $default_home = 'home/';
  17. /**
  18. * Construct.
  19. *
  20. * @param string $title
  21. */
  22. public function __construct($title)
  23. {
  24. $this->tpl = new Template($title);
  25. $this->home = api_get_home_path();
  26. $this->user_id = api_get_user_id();
  27. $this->load_directories_preview = false;
  28. // Load footer plugins systematically
  29. /*$config = api_get_settings_params(array('subkey = ? ' => 'customfooter', ' AND category = ? ' => 'Plugins'));
  30. if (!empty($config)) {
  31. foreach ($config as $fooid => $configrecord) {
  32. $canonic = preg_replace('/^customfooter_/', '', $configrecord['variable']);
  33. $footerconfig->$canonic = $configrecord['selected_value'];
  34. }
  35. if (!empty($footerconfig->footer_left)) {
  36. $this->tpl->assign('plugin_footer_left', $footerconfig->footer_left);
  37. }
  38. if (!empty($footerconfig->footer_right)) {
  39. $this->tpl->assign('plugin_footer_right', $footerconfig->footer_right);
  40. }
  41. }*/
  42. if (api_get_setting('show_documents_preview') === 'true') {
  43. $this->load_directories_preview = true;
  44. }
  45. }
  46. /**
  47. * @param bool $setLoginForm
  48. */
  49. public function set_login_form($setLoginForm = true)
  50. {
  51. global $loginFailed;
  52. $this->tpl->setLoginForm($setLoginForm);
  53. }
  54. /**
  55. * @param array $personal_course_list
  56. */
  57. public function return_exercise_block($personal_course_list)
  58. {
  59. $exercise_list = [];
  60. if (!empty($personal_course_list)) {
  61. foreach ($personal_course_list as $course_item) {
  62. $course_code = $course_item['c'];
  63. $session_id = $course_item['id_session'];
  64. $exercises = ExerciseLib::get_exercises_to_be_taken(
  65. $course_code,
  66. $session_id
  67. );
  68. foreach ($exercises as $exercise_item) {
  69. $exercise_item['course_code'] = $course_code;
  70. $exercise_item['session_id'] = $session_id;
  71. $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC');
  72. $exercise_list[] = $exercise_item;
  73. }
  74. }
  75. if (!empty($exercise_list)) {
  76. $exercise_list = msort($exercise_list, 'tms');
  77. $my_exercise = $exercise_list[0];
  78. $url = Display::url(
  79. $my_exercise['title'],
  80. api_get_path(
  81. WEB_CODE_PATH
  82. ).'exercise/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']
  83. );
  84. $this->tpl->assign('exercise_url', $url);
  85. $this->tpl->assign(
  86. 'exercise_end_date',
  87. api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT)
  88. );
  89. }
  90. }
  91. }
  92. /**
  93. * @param bool $show_slide
  94. *
  95. * @return null|string
  96. */
  97. public function return_announcements($show_slide = true)
  98. {
  99. $hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected');
  100. $currentUserId = api_get_user_id();
  101. if ($hideAnnouncements == 'true' && empty($currentUserId)) {
  102. return null;
  103. }
  104. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
  105. $announcement = intval($announcement);
  106. if (!api_is_anonymous() && $this->user_id) {
  107. $visibility = SystemAnnouncementManager::getCurrentUserVisibility();
  108. if ($show_slide) {
  109. $announcements = SystemAnnouncementManager::displayAnnouncementsSlider(
  110. $visibility,
  111. $announcement
  112. );
  113. } else {
  114. $announcements = SystemAnnouncementManager::displayAllAnnouncements(
  115. $visibility,
  116. $announcement
  117. );
  118. }
  119. } else {
  120. if ($show_slide) {
  121. $announcements = SystemAnnouncementManager::displayAnnouncementsSlider(
  122. SystemAnnouncementManager::VISIBLE_GUEST,
  123. $announcement
  124. );
  125. } else {
  126. $announcements = SystemAnnouncementManager::displayAllAnnouncements(
  127. SystemAnnouncementManager::VISIBLE_GUEST,
  128. $announcement
  129. );
  130. }
  131. }
  132. return $announcements;
  133. }
  134. /**
  135. * Alias for the online_logout() function.
  136. *
  137. * @param bool $redirect Whether to ask online_logout to redirect to index.php or not
  138. * @param array $logoutInfo Information stored by local.inc.php before new context ['uid'=> x, 'cid'=>y, 'sid'=>z]
  139. */
  140. public function logout($redirect = true, $logoutInfo = [])
  141. {
  142. online_logout($this->user_id, true);
  143. Event::courseLogout($logoutInfo);
  144. }
  145. /**
  146. * This function checks if there are courses that are open to the world in the platform course categories (=faculties).
  147. *
  148. * @param string $category
  149. *
  150. * @return bool
  151. */
  152. public function category_has_open_courses($category)
  153. {
  154. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  155. $main_course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  156. $category = Database::escape_string($category);
  157. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  158. $sql_result = Database::query($sql_query);
  159. while ($course = Database::fetch_array($sql_result)) {
  160. if (!$setting_show_also_closed_courses) {
  161. if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) ||
  162. ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)
  163. ) {
  164. return true; //at least one open course
  165. }
  166. } else {
  167. if (isset($course['visibility'])) {
  168. return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
  169. }
  170. }
  171. }
  172. return false;
  173. }
  174. /**
  175. * Includes a created page.
  176. *
  177. * @param bool $getIncludedFile Whether to include a file as provided in URL GET or simply the homepage
  178. *
  179. * @return string
  180. */
  181. public function return_home_page($getIncludedFile = false)
  182. {
  183. $userId = api_get_user_id();
  184. // Including the page for the news
  185. $html = '';
  186. if ($getIncludedFile === true) {
  187. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  188. $open = @(string) file_get_contents($this->home.$_GET['include']);
  189. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  190. }
  191. } else {
  192. // Hiding home top when user not connected.
  193. $hideTop = api_get_setting('hide_home_top_when_connected');
  194. if ($hideTop == 'true' && !empty($userId)) {
  195. return $html;
  196. }
  197. if (!empty($_SESSION['user_language_choice'])) {
  198. $user_selected_language = $_SESSION['user_language_choice'];
  199. } elseif (!empty($_SESSION['_user']['language'])) {
  200. $user_selected_language = $_SESSION['_user']['language'];
  201. } else {
  202. $user_selected_language = api_get_setting('platformLanguage');
  203. }
  204. $home_top_temp = '';
  205. // Try language specific home
  206. if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
  207. $home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
  208. }
  209. // Try default language home
  210. if (empty($home_top_temp)) {
  211. if (file_exists($this->home.'home_top.html')) {
  212. $home_top_temp = file_get_contents($this->home.'home_top.html');
  213. } else {
  214. if (file_exists($this->default_home.'home_top.html')) {
  215. $home_top_temp = file_get_contents($this->default_home.'home_top.html');
  216. }
  217. }
  218. }
  219. if (trim($home_top_temp) == '' && api_is_platform_admin()) {
  220. $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
  221. } else {
  222. $home_top_temp;
  223. }
  224. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  225. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  226. }
  227. return $html;
  228. }
  229. /**
  230. * @return string
  231. */
  232. public function return_notice()
  233. {
  234. $user_selected_language = api_get_interface_language();
  235. // Notice
  236. $home_notice = @(string) file_get_contents($this->home.'home_notice_'.$user_selected_language.'.html');
  237. if (empty($home_notice)) {
  238. $home_notice = @(string) file_get_contents($this->home.'home_notice.html');
  239. }
  240. if (!empty($home_notice)) {
  241. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  242. }
  243. return $home_notice;
  244. }
  245. /**
  246. * @return string
  247. */
  248. public function return_help()
  249. {
  250. $user_selected_language = api_get_interface_language();
  251. $platformLanguage = api_get_setting('platformLanguage');
  252. // Help section.
  253. /* Hide right menu "general" and other parts on anonymous right menu. */
  254. if (!isset($user_selected_language)) {
  255. $user_selected_language = $platformLanguage;
  256. }
  257. $html = '';
  258. $home_menu = @(string) file_get_contents($this->home.'home_menu_'.$user_selected_language.'.html');
  259. if (!empty($home_menu)) {
  260. $html = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  261. }
  262. return $html;
  263. }
  264. /**
  265. * Generate the block for show a panel with links to My Certificates and Certificates Search pages.
  266. *
  267. * @return array The HTML code for the panel
  268. */
  269. public function returnSkillLinks()
  270. {
  271. $items = [];
  272. if (!api_is_anonymous() &&
  273. api_get_configuration_value('hide_my_certificate_link') === false
  274. ) {
  275. $items[] = [
  276. 'icon' => Display::return_icon('graduation.png', get_lang('MyCertificates')),
  277. 'link' => api_get_path(WEB_CODE_PATH).'gradebook/my_certificates.php',
  278. 'title' => get_lang('MyCertificates'),
  279. ];
  280. }
  281. if (api_get_setting('allow_public_certificates') == 'true') {
  282. $items[] = [
  283. 'icon' => Display::return_icon('search_graduation.png', get_lang('Search')),
  284. 'link' => api_get_path(WEB_CODE_PATH).'gradebook/search.php',
  285. 'title' => get_lang('Search'),
  286. ];
  287. }
  288. $myCertificate = GradebookUtils::get_certificate_by_user_id(
  289. +0,
  290. $this->user_id
  291. );
  292. if ($myCertificate) {
  293. $items[] = [
  294. 'icon' => Display::return_icon(
  295. 'skill-badges.png',
  296. get_lang('MyGeneralCertificate'),
  297. null,
  298. ICON_SIZE_SMALL
  299. ),
  300. 'link' => api_get_path(WEB_CODE_PATH).'social/my_skills_report.php?a=generate_custom_skill',
  301. 'title' => get_lang('MyGeneralCertificate'),
  302. ];
  303. }
  304. if (Skill::isAllowed(api_get_user_id(), false)) {
  305. $items[] = [
  306. 'icon' => Display::return_icon('skill-badges.png', get_lang('MySkills')),
  307. 'link' => api_get_path(WEB_CODE_PATH).'social/my_skills_report.php',
  308. 'title' => get_lang('MySkills'),
  309. ];
  310. $allowSkillsManagement = api_get_setting('allow_hr_skills_management') == 'true';
  311. if (($allowSkillsManagement && api_is_drh()) || api_is_platform_admin()) {
  312. $items[] = [
  313. 'icon' => Display::return_icon('edit-skill.png', get_lang('MySkills')),
  314. 'link' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php',
  315. 'title' => get_lang('ManageSkills'),
  316. ];
  317. }
  318. }
  319. return $items;
  320. }
  321. /**
  322. * Reacts on a failed login:
  323. * Displays an explanation with a link to the registration form.
  324. *
  325. * @version 1.0.1
  326. */
  327. public function handle_login_failed()
  328. {
  329. return $this->tpl->handleLoginFailed();
  330. }
  331. /**
  332. * Display list of courses in a category.
  333. * (for anonymous users).
  334. *
  335. * @version 1.1
  336. *
  337. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  338. * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
  339. */
  340. public function return_courses_in_categories()
  341. {
  342. $result = '';
  343. $stok = Security::get_token();
  344. // Initialization.
  345. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  346. $web_course_path = api_get_path(WEB_COURSE_PATH);
  347. $category = isset($_GET['category']) ? Database::escape_string($_GET['category']) : '';
  348. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  349. // Database table definitions.
  350. $main_course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  351. $main_category_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
  352. // Get list of courses in category $category.
  353. $sql = "SELECT * FROM $main_course_table cours
  354. WHERE category_code = '".$category."'
  355. ORDER BY title, UPPER(visual_code)";
  356. // Showing only the courses of the current access_url_id.
  357. if (api_is_multiple_url_enabled()) {
  358. $url_access_id = api_get_current_access_url_id();
  359. if ($url_access_id != -1) {
  360. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  361. $sql = "SELECT * FROM $main_course_table as course
  362. INNER JOIN $tbl_url_rel_course as url_rel_course
  363. ON (url_rel_course.c_id = course.id)
  364. WHERE
  365. access_url_id = $url_access_id AND
  366. category_code = '".$category."'
  367. ORDER BY title, UPPER(visual_code)";
  368. }
  369. }
  370. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  371. $queryResult = Database::query($sql);
  372. while ($course_result = Database::fetch_array($queryResult)) {
  373. $course_list[] = $course_result;
  374. }
  375. $numRows = Database::num_rows($queryResult);
  376. // $setting_show_also_closed_courses
  377. if ($user_identified) {
  378. if ($setting_show_also_closed_courses) {
  379. $platform_visible_courses = '';
  380. } else {
  381. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  382. }
  383. } else {
  384. if ($setting_show_also_closed_courses) {
  385. $platform_visible_courses = '';
  386. } else {
  387. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  388. }
  389. }
  390. $sqlGetSubCatList = "
  391. SELECT t1.name,
  392. t1.code,
  393. t1.parent_id,
  394. t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  395. FROM $main_category_table t1
  396. LEFT JOIN $main_category_table t2
  397. ON t1.code=t2.parent_id
  398. LEFT JOIN $main_course_table t3
  399. ON (t3.category_code = t1.code $platform_visible_courses)
  400. WHERE t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  401. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count
  402. ORDER BY t1.tree_pos, t1.name";
  403. // Showing only the category of courses of the current access_url_id
  404. if (api_is_multiple_url_enabled()) {
  405. $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
  406. $courseCategoryCondition = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
  407. $url_access_id = api_get_current_access_url_id();
  408. if ($url_access_id != -1) {
  409. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  410. $sqlGetSubCatList = "
  411. SELECT t1.name,
  412. t1.code,
  413. t1.parent_id,
  414. t1.children_count,
  415. COUNT(DISTINCT t3.code) AS nbCourse
  416. FROM $main_category_table t1
  417. $courseCategoryCondition
  418. LEFT JOIN $main_category_table t2 ON t1.code = t2.parent_id
  419. LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses)
  420. INNER JOIN $tbl_url_rel_course as url_rel_course
  421. ON (url_rel_course.c_id = t3.id)
  422. WHERE
  423. url_rel_course.access_url_id = $url_access_id AND
  424. t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  425. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count
  426. ORDER BY t1.tree_pos, t1.name";
  427. }
  428. }
  429. $resCats = Database::query($sqlGetSubCatList);
  430. $thereIsSubCat = false;
  431. if (Database::num_rows($resCats) > 0) {
  432. $htmlListCat = Display::page_header(get_lang('CatList'));
  433. $htmlListCat .= '<ul>';
  434. $htmlTitre = '';
  435. while ($catLine = Database::fetch_array($resCats)) {
  436. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  437. if ($category_has_open_courses) {
  438. // The category contains courses accessible to anonymous visitors.
  439. $htmlListCat .= '<li>';
  440. $htmlListCat .= '<a href="'.api_get_self(
  441. ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  442. if (api_get_setting('show_number_of_courses') == 'true') {
  443. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  444. }
  445. $htmlListCat .= "</li>";
  446. $thereIsSubCat = true;
  447. } elseif ($catLine['children_count'] > 0) {
  448. // The category has children, subcategories.
  449. $htmlListCat .= '<li>';
  450. $htmlListCat .= '<a href="'.api_get_self(
  451. ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  452. $htmlListCat .= "</li>";
  453. $thereIsSubCat = true;
  454. } elseif (api_get_setting('show_empty_course_categories') == 'true') {
  455. /* End changed code to eliminate the (0 courses) after empty categories. */
  456. $htmlListCat .= '<li>';
  457. $htmlListCat .= $catLine['name'];
  458. $htmlListCat .= "</li>";
  459. $thereIsSubCat = true;
  460. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  461. // TODO: deprecate this useless feature - this includes removing system variable
  462. if (empty($htmlTitre)) {
  463. $htmlTitre = '<p>';
  464. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  465. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  466. }
  467. $htmlTitre .= "</p>";
  468. }
  469. }
  470. $htmlListCat .= "</ul>";
  471. }
  472. $result .= $htmlTitre;
  473. if ($thereIsSubCat) {
  474. $result .= $htmlListCat;
  475. }
  476. while ($categoryName = Database::fetch_array($resCats)) {
  477. $result .= '<h3>'.$categoryName['name']."</h3>\n";
  478. }
  479. $courses_list_string = '';
  480. $courses_shown = 0;
  481. if ($numRows > 0) {
  482. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  483. $courses_list_string .= "<ul>";
  484. if (api_get_user_id()) {
  485. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  486. }
  487. foreach ($course_list as $course) {
  488. // $setting_show_also_closed_courses
  489. if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) {
  490. continue;
  491. }
  492. if (!$setting_show_also_closed_courses) {
  493. // If we do not show the closed courses
  494. // we only show the courses that are open to the world (to everybody)
  495. // and the courses that are open to the platform (if the current user is a registered user.
  496. if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) ||
  497. ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)
  498. ) {
  499. $courses_shown++;
  500. $courses_list_string .= "<li>";
  501. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  502. $course_details = [];
  503. if (api_get_setting('display_coursecode_in_courselist') === 'true') {
  504. $course_details[] = '('.$course['visual_code'].')';
  505. }
  506. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  507. $course_details[] = CourseManager::getTeacherListFromCourseCodeToString($course['code']);
  508. }
  509. if (api_get_setting('show_different_course_language') === 'true' &&
  510. $course['course_language'] != api_get_setting('platformLanguage')
  511. ) {
  512. $course_details[] = $course['course_language'];
  513. }
  514. $courses_list_string .= implode(' - ', $course_details);
  515. $courses_list_string .= "</li>";
  516. }
  517. } else {
  518. // We DO show the closed courses.
  519. // The course is accessible if (link to the course homepage):
  520. // 1. the course is open to the world (doesn't matter if the user is logged in or not): $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD);
  521. // 2. the user is logged in and the course is open to the world or open to the platform: ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM);
  522. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  523. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  524. // 5. the user is the platform admin api_is_platform_admin().
  525. $courses_shown++;
  526. $courses_list_string .= "<li>";
  527. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  528. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  529. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  530. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  531. || $courses_of_user[$course['code']]['status'] == '1'
  532. || api_is_platform_admin()
  533. ) {
  534. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  535. }
  536. $courses_list_string .= $course['title'];
  537. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  538. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  539. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  540. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  541. || $courses_of_user[$course['code']]['status'] == '1'
  542. || api_is_platform_admin()
  543. ) {
  544. $courses_list_string .= '</a><br />';
  545. }
  546. $course_details = [];
  547. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  548. $course_details[] = '('.$course['visual_code'].')';
  549. }
  550. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  551. if (!empty($course['tutor_name'])) {
  552. $course_details[] = $course['tutor_name'];
  553. }
  554. }
  555. if (api_get_setting('show_different_course_language') == 'true' &&
  556. $course['course_language'] != api_get_setting('platformLanguage')
  557. ) {
  558. $course_details[] = $course['course_language'];
  559. }
  560. $courses_list_string .= implode(' - ', $course_details);
  561. // We display a subscription link if:
  562. // 1. it is allowed to register for the course and if the course is not already in
  563. // the courselist of the user and if the user is identified
  564. // 2.
  565. if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
  566. if ($course['subscribe'] == '1') {
  567. $courses_list_string .= '&nbsp;<a class="btn btn-primary" href="main/auth/courses.php?action=subscribe_course&sec_token='.$stok.'&subscribe_course='.$course['code'].'&category_code='.Security::remove_XSS(
  568. $_GET['category']
  569. ).'">'.get_lang('Subscribe').'</a><br />';
  570. } else {
  571. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  572. }
  573. }
  574. $courses_list_string .= "</li>";
  575. } //end else
  576. } // end foreach
  577. $courses_list_string .= "</ul>";
  578. }
  579. if ($courses_shown > 0) {
  580. // Only display the list of courses and categories if there was more than
  581. // 0 courses visible to the world (we're in the anonymous list here).
  582. $result .= $courses_list_string;
  583. }
  584. if ($category != '') {
  585. $result .= '<p><a href="'.api_get_self().'">'
  586. .Display:: return_icon('back.png', get_lang('BackToHomePage'))
  587. .get_lang('BackToHomePage').'</a></p>';
  588. }
  589. return $result;
  590. }
  591. /**
  592. * retrieves all the courses that the user has already subscribed to.
  593. *
  594. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  595. *
  596. * @param int $user_id : the id of the user
  597. *
  598. * @return array an array containing all the information of the courses of the given user
  599. */
  600. public function get_courses_of_user($user_id)
  601. {
  602. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  603. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  604. // Secondly we select the courses that are in a category (user_course_cat <> 0)
  605. // and sort these according to the sort of the category
  606. $user_id = intval($user_id);
  607. $sql = "SELECT
  608. course.code k,
  609. course.visual_code vc,
  610. course.subscribe subscr,
  611. course.unsubscribe unsubscr,
  612. course.title i,
  613. course.tutor_name t,
  614. course.directory dir,
  615. course_rel_user.status status,
  616. course_rel_user.sort sort,
  617. course_rel_user.user_course_cat user_course_cat
  618. FROM
  619. $table_course course,
  620. $table_course_user course_rel_user
  621. WHERE
  622. course.id = course_rel_user.c_id AND
  623. course_rel_user.user_id = '".$user_id."' AND
  624. course_rel_user.relation_type <> ".COURSE_RELATION_TYPE_RRHH."
  625. ORDER BY course_rel_user.sort ASC";
  626. $result = Database::query($sql);
  627. $courses = [];
  628. while ($row = Database::fetch_array($result)) {
  629. // We only need the database name of the course.
  630. $courses[$row['k']] = [
  631. 'code' => $row['k'],
  632. 'visual_code' => $row['vc'],
  633. 'title' => $row['i'],
  634. 'directory' => $row['dir'],
  635. 'status' => $row['status'],
  636. 'tutor' => $row['t'],
  637. 'subscribe' => $row['subscr'],
  638. 'unsubscribe' => $row['unsubscr'],
  639. 'sort' => $row['sort'],
  640. 'user_course_category' => $row['user_course_cat'],
  641. ];
  642. }
  643. return $courses;
  644. }
  645. /**
  646. * @todo use the template system
  647. *
  648. * @param $title
  649. * @param $content
  650. * @param string $id
  651. * @param array $params
  652. * @param string $idAccordion
  653. * @param string $idCollapse
  654. *
  655. * @return string
  656. */
  657. public function showRightBlock(
  658. $title,
  659. $content,
  660. $id = '',
  661. $params = [],
  662. $idAccordion = '',
  663. $idCollapse = ''
  664. ) {
  665. $html = '';
  666. if (!empty($idAccordion)) {
  667. $html .= '<div class="panel-group" id="'.$idAccordion.'" role="tablist" aria-multiselectable="true">';
  668. $html .= '<div class="panel panel-default" id="'.$id.'">';
  669. $html .= '<div class="panel-heading" role="tab"><h4 class="panel-title">';
  670. $html .= '<a role="button" data-toggle="collapse" data-parent="#'.$idAccordion.'" href="#'.$idCollapse.'" aria-expanded="true" aria-controls="'.$idCollapse.'">'.$title.'</a>';
  671. $html .= '</h4></div>';
  672. $html .= '<div id="'.$idCollapse.'" class="panel-collapse collapse in" role="tabpanel">';
  673. $html .= '<div class="panel-body">'.$content.'</div>';
  674. $html .= '</div></div></div>';
  675. } else {
  676. if (!empty($id)) {
  677. $params['id'] = $id;
  678. }
  679. $params['class'] = 'panel panel-default';
  680. $html = null;
  681. if (!empty($title)) {
  682. $html .= '<div class="panel-heading">'.$title.'</div>';
  683. }
  684. $html .= '<div class="panel-body">'.$content.'</div>';
  685. $html = Display::div($html, $params);
  686. }
  687. return $html;
  688. }
  689. /**
  690. * Adds a form to let users login.
  691. *
  692. * @version 1.1
  693. */
  694. public function display_login_form()
  695. {
  696. return $this->tpl->displayLoginForm();
  697. }
  698. /**
  699. * @todo use FormValidator
  700. *
  701. * @return string
  702. */
  703. public function return_search_block()
  704. {
  705. $html = '';
  706. if (api_get_setting('search_enabled') == 'true') {
  707. $search_btn = get_lang('Search');
  708. $search_content = '<form action="main/search/" method="post">
  709. <div class="form-group">
  710. <input type="text" id="query" class="form-control" name="query" value="" />
  711. <button class="btn btn-default" type="submit" name="submit" value="'.$search_btn.'" />'.
  712. $search_btn.' </button>
  713. </div></form>';
  714. $html .= $this->showRightBlock(get_lang('Search'), $search_content, 'search_block');
  715. }
  716. return $html;
  717. }
  718. /**
  719. * @return string
  720. */
  721. public function returnClassesBlock()
  722. {
  723. if (api_get_setting('show_groups_to_users') !== 'true') {
  724. return '';
  725. }
  726. $items = [];
  727. $usergroup = new UserGroup();
  728. if (api_is_platform_admin()) {
  729. $items[] = [
  730. 'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add',
  731. 'title' => get_lang('AddClasses'),
  732. ];
  733. } else {
  734. if (api_is_teacher() && $usergroup->allowTeachers()) {
  735. $items[] = [
  736. 'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php',
  737. 'title' => get_lang('ClassList'),
  738. ];
  739. }
  740. }
  741. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  742. if (!empty($usergroup_list)) {
  743. foreach ($usergroup_list as $group_id) {
  744. $data = $usergroup->get($group_id);
  745. $items[] = [
  746. 'link' => api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id'],
  747. 'title' => $data['name'],
  748. ];
  749. }
  750. }
  751. $html = $this->showRightBlock(
  752. get_lang('Classes'),
  753. self::returnRightBlockItems($items),
  754. 'classes_block'
  755. );
  756. return $html;
  757. }
  758. /**
  759. * @return string
  760. */
  761. public function return_user_image_block()
  762. {
  763. $html = '';
  764. if (!api_is_anonymous()) {
  765. $userPicture = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
  766. $content = null;
  767. if (api_get_setting('allow_social_tool') == 'true') {
  768. $content .= '<a style="text-align:center" href="'.api_get_path(WEB_PATH).'main/social/home.php">
  769. <img class="img-circle" src="'.$userPicture.'"></a>';
  770. } else {
  771. $content .= '<a style="text-align:center" href="'.api_get_path(WEB_PATH).'main/auth/profile.php">
  772. <img class="img-circle" title="'.get_lang('EditProfile').'" src="'.$userPicture.'"></a>';
  773. }
  774. $html = $this->showRightBlock(
  775. null,
  776. $content,
  777. 'user_image_block',
  778. ['style' => 'text-align:center;']
  779. );
  780. }
  781. return $html;
  782. }
  783. /**
  784. * @return array
  785. */
  786. public function return_profile_block()
  787. {
  788. $userInfo = api_get_user_info();
  789. $userId = api_get_user_id();
  790. if (empty($userId)) {
  791. return;
  792. }
  793. $items = [];
  794. $userGroup = new UserGroup();
  795. // @todo Add a platform setting to add the user image.
  796. if (api_get_setting('allow_message_tool') === 'true') {
  797. // New messages.
  798. $number_of_new_messages = MessageManager::getCountNewMessages();
  799. // New contact invitations.
  800. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(
  801. $userId
  802. );
  803. // New group invitations sent by a moderator.
  804. $group_pending_invitations = $userGroup->get_groups_by_user(
  805. $userId,
  806. GROUP_USER_PERMISSION_PENDING_INVITATION,
  807. false
  808. );
  809. $group_pending_invitations = count($group_pending_invitations);
  810. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  811. $cant_msg = Display::badge($number_of_new_messages);
  812. $items[] = [
  813. 'class' => 'inbox-message-social',
  814. 'icon' => Display::return_icon('inbox.png', get_lang('Inbox')),
  815. 'link' => api_get_path(WEB_PATH).'main/messages/inbox.php',
  816. 'title' => get_lang('Inbox').$cant_msg,
  817. ];
  818. $items[] = [
  819. 'class' => 'new-message-social',
  820. 'icon' => Display::return_icon('new-message.png', get_lang('Compose')),
  821. 'link' => api_get_path(WEB_PATH).'main/messages/new_message.php',
  822. 'title' => get_lang('Compose'),
  823. ];
  824. if (api_get_setting('allow_social_tool') == 'true') {
  825. $total_invitations = Display::badge($total_invitations);
  826. $items[] = [
  827. 'class' => 'invitations-social',
  828. 'icon' => Display::return_icon('invitations.png', get_lang('PendingInvitations')),
  829. 'link' => api_get_path(WEB_PATH).'main/social/invitations.php',
  830. 'title' => get_lang('PendingInvitations').$total_invitations,
  831. ];
  832. } else {
  833. $items[] = [
  834. 'class' => 'personal-data',
  835. 'icon' => Display::return_icon('database.png', get_lang('PersonalDataReport')),
  836. 'link' => api_get_path(WEB_CODE_PATH).'social/personal_data.php',
  837. 'title' => get_lang('PersonalDataReport'),
  838. ];
  839. }
  840. if (api_get_configuration_value('allow_my_files_link_in_homepage')) {
  841. if (api_get_setting('allow_my_files') !== 'false') {
  842. $items[] = [
  843. 'class' => 'myfiles-social',
  844. 'icon' => Display::return_icon('sn-files.png', get_lang('Files')),
  845. 'link' => api_get_path(WEB_PATH).'main/social/myfiles.php',
  846. 'title' => get_lang('MyFiles'),
  847. ];
  848. }
  849. }
  850. }
  851. $items[] = [
  852. 'class' => 'profile-social',
  853. 'icon' => Display::return_icon('edit-profile.png', get_lang('EditProfile')),
  854. 'link' => Display::getProfileEditionLink($userId),
  855. 'title' => get_lang('EditProfile'),
  856. ];
  857. if (api_get_configuration_value('show_link_request_hrm_user') &&
  858. api_is_drh()
  859. ) {
  860. $label = get_lang('RequestLinkingToUser');
  861. $items[] = [
  862. 'icon' => Display::return_icon('new_group.png', $label),
  863. 'link' => api_get_path(WEB_CODE_PATH).'social/require_user_linking.php',
  864. 'title' => $label,
  865. ];
  866. }
  867. if (bbb::showGlobalConferenceLink($userInfo)) {
  868. $bbb = new bbb('', '', true, api_get_user_id());
  869. $url = $bbb->getListingUrl();
  870. $items[] = [
  871. 'class' => 'video-conference',
  872. 'icon' => Display::return_icon(
  873. 'bbb.png',
  874. get_lang('VideoConference')
  875. ),
  876. 'link' => $url,
  877. 'title' => get_lang('VideoConference'),
  878. ];
  879. }
  880. if (true === api_get_configuration_value('whispeak_auth_enabled')) {
  881. $itemTitle = WhispeakAuthPlugin::create()->get_title();
  882. $items[] = [
  883. 'class' => 'whispeak-enrollment',
  884. 'icon' => Display::return_icon('addworkuser.png', $itemTitle),
  885. 'link' => WhispeakAuthPlugin::getEnrollmentUrl(),
  886. 'title' => $itemTitle,
  887. ];
  888. }
  889. return $items;
  890. }
  891. /**
  892. * @return array
  893. */
  894. public function return_navigation_links()
  895. {
  896. $items = [];
  897. // Deleting the myprofile link.
  898. if (api_get_setting('allow_social_tool') == 'true') {
  899. unset($this->tpl->menu_navigation['myprofile']);
  900. }
  901. $hideMenu = api_get_configuration_value('hide_main_navigation_menu');
  902. if ($hideMenu === true) {
  903. return '';
  904. }
  905. // Main navigation section.
  906. // Tabs that are deactivated are added here.
  907. if (!empty($this->tpl->menu_navigation)) {
  908. foreach ($this->tpl->menu_navigation as $section => $navigation_info) {
  909. $items[] = [
  910. 'icon' => null,
  911. 'link' => $navigation_info['url'],
  912. 'title' => $navigation_info['title'],
  913. ];
  914. }
  915. }
  916. return $items;
  917. }
  918. /**
  919. * @return array
  920. */
  921. public function return_course_block()
  922. {
  923. $isHrm = api_is_drh();
  924. $show_create_link = false;
  925. $show_course_link = false;
  926. if (api_is_allowed_to_create_course()) {
  927. $show_create_link = true;
  928. }
  929. if (api_get_setting('allow_students_to_browse_courses') === 'true') {
  930. $show_course_link = true;
  931. }
  932. $items = [];
  933. // My account section
  934. if ($show_create_link) {
  935. if (api_get_setting('course_validation') == 'true' && !api_is_platform_admin()) {
  936. $items[] = [
  937. 'class' => 'add-course',
  938. 'icon' => Display::return_icon('new-course.png', get_lang('CreateCourseRequest')),
  939. 'link' => 'main/create_course/add_course.php',
  940. 'title' => get_lang('CreateCourseRequest'),
  941. ];
  942. } else {
  943. $items[] = [
  944. 'class' => 'add-course',
  945. 'icon' => Display::return_icon('new-course.png', get_lang('CourseCreate')),
  946. 'link' => 'main/create_course/add_course.php',
  947. 'title' => get_lang('CourseCreate'),
  948. ];
  949. }
  950. if (SessionManager::allowToManageSessions()) {
  951. $items[] = [
  952. 'class' => 'add-session',
  953. 'icon' => Display::return_icon('session.png', get_lang('AddSession')),
  954. 'link' => 'main/session/session_add.php',
  955. 'title' => get_lang('AddSession'),
  956. ];
  957. }
  958. }
  959. // Sort courses
  960. $items[] = [
  961. 'class' => 'order-course',
  962. 'icon' => Display::return_icon('order-course.png', get_lang('SortMyCourses')),
  963. 'link' => api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses',
  964. 'title' => get_lang('SortMyCourses'),
  965. ];
  966. // Session history
  967. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  968. $items[] = [
  969. 'class' => 'history-course',
  970. 'icon' => Display::return_icon('history-course.png', get_lang('DisplayTrainingList')),
  971. 'link' => 'user_portal.php',
  972. 'title' => get_lang('DisplayTrainingList'),
  973. ];
  974. } else {
  975. $items[] = [
  976. 'class' => 'history-course',
  977. 'icon' => Display::return_icon('history-course.png', get_lang('HistoryTrainingSessions')),
  978. 'link' => 'user_portal.php?history=1',
  979. 'title' => get_lang('HistoryTrainingSessions'),
  980. ];
  981. }
  982. if ($isHrm) {
  983. $items[] = [
  984. 'link' => api_get_path(WEB_CODE_PATH).'auth/hrm_courses.php',
  985. 'title' => get_lang('HrmAssignedUsersCourseList'),
  986. ];
  987. }
  988. // Course catalog
  989. if ($show_course_link) {
  990. if (!api_is_drh()) {
  991. $items[] = [
  992. 'class' => 'list-course',
  993. 'icon' => Display::return_icon('catalog-course.png', get_lang('CourseCatalog')),
  994. 'link' => 'main/auth/courses.php',
  995. 'title' => get_lang('CourseCatalog'),
  996. ];
  997. } else {
  998. $items[] = [
  999. 'link' => 'main/dashboard/index.php',
  1000. 'title' => get_lang('Dashboard'),
  1001. ];
  1002. }
  1003. }
  1004. return $items;
  1005. }
  1006. /**
  1007. * Prints the session and course list (user_portal.php).
  1008. *
  1009. * @param int $user_id
  1010. * @param bool $showSessions
  1011. * @param string $categoryCodeFilter
  1012. * @param bool $useUserLanguageFilterIfAvailable
  1013. * @param bool $loadHistory
  1014. *
  1015. * @return array
  1016. */
  1017. public function returnCoursesAndSessions(
  1018. $user_id,
  1019. $showSessions = true,
  1020. $categoryCodeFilter = '',
  1021. $useUserLanguageFilterIfAvailable = true,
  1022. $loadHistory = false
  1023. ) {
  1024. $gameModeIsActive = api_get_setting('gamification_mode');
  1025. $viewGridCourses = api_get_configuration_value('view_grid_courses') === true;
  1026. $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info');
  1027. $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl';
  1028. $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl';
  1029. $showAllSessions = api_get_configuration_value('show_all_sessions_on_my_course_page') === true;
  1030. if ($loadHistory) {
  1031. // Load sessions in category in *history*
  1032. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1033. } else {
  1034. // Load sessions in category
  1035. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1036. }
  1037. $sessionCount = 0;
  1038. $courseCount = 0;
  1039. // Student info code check (shows student progress information on
  1040. // courses list
  1041. $studentInfo = api_get_configuration_value('course_student_info');
  1042. $viewGrid = api_get_configuration_value('view_grid_courses');
  1043. $studentInfoProgress = !empty($studentInfo['progress']) && $studentInfo['progress'] === true;
  1044. $studentInfoScore = !empty($studentInfo['score']) && $studentInfo['score'] === true;
  1045. $studentInfoCertificate = !empty($studentInfo['certificate']) && $studentInfo['certificate'] === true;
  1046. $courseCompleteList = [];
  1047. $coursesInCategoryCount = 0;
  1048. $coursesNotInCategoryCount = 0;
  1049. $listCourse = '';
  1050. $specialCourseList = '';
  1051. // If we're not in the history view...
  1052. if ($loadHistory == false) {
  1053. // Display special courses.
  1054. $specialCourses = CourseManager::returnSpecialCourses(
  1055. $user_id,
  1056. $this->load_directories_preview,
  1057. $useUserLanguageFilterIfAvailable
  1058. );
  1059. // Display courses.
  1060. $courses = CourseManager::returnCourses(
  1061. $user_id,
  1062. $this->load_directories_preview,
  1063. $useUserLanguageFilterIfAvailable
  1064. );
  1065. // Course option (show student progress)
  1066. // This code will add new variables (Progress, Score, Certificate)
  1067. if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) {
  1068. if (!empty($specialCourses)) {
  1069. foreach ($specialCourses as $key => $specialCourseInfo) {
  1070. if ($studentInfoProgress) {
  1071. $progress = Tracking::get_avg_student_progress(
  1072. $user_id,
  1073. $specialCourseInfo['course_code']
  1074. );
  1075. $specialCourses[$key]['student_info']['progress'] = $progress === false ? null : $progress;
  1076. }
  1077. if ($studentInfoScore) {
  1078. $percentage_score = Tracking::get_avg_student_score(
  1079. $user_id,
  1080. $specialCourseInfo['course_code'],
  1081. []
  1082. );
  1083. $specialCourses[$key]['student_info']['score'] = $percentage_score;
  1084. }
  1085. if ($studentInfoCertificate) {
  1086. $category = Category::load(
  1087. null,
  1088. null,
  1089. $specialCourseInfo['course_code'],
  1090. null,
  1091. null,
  1092. null
  1093. );
  1094. $specialCourses[$key]['student_info']['certificate'] = null;
  1095. if (isset($category[0])) {
  1096. if ($category[0]->is_certificate_available($user_id)) {
  1097. $specialCourses[$key]['student_info']['certificate'] = Display::label(
  1098. get_lang('Yes'),
  1099. 'success'
  1100. );
  1101. } else {
  1102. $specialCourses[$key]['student_info']['certificate'] = Display::label(
  1103. get_lang('No'),
  1104. 'danger'
  1105. );
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }
  1111. if (isset($courses['in_category'])) {
  1112. foreach ($courses['in_category'] as $key1 => $value) {
  1113. if (isset($courses['in_category'][$key1]['courses'])) {
  1114. foreach ($courses['in_category'][$key1]['courses'] as $key2 => $courseInCatInfo) {
  1115. if ($studentInfoProgress) {
  1116. $progress = Tracking::get_avg_student_progress(
  1117. $user_id,
  1118. $courseInCatInfo['course_code']
  1119. );
  1120. $courses['in_category'][$key1]['courses'][$key2]['student_info']['progress'] = $progress === false ? null : $progress;
  1121. }
  1122. if ($studentInfoScore) {
  1123. $percentage_score = Tracking::get_avg_student_score(
  1124. $user_id,
  1125. $specialCourseInfo['course_code'],
  1126. []
  1127. );
  1128. $courses['in_category'][$key1]['courses'][$key2]['student_info']['score'] = $percentage_score;
  1129. }
  1130. if ($studentInfoCertificate) {
  1131. $category = Category::load(
  1132. null,
  1133. null,
  1134. $courseInCatInfo['course_code'],
  1135. null,
  1136. null,
  1137. null
  1138. );
  1139. $courses['in_category'][$key1]['student_info']['certificate'] = null;
  1140. $isCertificateAvailable = $category[0]->is_certificate_available($user_id);
  1141. if (isset($category[0])) {
  1142. if ($viewGrid) {
  1143. if ($isCertificateAvailable) {
  1144. $courses['in_category'][$key1]['student_info']['certificate'] = get_lang(
  1145. 'Yes'
  1146. );
  1147. } else {
  1148. $courses['in_category'][$key1]['student_info']['certificate'] = get_lang(
  1149. 'No'
  1150. );
  1151. }
  1152. } else {
  1153. if ($isCertificateAvailable) {
  1154. $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
  1155. get_lang('Yes'),
  1156. 'success'
  1157. );
  1158. } else {
  1159. $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
  1160. get_lang('No'),
  1161. 'danger'
  1162. );
  1163. }
  1164. }
  1165. }
  1166. }
  1167. }
  1168. }
  1169. }
  1170. }
  1171. if (isset($courses['not_category'])) {
  1172. foreach ($courses['not_category'] as $key => $courseNotInCatInfo) {
  1173. if ($studentInfoProgress) {
  1174. $progress = Tracking::get_avg_student_progress(
  1175. $user_id,
  1176. $courseNotInCatInfo['course_code']
  1177. );
  1178. $courses['not_category'][$key]['student_info']['progress'] = $progress === false ? null : $progress;
  1179. }
  1180. if ($studentInfoScore) {
  1181. $percentage_score = Tracking::get_avg_student_score(
  1182. $user_id,
  1183. $courseNotInCatInfo['course_code'],
  1184. []
  1185. );
  1186. $courses['not_category'][$key]['student_info']['score'] = $percentage_score;
  1187. }
  1188. if ($studentInfoCertificate) {
  1189. $category = Category::load(
  1190. null,
  1191. null,
  1192. $courseNotInCatInfo['course_code'],
  1193. null,
  1194. null,
  1195. null
  1196. );
  1197. $courses['not_category'][$key]['student_info']['certificate'] = null;
  1198. if (isset($category[0])) {
  1199. $certificateAvailable = $category[0]->is_certificate_available($user_id);
  1200. if ($viewGrid) {
  1201. if ($certificateAvailable) {
  1202. $courses['not_category'][$key]['student_info']['certificate'] = get_lang('Yes');
  1203. } else {
  1204. $courses['not_category'][$key]['student_info']['certificate'] = get_lang('No');
  1205. }
  1206. } else {
  1207. if ($certificateAvailable) {
  1208. $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
  1209. get_lang('Yes'),
  1210. 'success'
  1211. );
  1212. } else {
  1213. $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
  1214. get_lang('No'),
  1215. 'danger'
  1216. );
  1217. }
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }
  1223. }
  1224. if ($viewGridCourses) {
  1225. $coursesWithoutCategoryTemplate = '/user_portal/grid_courses_without_category.tpl';
  1226. $coursesWithCategoryTemplate = '/user_portal/grid_courses_with_category.tpl';
  1227. }
  1228. if ($specialCourses) {
  1229. if ($categoryCodeFilter) {
  1230. $specialCourses = self::filterByCategory($specialCourses, $categoryCodeFilter);
  1231. }
  1232. $this->tpl->assign('courses', $specialCourses);
  1233. $specialCourseList = $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate));
  1234. $courseCompleteList = array_merge($courseCompleteList, $specialCourses);
  1235. }
  1236. if ($courses['in_category'] || $courses['not_category']) {
  1237. foreach ($courses['in_category'] as $courseData) {
  1238. if (!empty($courseData['courses'])) {
  1239. $coursesInCategoryCount += count($courseData['courses']);
  1240. $courseCompleteList = array_merge($courseCompleteList, $courseData['courses']);
  1241. }
  1242. }
  1243. $coursesNotInCategoryCount += count($courses['not_category']);
  1244. $courseCompleteList = array_merge($courseCompleteList, $courses['not_category']);
  1245. if ($categoryCodeFilter) {
  1246. $courses['in_category'] = self::filterByCategory(
  1247. $courses['in_category'],
  1248. $categoryCodeFilter
  1249. );
  1250. $courses['not_category'] = self::filterByCategory(
  1251. $courses['not_category'],
  1252. $categoryCodeFilter
  1253. );
  1254. }
  1255. $this->tpl->assign('courses', $courses['not_category']);
  1256. $this->tpl->assign('categories', $courses['in_category']);
  1257. $listCourse = $this->tpl->fetch($this->tpl->get_template($coursesWithCategoryTemplate));
  1258. $listCourse .= $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate));
  1259. }
  1260. $courseCount = count($specialCourses) + $coursesInCategoryCount + $coursesNotInCategoryCount;
  1261. }
  1262. $sessions_with_category = '';
  1263. $sessions_with_no_category = '';
  1264. $collapsable = api_get_configuration_value('allow_user_session_collapsable');
  1265. $collapsableLink = '';
  1266. if ($collapsable) {
  1267. $collapsableLink = api_get_path(WEB_PATH).'user_portal.php?action=collapse_session';
  1268. }
  1269. $extraFieldValue = new ExtraFieldValue('session');
  1270. if ($showSessions) {
  1271. $coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link');
  1272. $coursesListSessionStyle = $coursesListSessionStyle === false ? 1 : $coursesListSessionStyle;
  1273. if (api_is_drh()) {
  1274. $coursesListSessionStyle = 1;
  1275. }
  1276. $portalShowDescription = api_get_setting('show_session_description') === 'true';
  1277. // Declared listSession variable
  1278. $listSession = [];
  1279. // Get timestamp in UTC to compare to DB values (in UTC by convention)
  1280. $session_now = strtotime(api_get_utc_datetime(time()));
  1281. if (is_array($session_categories)) {
  1282. foreach ($session_categories as $session_category) {
  1283. $session_category_id = $session_category['session_category']['id'];
  1284. // Sessions and courses that are not in a session category
  1285. if (empty($session_category_id) &&
  1286. isset($session_category['sessions'])
  1287. ) {
  1288. // Independent sessions
  1289. foreach ($session_category['sessions'] as $session) {
  1290. $session_id = $session['session_id'];
  1291. // Don't show empty sessions.
  1292. if (count($session['courses']) < 1) {
  1293. continue;
  1294. }
  1295. // Courses inside the current session.
  1296. $date_session_start = $session['access_start_date'];
  1297. $date_session_end = $session['access_end_date'];
  1298. $coachAccessStartDate = $session['coach_access_start_date'];
  1299. $coachAccessEndDate = $session['coach_access_end_date'];
  1300. $count_courses_session = 0;
  1301. // Loop course content
  1302. $html_courses_session = [];
  1303. $atLeastOneCourseIsVisible = false;
  1304. $markAsOld = false;
  1305. $markAsFuture = false;
  1306. foreach ($session['courses'] as $course) {
  1307. $is_coach_course = api_is_coach($session_id, $course['real_id']);
  1308. $allowed_time = 0;
  1309. $allowedEndTime = true;
  1310. if (!empty($date_session_start)) {
  1311. if ($is_coach_course) {
  1312. $allowed_time = api_strtotime($coachAccessStartDate);
  1313. } else {
  1314. $allowed_time = api_strtotime($date_session_start);
  1315. }
  1316. $endSessionToTms = null;
  1317. if (!isset($_GET['history'])) {
  1318. if (!empty($date_session_end)) {
  1319. if ($is_coach_course) {
  1320. // if coach end date is empty we use the default end date
  1321. if (empty($coachAccessEndDate)) {
  1322. $endSessionToTms = api_strtotime($date_session_end);
  1323. if ($session_now > $endSessionToTms) {
  1324. $allowedEndTime = false;
  1325. }
  1326. } else {
  1327. $endSessionToTms = api_strtotime($coachAccessEndDate);
  1328. if ($session_now > $endSessionToTms) {
  1329. $allowedEndTime = false;
  1330. }
  1331. }
  1332. } else {
  1333. $endSessionToTms = api_strtotime($date_session_end);
  1334. if ($session_now > $endSessionToTms) {
  1335. $allowedEndTime = false;
  1336. }
  1337. }
  1338. }
  1339. }
  1340. }
  1341. if ($showAllSessions) {
  1342. if ($allowed_time < $session_now && $allowedEndTime === false) {
  1343. $markAsOld = true;
  1344. }
  1345. if ($allowed_time > $session_now && $endSessionToTms > $session_now) {
  1346. $markAsFuture = true;
  1347. }
  1348. $allowedEndTime = true;
  1349. $allowed_time = 0;
  1350. }
  1351. if ($session_now >= $allowed_time && $allowedEndTime) {
  1352. // Read only and accessible.
  1353. $atLeastOneCourseIsVisible = true;
  1354. if (api_get_setting('hide_courses_in_sessions') === 'false') {
  1355. $courseUserHtml = CourseManager::get_logged_user_course_html(
  1356. $course,
  1357. $session_id,
  1358. 'session_course_item',
  1359. true,
  1360. $this->load_directories_preview
  1361. );
  1362. if (isset($courseUserHtml[1])) {
  1363. $course_session = $courseUserHtml[1];
  1364. $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
  1365. // Course option (show student progress)
  1366. // This code will add new variables (Progress, Score, Certificate)
  1367. if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) {
  1368. if ($studentInfoProgress) {
  1369. $progress = Tracking::get_avg_student_progress(
  1370. $user_id,
  1371. $course['course_code'],
  1372. [],
  1373. $session_id
  1374. );
  1375. $course_session['student_info']['progress'] = $progress === false ? null : $progress;
  1376. }
  1377. if ($studentInfoScore) {
  1378. $percentage_score = Tracking::get_avg_student_score(
  1379. $user_id,
  1380. $course['course_code'],
  1381. [],
  1382. $session_id
  1383. );
  1384. $course_session['student_info']['score'] = $percentage_score;
  1385. }
  1386. if ($studentInfoCertificate) {
  1387. $category = Category::load(
  1388. null,
  1389. null,
  1390. $course['course_code'],
  1391. null,
  1392. null,
  1393. $session_id
  1394. );
  1395. $course_session['student_info']['certificate'] = null;
  1396. if (isset($category[0])) {
  1397. if ($category[0]->is_certificate_available($user_id)) {
  1398. $course_session['student_info']['certificate'] = Display::label(
  1399. get_lang('Yes'),
  1400. 'success'
  1401. );
  1402. } else {
  1403. $course_session['student_info']['certificate'] = Display::label(
  1404. get_lang('No')
  1405. );
  1406. }
  1407. }
  1408. }
  1409. }
  1410. $html_courses_session[] = $course_session;
  1411. }
  1412. }
  1413. $count_courses_session++;
  1414. }
  1415. }
  1416. // No courses to show.
  1417. if ($atLeastOneCourseIsVisible === false) {
  1418. if (empty($html_courses_session)) {
  1419. continue;
  1420. }
  1421. }
  1422. if ($count_courses_session > 0) {
  1423. $params = [
  1424. 'id' => $session_id,
  1425. ];
  1426. $session_box = Display::getSessionTitleBox($session_id);
  1427. $coachId = $session_box['id_coach'];
  1428. $imageField = $extraFieldValue->get_values_by_handler_and_field_variable(
  1429. $session_id,
  1430. 'image'
  1431. );
  1432. $params['category_id'] = $session_box['category_id'];
  1433. $params['title'] = $session_box['title'];
  1434. $params['id_coach'] = $coachId;
  1435. $params['coach_url'] = api_get_path(WEB_AJAX_PATH).
  1436. 'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId;
  1437. $params['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
  1438. $params['coach_avatar'] = UserManager::getUserPicture(
  1439. $coachId,
  1440. USER_IMAGE_SIZE_SMALL
  1441. );
  1442. $params['date'] = $session_box['dates'];
  1443. $params['image'] = isset($imageField['value']) ? $imageField['value'] : null;
  1444. $params['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
  1445. $params['show_actions'] = SessionManager::cantEditSession($session_id);
  1446. if ($collapsable) {
  1447. $collapsableData = Sessionmanager::getCollapsableData(
  1448. $user_id,
  1449. $session_id,
  1450. $extraFieldValue,
  1451. $collapsableLink
  1452. );
  1453. $params['collapsed'] = $collapsableData['collapsed'];
  1454. $params['collapsable_link'] = $collapsableData['collapsable_link'];
  1455. }
  1456. $params['show_description'] = $session_box['show_description'] == 1 && $portalShowDescription;
  1457. $params['description'] = $session_box['description'];
  1458. $params['visibility'] = $session_box['visibility'];
  1459. $params['show_simple_session_info'] = $showSimpleSessionInfo;
  1460. $params['course_list_session_style'] = $coursesListSessionStyle;
  1461. $params['num_users'] = $session_box['num_users'];
  1462. $params['num_courses'] = $session_box['num_courses'];
  1463. $params['course_categories'] = CourseManager::getCourseCategoriesFromCourseList(
  1464. $html_courses_session
  1465. );
  1466. $params['courses'] = $html_courses_session;
  1467. $params['is_old'] = $markAsOld;
  1468. $params['is_future'] = $markAsFuture;
  1469. if ($showSimpleSessionInfo) {
  1470. $params['subtitle'] = self::getSimpleSessionDetails(
  1471. $session_box['coach'],
  1472. $session_box['dates'],
  1473. isset($session_box['duration']) ? $session_box['duration'] : null
  1474. );
  1475. }
  1476. if ($gameModeIsActive) {
  1477. $params['stars'] = GamificationUtils::getSessionStars(
  1478. $params['id'],
  1479. $this->user_id
  1480. );
  1481. $params['progress'] = GamificationUtils::getSessionProgress(
  1482. $params['id'],
  1483. $this->user_id
  1484. );
  1485. $params['points'] = GamificationUtils::getSessionPoints(
  1486. $params['id'],
  1487. $this->user_id
  1488. );
  1489. }
  1490. $listSession[] = $params;
  1491. $sessionCount++;
  1492. }
  1493. }
  1494. } else {
  1495. // All sessions included in
  1496. $count_courses_session = 0;
  1497. $html_sessions = '';
  1498. if (isset($session_category['sessions'])) {
  1499. foreach ($session_category['sessions'] as $session) {
  1500. $session_id = $session['session_id'];
  1501. // Don't show empty sessions.
  1502. if (count($session['courses']) < 1) {
  1503. continue;
  1504. }
  1505. $date_session_start = $session['access_start_date'];
  1506. $date_session_end = $session['access_end_date'];
  1507. $coachAccessStartDate = $session['coach_access_start_date'];
  1508. $coachAccessEndDate = $session['coach_access_end_date'];
  1509. $html_courses_session = [];
  1510. $count = 0;
  1511. $markAsOld = false;
  1512. $markAsFuture = false;
  1513. foreach ($session['courses'] as $course) {
  1514. $is_coach_course = api_is_coach($session_id, $course['real_id']);
  1515. $allowed_time = 0;
  1516. $allowedEndTime = true;
  1517. if (!empty($date_session_start)) {
  1518. if ($is_coach_course) {
  1519. $allowed_time = api_strtotime($coachAccessStartDate);
  1520. } else {
  1521. $allowed_time = api_strtotime($date_session_start);
  1522. }
  1523. if (!isset($_GET['history'])) {
  1524. if (!empty($date_session_end)) {
  1525. if ($is_coach_course) {
  1526. // if coach end date is empty we use the default end date
  1527. if (empty($coachAccessEndDate)) {
  1528. $endSessionToTms = api_strtotime($date_session_end);
  1529. if ($session_now > $endSessionToTms) {
  1530. $allowedEndTime = false;
  1531. }
  1532. } else {
  1533. $endSessionToTms = api_strtotime($coachAccessEndDate);
  1534. if ($session_now > $endSessionToTms) {
  1535. $allowedEndTime = false;
  1536. }
  1537. }
  1538. } else {
  1539. $endSessionToTms = api_strtotime($date_session_end);
  1540. if ($session_now > $endSessionToTms) {
  1541. $allowedEndTime = false;
  1542. }
  1543. }
  1544. }
  1545. }
  1546. }
  1547. if ($showAllSessions) {
  1548. if ($allowed_time < $session_now && $allowedEndTime == false) {
  1549. $markAsOld = true;
  1550. }
  1551. if ($allowed_time > $session_now && $endSessionToTms > $session_now) {
  1552. $markAsFuture = true;
  1553. }
  1554. $allowedEndTime = true;
  1555. $allowed_time = 0;
  1556. }
  1557. if ($session_now >= $allowed_time && $allowedEndTime) {
  1558. if (api_get_setting('hide_courses_in_sessions') === 'false') {
  1559. $c = CourseManager::get_logged_user_course_html(
  1560. $course,
  1561. $session_id,
  1562. 'session_course_item'
  1563. );
  1564. if (isset($c[1])) {
  1565. $html_courses_session[] = $c[1];
  1566. }
  1567. }
  1568. $count_courses_session++;
  1569. $count++;
  1570. }
  1571. }
  1572. $sessionParams = [];
  1573. // Category
  1574. if ($count > 0) {
  1575. $session_box = Display::getSessionTitleBox($session_id);
  1576. $sessionParams[0]['id'] = $session_id;
  1577. $sessionParams[0]['date'] = $session_box['dates'];
  1578. $sessionParams[0]['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
  1579. $sessionParams[0]['course_list_session_style'] = $coursesListSessionStyle;
  1580. $sessionParams[0]['title'] = $session_box['title'];
  1581. $sessionParams[0]['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
  1582. $sessionParams[0]['show_actions'] = SessionManager::cantEditSession($session_id);
  1583. $sessionParams[0]['courses'] = $html_courses_session;
  1584. $sessionParams[0]['show_simple_session_info'] = $showSimpleSessionInfo;
  1585. $sessionParams[0]['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
  1586. $sessionParams[0]['is_old'] = $markAsOld;
  1587. $sessionParams[0]['is_future'] = $markAsFuture;
  1588. if ($collapsable) {
  1589. $collapsableData = Sessionmanager::getCollapsableData(
  1590. $user_id,
  1591. $session_id,
  1592. $extraFieldValue,
  1593. $collapsableLink
  1594. );
  1595. $sessionParams[0]['collapsable_link'] = $collapsableData['collapsable_link'];
  1596. $sessionParams[0]['collapsed'] = $collapsableData['collapsed'];
  1597. }
  1598. if ($showSimpleSessionInfo) {
  1599. $sessionParams[0]['subtitle'] = self::getSimpleSessionDetails(
  1600. $session_box['coach'],
  1601. $session_box['dates'],
  1602. isset($session_box['duration']) ? $session_box['duration'] : null
  1603. );
  1604. }
  1605. $this->tpl->assign('session', $sessionParams);
  1606. if ($viewGridCourses) {
  1607. $html_sessions .= $this->tpl->fetch(
  1608. $this->tpl->get_template('/user_portal/grid_session.tpl')
  1609. );
  1610. } else {
  1611. $html_sessions .= $this->tpl->fetch(
  1612. $this->tpl->get_template('user_portal/classic_session.tpl')
  1613. );
  1614. }
  1615. $sessionCount++;
  1616. }
  1617. }
  1618. }
  1619. if ($count_courses_session > 0) {
  1620. $categoryParams = [
  1621. 'id' => $session_category['session_category']['id'],
  1622. 'title' => $session_category['session_category']['name'],
  1623. 'show_actions' => api_is_platform_admin(),
  1624. 'subtitle' => '',
  1625. 'sessions' => $html_sessions,
  1626. ];
  1627. $session_category_start_date = $session_category['session_category']['date_start'];
  1628. $session_category_end_date = $session_category['session_category']['date_end'];
  1629. if ($session_category_start_date == '0000-00-00') {
  1630. $session_category_start_date = '';
  1631. }
  1632. if ($session_category_end_date == '0000-00-00') {
  1633. $session_category_end_date = '';
  1634. }
  1635. if (!empty($session_category_start_date) &&
  1636. !empty($session_category_end_date)
  1637. ) {
  1638. $categoryParams['subtitle'] = sprintf(
  1639. get_lang('FromDateXToDateY'),
  1640. $session_category_start_date,
  1641. $session_category_end_date
  1642. );
  1643. } else {
  1644. if (!empty($session_category_start_date)) {
  1645. $categoryParams['subtitle'] = get_lang('From').' '.$session_category_start_date;
  1646. }
  1647. if (!empty($session_category_end_date)) {
  1648. $categoryParams['subtitle'] = get_lang('Until').' '.$session_category_end_date;
  1649. }
  1650. }
  1651. $this->tpl->assign('session_category', $categoryParams);
  1652. $sessions_with_category .= $this->tpl->fetch(
  1653. $this->tpl->get_template('user_portal/session_category.tpl')
  1654. );
  1655. }
  1656. }
  1657. }
  1658. $allCoursesInSessions = [];
  1659. foreach ($listSession as $currentSession) {
  1660. $coursesInSessions = $currentSession['courses'];
  1661. unset($currentSession['courses']);
  1662. foreach ($coursesInSessions as $coursesInSession) {
  1663. $coursesInSession['session'] = $currentSession;
  1664. $allCoursesInSessions[] = $coursesInSession;
  1665. }
  1666. }
  1667. $this->tpl->assign('all_courses', $allCoursesInSessions);
  1668. $this->tpl->assign('session', $listSession);
  1669. $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false));
  1670. $this->tpl->assign('gamification_mode', $gameModeIsActive);
  1671. $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url'));
  1672. if ($viewGridCourses) {
  1673. $sessions_with_no_category = $this->tpl->fetch(
  1674. $this->tpl->get_template('/user_portal/grid_session.tpl')
  1675. );
  1676. } else {
  1677. $sessions_with_no_category = $this->tpl->fetch(
  1678. $this->tpl->get_template('user_portal/classic_session.tpl')
  1679. );
  1680. }
  1681. }
  1682. }
  1683. return [
  1684. 'courses' => $courseCompleteList,
  1685. 'sessions' => $session_categories,
  1686. 'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse),
  1687. 'session_count' => $sessionCount,
  1688. 'course_count' => $courseCount,
  1689. ];
  1690. }
  1691. /**
  1692. * Shows a welcome message when the user doesn't have any content in the course list.
  1693. */
  1694. public function return_welcome_to_course_block()
  1695. {
  1696. $count_courses = CourseManager::count_courses();
  1697. $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
  1698. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  1699. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  1700. $this->tpl->assign('course_catalog_url', $course_catalog_url);
  1701. $this->tpl->assign('course_list_url', $course_list_url);
  1702. $this->tpl->assign('course_catalog_link', Display::url(get_lang('Here'), $course_catalog_url));
  1703. $this->tpl->assign('course_list_link', Display::url(get_lang('Here'), $course_list_url));
  1704. $this->tpl->assign('count_courses', $count_courses);
  1705. return $this->tpl->fetch($tpl);
  1706. }
  1707. /**
  1708. * @return array
  1709. */
  1710. public function return_hot_courses()
  1711. {
  1712. return CourseManager::return_hot_courses(30, 6);
  1713. }
  1714. /**
  1715. * UserPortal view for session, return the HTML of the course list.
  1716. *
  1717. * @param $user_id
  1718. *
  1719. * @return string
  1720. */
  1721. public function returnCoursesAndSessionsViewBySession($user_id)
  1722. {
  1723. $sessionCount = 0;
  1724. $courseCount = 0;
  1725. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  1726. if ($load_history) {
  1727. // Load sessions in category in *history*
  1728. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1729. } else {
  1730. // Load sessions in category
  1731. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1732. }
  1733. $html = '';
  1734. $loadDirs = $this->load_directories_preview;
  1735. // If we're not in the history view...
  1736. $listCoursesInfo = [];
  1737. if (!isset($_GET['history'])) {
  1738. // Display special courses
  1739. $specialCoursesResult = CourseManager::returnSpecialCourses(
  1740. $user_id,
  1741. $loadDirs
  1742. );
  1743. $specialCourses = $specialCoursesResult;
  1744. if ($specialCourses) {
  1745. $this->tpl->assign('courses', $specialCourses);
  1746. $html = $this->tpl->fetch(
  1747. $this->tpl->get_template('/user_portal/classic_courses_without_category.tpl')
  1748. );
  1749. }
  1750. // Display courses
  1751. // [code=>xxx, real_id=>000]
  1752. $listCourses = CourseManager::get_courses_list_by_user_id(
  1753. $user_id,
  1754. false
  1755. );
  1756. foreach ($listCourses as $i => $listCourseCodeId) {
  1757. if (isset($listCourseCodeId['special_course'])) {
  1758. continue;
  1759. }
  1760. $courseCategory = CourseManager::getUserCourseCategoryForCourse(
  1761. $user_id,
  1762. $listCourseCodeId['real_id']
  1763. );
  1764. $userCatTitle = '';
  1765. $userCategoryId = 0;
  1766. if ($courseCategory) {
  1767. $userCategoryId = $courseCategory['user_course_cat'];
  1768. $userCatTitle = $courseCategory['title'];
  1769. }
  1770. $listCourse = api_get_course_info_by_id($listCourseCodeId['real_id']);
  1771. $listCoursesInfo[] = [
  1772. 'course' => $listCourse,
  1773. 'code' => $listCourseCodeId['code'],
  1774. 'id' => $listCourseCodeId['real_id'],
  1775. 'title' => $listCourse['title'],
  1776. 'userCatId' => $userCategoryId,
  1777. 'userCatTitle' => $userCatTitle,
  1778. ];
  1779. $courseCount++;
  1780. }
  1781. usort($listCoursesInfo, 'self::compareByCourse');
  1782. }
  1783. $listCoursesInSession = [];
  1784. if (is_array($session_categories)) {
  1785. // all courses that are in a session
  1786. $listCoursesInSession = SessionManager::getNamedSessionCourseForCoach($user_id);
  1787. }
  1788. // we got all courses
  1789. // for each user category, sorted alphabetically, display courses
  1790. $listUserCategories = CourseManager::get_user_course_categories($user_id);
  1791. $listCoursesAlreadyDisplayed = [];
  1792. uasort($listUserCategories, "self::compareListUserCategory");
  1793. $listUserCategories[0] = '';
  1794. $html .= '<div class="session-view-block">';
  1795. foreach ($listUserCategories as $userCategoryId => $userCat) {
  1796. // add user category
  1797. $userCategoryHtml = '';
  1798. if ($userCategoryId != 0) {
  1799. $userCategoryHtml = '<div class="session-view-well ">';
  1800. $userCategoryHtml .= self::getHtmlForUserCategory($userCategoryId, $userCat['title']);
  1801. }
  1802. // look for course in this userCat in session courses : $listCoursesInSession
  1803. $htmlCategory = '';
  1804. if (isset($listCoursesInSession[$userCategoryId])) {
  1805. // list of courses in this user cat
  1806. foreach ($listCoursesInSession[$userCategoryId]['courseInUserCatList'] as $i => $listCourse) {
  1807. // add course
  1808. $listCoursesAlreadyDisplayed[$listCourse['courseId']] = 1;
  1809. if ($userCategoryId == 0) {
  1810. $htmlCategory .= '<div class="panel panel-default">';
  1811. } else {
  1812. $htmlCategory .= '<div class="panel panel-default">';
  1813. }
  1814. $htmlCategory .= '<div class="panel-body">';
  1815. $coursesInfo = $listCourse['course'];
  1816. $htmlCategory .= self::getHtmlForCourse(
  1817. $coursesInfo,
  1818. $userCategoryId,
  1819. 1,
  1820. $loadDirs
  1821. );
  1822. // list of session category
  1823. $htmlSessionCategory = '<div class="session-view-row" style="display:none;" id="courseblock-'.$coursesInfo['real_id'].'">';
  1824. foreach ($listCourse['sessionCatList'] as $listCategorySession) {
  1825. // add session category
  1826. $htmlSessionCategory .= self::getHtmlSessionCategory(
  1827. $listCategorySession['catSessionId'],
  1828. $listCategorySession['catSessionName']
  1829. );
  1830. // list of session
  1831. $htmlSession = ''; // start
  1832. foreach ($listCategorySession['sessionList'] as $listSession) {
  1833. // add session
  1834. $htmlSession .= '<div class="session-view-row">';
  1835. $htmlSession .= self::getHtmlForSession(
  1836. $listSession['sessionId'],
  1837. $listSession['sessionName'],
  1838. $listCategorySession['catSessionId'],
  1839. $coursesInfo
  1840. );
  1841. $htmlSession .= '</div>';
  1842. $sessionCount++;
  1843. }
  1844. $htmlSession .= ''; // end session block
  1845. $htmlSessionCategory .= $htmlSession;
  1846. }
  1847. $htmlSessionCategory .= '</div>'; // end session cat block
  1848. $htmlCategory .= $htmlSessionCategory.'</div></div>';
  1849. $htmlCategory .= ''; // end course block
  1850. }
  1851. $userCategoryHtml .= $htmlCategory;
  1852. }
  1853. // look for courses in this userCat in not in session courses : $listCoursesInfo
  1854. // if course not already added
  1855. $htmlCategory = '';
  1856. foreach ($listCoursesInfo as $i => $listCourse) {
  1857. if ($listCourse['userCatId'] == $userCategoryId &&
  1858. !isset($listCoursesAlreadyDisplayed[$listCourse['id']])
  1859. ) {
  1860. if ($userCategoryId != 0) {
  1861. $htmlCategory .= '<div class="panel panel-default">';
  1862. } else {
  1863. $htmlCategory .= '<div class="panel panel-default">';
  1864. }
  1865. $htmlCategory .= '<div class="panel-body">';
  1866. $htmlCategory .= self::getHtmlForCourse(
  1867. $listCourse['course'],
  1868. $userCategoryId,
  1869. 0,
  1870. $loadDirs
  1871. );
  1872. $htmlCategory .= '</div></div>';
  1873. }
  1874. }
  1875. $htmlCategory .= '';
  1876. $userCategoryHtml .= $htmlCategory; // end user cat block
  1877. if ($userCategoryId != 0) {
  1878. $userCategoryHtml .= '</div>';
  1879. }
  1880. $html .= $userCategoryHtml;
  1881. }
  1882. $html .= '</div>';
  1883. return [
  1884. 'html' => $html,
  1885. 'sessions' => $session_categories,
  1886. 'courses' => $listCoursesInfo,
  1887. 'session_count' => $sessionCount,
  1888. 'course_count' => $courseCount,
  1889. ];
  1890. }
  1891. /**
  1892. * @param $listA
  1893. * @param $listB
  1894. *
  1895. * @return int
  1896. */
  1897. public static function compareListUserCategory($listA, $listB)
  1898. {
  1899. if ($listA['title'] == $listB['title']) {
  1900. return 0;
  1901. }
  1902. if ($listA['title'] > $listB['title']) {
  1903. return 1;
  1904. }
  1905. return -1;
  1906. }
  1907. /**
  1908. * @param $view
  1909. * @param $userId
  1910. */
  1911. public static function setDefaultMyCourseView($view, $userId)
  1912. {
  1913. setcookie('defaultMyCourseView'.$userId, $view);
  1914. }
  1915. /**
  1916. * @param int $userId
  1917. *
  1918. * @return array
  1919. */
  1920. public function returnCourseCategoryListFromUser($userId)
  1921. {
  1922. $sessionCount = 0;
  1923. $courseList = CourseManager::get_courses_list_by_user_id($userId);
  1924. $categoryCodes = CourseManager::getCourseCategoriesFromCourseList($courseList);
  1925. $categories = [];
  1926. foreach ($categoryCodes as $categoryCode) {
  1927. $categories[] = CourseCategory::getCategory($categoryCode);
  1928. }
  1929. $template = new Template('', false, false, false, true, false, false);
  1930. $layout = $template->get_template('user_portal/course_categories.tpl');
  1931. $template->assign('course_categories', $categories);
  1932. return [
  1933. 'courses' => $courseList,
  1934. 'html' => $template->fetch($layout),
  1935. 'course_count' => count($courseList),
  1936. 'session_count' => $sessionCount,
  1937. ];
  1938. }
  1939. /**
  1940. * Set grade book dependency progress bar see BT#13099.
  1941. *
  1942. * @param $userId
  1943. *
  1944. * @return bool
  1945. */
  1946. public function setGradeBookDependencyBar($userId)
  1947. {
  1948. $allow = api_get_configuration_value('gradebook_dependency');
  1949. if (api_is_anonymous()) {
  1950. return false;
  1951. }
  1952. if ($allow) {
  1953. $courseAndSessions = $this->returnCoursesAndSessions(
  1954. $userId,
  1955. false,
  1956. '',
  1957. false,
  1958. false
  1959. );
  1960. $courseList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
  1961. $courseList = isset($courseList['courses']) ? $courseList['courses'] : [];
  1962. $mandatoryCourse = [];
  1963. if (!empty($courseList)) {
  1964. foreach ($courseList as $courseId) {
  1965. $courseInfo = api_get_course_info_by_id($courseId);
  1966. $mandatoryCourse[] = $courseInfo['code'];
  1967. }
  1968. }
  1969. // @todo improve calls of course info
  1970. $subscribedCourses = !empty($courseAndSessions['courses']) ? $courseAndSessions['courses'] : [];
  1971. $mainCategoryList = [];
  1972. foreach ($subscribedCourses as $courseInfo) {
  1973. $courseCode = $courseInfo['code'];
  1974. $categories = Category::load(null, null, $courseCode);
  1975. /** @var Category $category */
  1976. $category = !empty($categories[0]) ? $categories[0] : [];
  1977. if (!empty($category)) {
  1978. $mainCategoryList[] = $category;
  1979. }
  1980. }
  1981. $result20 = 0;
  1982. $result80 = 0;
  1983. $countCoursesPassedNoDependency = 0;
  1984. /** @var Category $category */
  1985. foreach ($mainCategoryList as $category) {
  1986. $userFinished = Category::userFinishedCourse(
  1987. $userId,
  1988. $category,
  1989. true
  1990. );
  1991. if ($userFinished) {
  1992. if (in_array($category->get_course_code(), $mandatoryCourse)) {
  1993. if ($result20 < 20) {
  1994. $result20 += 10;
  1995. }
  1996. } else {
  1997. $countCoursesPassedNoDependency++;
  1998. if ($result80 < 80) {
  1999. $result80 += 10;
  2000. }
  2001. }
  2002. }
  2003. }
  2004. $finalResult = $result20 + $result80;
  2005. $gradeBookList = api_get_configuration_value('gradebook_badge_sidebar');
  2006. $gradeBookList = isset($gradeBookList['gradebooks']) ? $gradeBookList['gradebooks'] : [];
  2007. $badgeList = [];
  2008. foreach ($gradeBookList as $id) {
  2009. $categories = Category::load($id);
  2010. /** @var Category $category */
  2011. $category = !empty($categories[0]) ? $categories[0] : [];
  2012. $badgeList[$id]['name'] = $category->get_name();
  2013. $badgeList[$id]['finished'] = false;
  2014. $badgeList[$id]['skills'] = [];
  2015. if (!empty($category)) {
  2016. $minToValidate = $category->getMinimumToValidate();
  2017. $dependencies = $category->getCourseListDependency();
  2018. $gradeBooksToValidateInDependence = $category->getGradeBooksToValidateInDependence();
  2019. $countDependenciesPassed = 0;
  2020. foreach ($dependencies as $courseId) {
  2021. $courseInfo = api_get_course_info_by_id($courseId);
  2022. $courseCode = $courseInfo['code'];
  2023. $categories = Category::load(null, null, $courseCode);
  2024. $subCategory = !empty($categories[0]) ? $categories[0] : null;
  2025. if (!empty($subCategory)) {
  2026. $score = Category::userFinishedCourse(
  2027. $userId,
  2028. $subCategory,
  2029. true
  2030. );
  2031. if ($score) {
  2032. $countDependenciesPassed++;
  2033. }
  2034. }
  2035. }
  2036. $userFinished =
  2037. $countDependenciesPassed >= $gradeBooksToValidateInDependence &&
  2038. $countCoursesPassedNoDependency >= $minToValidate;
  2039. if ($userFinished) {
  2040. $badgeList[$id]['finished'] = true;
  2041. }
  2042. $objSkill = new Skill();
  2043. $skills = $category->get_skills();
  2044. $skillList = [];
  2045. foreach ($skills as $skill) {
  2046. $skillList[] = $objSkill->get($skill['id']);
  2047. }
  2048. $badgeList[$id]['skills'] = $skillList;
  2049. }
  2050. }
  2051. $this->tpl->assign(
  2052. 'grade_book_sidebar',
  2053. true
  2054. );
  2055. $this->tpl->assign(
  2056. 'grade_book_progress',
  2057. $finalResult
  2058. );
  2059. $this->tpl->assign('grade_book_badge_list', $badgeList);
  2060. return true;
  2061. }
  2062. return false;
  2063. }
  2064. /**
  2065. * Generate the HTML code for items when displaying the right-side blocks.
  2066. *
  2067. * @param array $items
  2068. *
  2069. * @return string
  2070. */
  2071. private static function returnRightBlockItems(array $items)
  2072. {
  2073. $my_account_content = '';
  2074. foreach ($items as $item) {
  2075. if (empty($item['link']) && empty($item['title'])) {
  2076. continue;
  2077. }
  2078. $my_account_content .= '<li class="list-group-item '.(empty($item['class']) ? '' : $item['class']).'">'
  2079. .(empty($item['icon']) ? '' : '<span class="item-icon">'.$item['icon'].'</span>')
  2080. .'<a href="'.$item['link'].'">'.$item['title'].'</a>'
  2081. .'</li>';
  2082. }
  2083. return '<ul class="list-group">'.$my_account_content.'</ul>';
  2084. }
  2085. /**
  2086. * Return HTML code for personal user course category.
  2087. *
  2088. * @param $id
  2089. * @param $title
  2090. *
  2091. * @return string
  2092. */
  2093. private static function getHtmlForUserCategory($id, $title)
  2094. {
  2095. if ($id == 0) {
  2096. return '';
  2097. }
  2098. $icon = Display::return_icon(
  2099. 'folder_yellow.png',
  2100. $title,
  2101. ['class' => 'sessionView'],
  2102. ICON_SIZE_LARGE
  2103. );
  2104. return "<div class='session-view-user-category'>$icon<span>$title</span></div>";
  2105. }
  2106. /**
  2107. * return HTML code for course display in session view.
  2108. *
  2109. * @param array $courseInfo
  2110. * @param $userCategoryId
  2111. * @param bool $displayButton
  2112. * @param $loadDirs
  2113. *
  2114. * @return string
  2115. */
  2116. private static function getHtmlForCourse(
  2117. $courseInfo,
  2118. $userCategoryId,
  2119. $displayButton = false,
  2120. $loadDirs
  2121. ) {
  2122. if (empty($courseInfo)) {
  2123. return '';
  2124. }
  2125. $id = $courseInfo['real_id'];
  2126. $title = $courseInfo['title'];
  2127. $code = $courseInfo['code'];
  2128. $class = 'session-view-lvl-6';
  2129. if ($userCategoryId != 0 && !$displayButton) {
  2130. $class = 'session-view-lvl-7';
  2131. }
  2132. $class2 = 'session-view-lvl-6';
  2133. if ($displayButton || $userCategoryId != 0) {
  2134. $class2 = 'session-view-lvl-7';
  2135. }
  2136. $button = '';
  2137. if ($displayButton) {
  2138. $button = '<input id="session-view-button-'.intval(
  2139. $id
  2140. ).'" class="btn btn-default btn-sm" type="button" onclick="hideUnhide(\'courseblock-'.intval(
  2141. $id
  2142. ).'\', \'session-view-button-'.intval($id).'\', \'+\', \'-\')" value="+" />';
  2143. }
  2144. $icon = Display::return_icon(
  2145. 'blackboard.png',
  2146. $title,
  2147. ['class' => 'sessionView'],
  2148. ICON_SIZE_LARGE
  2149. );
  2150. $courseLink = $courseInfo['course_public_url'].'?id_session=0';
  2151. // get html course params
  2152. $courseParams = CourseManager::getCourseParamsForDisplay($id, $loadDirs);
  2153. $teachers = '';
  2154. $rightActions = '';
  2155. // teacher list
  2156. if (!empty($courseParams['teachers'])) {
  2157. $teachers = '<p class="'.$class2.' view-by-session-teachers">'.$courseParams['teachers'].'</p>';
  2158. }
  2159. // notification
  2160. if (!empty($courseParams['right_actions'])) {
  2161. $rightActions = '<div class="pull-right">'.$courseParams['right_actions'].'</div>';
  2162. }
  2163. $notifications = isset($courseParams['notifications']) ? $courseParams['notifications'] : '';
  2164. return "<div>
  2165. $button
  2166. <span class='$class'>$icon
  2167. <a class='sessionView' href='$courseLink'>$title</a>
  2168. </span>
  2169. $notifications
  2170. $rightActions
  2171. </div>
  2172. $teachers";
  2173. }
  2174. /**
  2175. * return HTML code for session category.
  2176. *
  2177. * @param $id
  2178. * @param $title
  2179. *
  2180. * @return string
  2181. */
  2182. private static function getHtmlSessionCategory($id, $title)
  2183. {
  2184. if ($id == 0) {
  2185. return '';
  2186. }
  2187. $icon = Display::return_icon(
  2188. 'folder_blue.png',
  2189. $title,
  2190. ['class' => 'sessionView'],
  2191. ICON_SIZE_LARGE
  2192. );
  2193. return "<div class='session-view-session-category'>
  2194. <span class='session-view-lvl-2'>
  2195. $icon
  2196. <span>$title</span>
  2197. </span>
  2198. </div>";
  2199. }
  2200. /**
  2201. * return HTML code for session.
  2202. *
  2203. * @param int $id session id
  2204. * @param string $title session title
  2205. * @param int $categorySessionId
  2206. * @param array $courseInfo
  2207. *
  2208. * @return string
  2209. */
  2210. private static function getHtmlForSession($id, $title, $categorySessionId, $courseInfo)
  2211. {
  2212. $html = '';
  2213. if ($categorySessionId == 0) {
  2214. $class1 = 'session-view-lvl-2'; // session
  2215. $class2 = 'session-view-lvl-4'; // got to course in session link
  2216. } else {
  2217. $class1 = 'session-view-lvl-3'; // session
  2218. $class2 = 'session-view-lvl-5'; // got to course in session link
  2219. }
  2220. $icon = Display::return_icon(
  2221. 'blackboard_blue.png',
  2222. $title,
  2223. ['class' => 'sessionView'],
  2224. ICON_SIZE_LARGE
  2225. );
  2226. $courseLink = $courseInfo['course_public_url'].'?id_session='.intval($id);
  2227. $html .= "<span class='$class1 session-view-session'>$icon$title</span>";
  2228. $html .= '<div class="'.$class2.' session-view-session-go-to-course-in-session">
  2229. <a class="" href="'.$courseLink.'">'.get_lang('GoToCourseInsideSession').'</a></div>';
  2230. return '<div>'.$html.'</div>';
  2231. }
  2232. /**
  2233. * @param $listA
  2234. * @param $listB
  2235. *
  2236. * @return int
  2237. */
  2238. private static function compareByCourse($listA, $listB)
  2239. {
  2240. if ($listA['userCatTitle'] == $listB['userCatTitle']) {
  2241. if ($listA['title'] == $listB['title']) {
  2242. return 0;
  2243. }
  2244. if ($listA['title'] > $listB['title']) {
  2245. return 1;
  2246. }
  2247. return -1;
  2248. }
  2249. if ($listA['userCatTitle'] > $listB['userCatTitle']) {
  2250. return 1;
  2251. }
  2252. return -1;
  2253. }
  2254. /**
  2255. * Get the session coach name, duration or dates
  2256. * when $_configuration['show_simple_session_info'] is enabled.
  2257. *
  2258. * @param string $coachName
  2259. * @param string $dates
  2260. * @param string|null $duration Optional
  2261. *
  2262. * @return string
  2263. */
  2264. private static function getSimpleSessionDetails($coachName, $dates, $duration = null)
  2265. {
  2266. $strDetails = [];
  2267. if (!empty($coachName)) {
  2268. $strDetails[] = $coachName;
  2269. }
  2270. $strDetails[] = !empty($duration) ? $duration : $dates;
  2271. return implode(' | ', $strDetails);
  2272. }
  2273. /**
  2274. * Filter the course list by category code.
  2275. *
  2276. * @param array $courseList course list
  2277. * @param string $categoryCode
  2278. *
  2279. * @return array
  2280. */
  2281. private static function filterByCategory($courseList, $categoryCode)
  2282. {
  2283. return array_filter(
  2284. $courseList,
  2285. function ($courseInfo) use ($categoryCode) {
  2286. if (isset($courseInfo['category_code']) &&
  2287. $courseInfo['category_code'] === $categoryCode
  2288. ) {
  2289. return true;
  2290. }
  2291. return false;
  2292. }
  2293. );
  2294. }
  2295. }