userportal.lib.php 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546
  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 string|null
  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. $htmlTitre = '';
  432. $htmlListCat = '';
  433. if (Database::num_rows($resCats) > 0) {
  434. $htmlListCat = Display::page_header(get_lang('CatList'));
  435. $htmlListCat .= '<ul>';
  436. while ($catLine = Database::fetch_array($resCats)) {
  437. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  438. if ($category_has_open_courses) {
  439. // The category contains courses accessible to anonymous visitors.
  440. $htmlListCat .= '<li>';
  441. $htmlListCat .= '<a href="'.api_get_self(
  442. ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  443. if (api_get_setting('show_number_of_courses') == 'true') {
  444. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  445. }
  446. $htmlListCat .= "</li>";
  447. $thereIsSubCat = true;
  448. } elseif ($catLine['children_count'] > 0) {
  449. // The category has children, subcategories.
  450. $htmlListCat .= '<li>';
  451. $htmlListCat .= '<a href="'.api_get_self(
  452. ).'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  453. $htmlListCat .= "</li>";
  454. $thereIsSubCat = true;
  455. } elseif (api_get_setting('show_empty_course_categories') == 'true') {
  456. /* End changed code to eliminate the (0 courses) after empty categories. */
  457. $htmlListCat .= '<li>';
  458. $htmlListCat .= $catLine['name'];
  459. $htmlListCat .= "</li>";
  460. $thereIsSubCat = true;
  461. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  462. // TODO: deprecate this useless feature - this includes removing system variable
  463. if (empty($htmlTitre)) {
  464. $htmlTitre = '<p>';
  465. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  466. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  467. }
  468. $htmlTitre .= "</p>";
  469. }
  470. }
  471. $htmlListCat .= "</ul>";
  472. }
  473. $result .= $htmlTitre;
  474. if ($thereIsSubCat) {
  475. $result .= $htmlListCat;
  476. }
  477. while ($categoryName = Database::fetch_array($resCats)) {
  478. $result .= '<h3>'.$categoryName['name']."</h3>\n";
  479. }
  480. $courses_list_string = '';
  481. $courses_shown = 0;
  482. if ($numRows > 0) {
  483. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  484. $courses_list_string .= "<ul>";
  485. if (api_get_user_id()) {
  486. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  487. }
  488. foreach ($course_list as $course) {
  489. // $setting_show_also_closed_courses
  490. if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) {
  491. continue;
  492. }
  493. if (!$setting_show_also_closed_courses) {
  494. // If we do not show the closed courses
  495. // we only show the courses that are open to the world (to everybody)
  496. // and the courses that are open to the platform (if the current user is a registered user.
  497. if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) ||
  498. ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)
  499. ) {
  500. $courses_shown++;
  501. $courses_list_string .= "<li>";
  502. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  503. $course_details = [];
  504. if (api_get_setting('display_coursecode_in_courselist') === 'true') {
  505. $course_details[] = '('.$course['visual_code'].')';
  506. }
  507. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  508. $course_details[] = CourseManager::getTeacherListFromCourseCodeToString($course['code']);
  509. }
  510. if (api_get_setting('show_different_course_language') === 'true' &&
  511. $course['course_language'] != api_get_setting('platformLanguage')
  512. ) {
  513. $course_details[] = $course['course_language'];
  514. }
  515. $courses_list_string .= implode(' - ', $course_details);
  516. $courses_list_string .= "</li>";
  517. }
  518. } else {
  519. // We DO show the closed courses.
  520. // The course is accessible if (link to the course homepage):
  521. // 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);
  522. // 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);
  523. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  524. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  525. // 5. the user is the platform admin api_is_platform_admin().
  526. $courses_shown++;
  527. $courses_list_string .= "<li>";
  528. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  529. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  530. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  531. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  532. || $courses_of_user[$course['code']]['status'] == '1'
  533. || api_is_platform_admin()
  534. ) {
  535. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  536. }
  537. $courses_list_string .= $course['title'];
  538. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  539. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  540. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  541. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  542. || $courses_of_user[$course['code']]['status'] == '1'
  543. || api_is_platform_admin()
  544. ) {
  545. $courses_list_string .= '</a><br />';
  546. }
  547. $course_details = [];
  548. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  549. $course_details[] = '('.$course['visual_code'].')';
  550. }
  551. if (api_get_setting('display_teacher_in_courselist') === 'true') {
  552. if (!empty($course['tutor_name'])) {
  553. $course_details[] = $course['tutor_name'];
  554. }
  555. }
  556. if (api_get_setting('show_different_course_language') == 'true' &&
  557. $course['course_language'] != api_get_setting('platformLanguage')
  558. ) {
  559. $course_details[] = $course['course_language'];
  560. }
  561. $courses_list_string .= implode(' - ', $course_details);
  562. // We display a subscription link if:
  563. // 1. it is allowed to register for the course and if the course is not already in
  564. // the courselist of the user and if the user is identified
  565. // 2.
  566. if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
  567. if ($course['subscribe'] == '1') {
  568. $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(
  569. $_GET['category']
  570. ).'">'.get_lang('Subscribe').'</a><br />';
  571. } else {
  572. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  573. }
  574. }
  575. $courses_list_string .= "</li>";
  576. } //end else
  577. } // end foreach
  578. $courses_list_string .= "</ul>";
  579. }
  580. if ($courses_shown > 0) {
  581. // Only display the list of courses and categories if there was more than
  582. // 0 courses visible to the world (we're in the anonymous list here).
  583. $result .= $courses_list_string;
  584. }
  585. if ($category != '') {
  586. $result .= '<p><a href="'.api_get_self().'">'
  587. .Display:: return_icon('back.png', get_lang('BackToHomePage'))
  588. .get_lang('BackToHomePage').'</a></p>';
  589. }
  590. return $result;
  591. }
  592. /**
  593. * retrieves all the courses that the user has already subscribed to.
  594. *
  595. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  596. *
  597. * @param int $user_id : the id of the user
  598. *
  599. * @return array an array containing all the information of the courses of the given user
  600. */
  601. public function get_courses_of_user($user_id)
  602. {
  603. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  604. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  605. // Secondly we select the courses that are in a category (user_course_cat <> 0)
  606. // and sort these according to the sort of the category
  607. $user_id = intval($user_id);
  608. $sql = "SELECT
  609. course.code k,
  610. course.visual_code vc,
  611. course.subscribe subscr,
  612. course.unsubscribe unsubscr,
  613. course.title i,
  614. course.tutor_name t,
  615. course.directory dir,
  616. course_rel_user.status status,
  617. course_rel_user.sort sort,
  618. course_rel_user.user_course_cat user_course_cat
  619. FROM
  620. $table_course course,
  621. $table_course_user course_rel_user
  622. WHERE
  623. course.id = course_rel_user.c_id AND
  624. course_rel_user.user_id = '".$user_id."' AND
  625. course_rel_user.relation_type <> ".COURSE_RELATION_TYPE_RRHH."
  626. ORDER BY course_rel_user.sort ASC";
  627. $result = Database::query($sql);
  628. $courses = [];
  629. while ($row = Database::fetch_array($result)) {
  630. // We only need the database name of the course.
  631. $courses[$row['k']] = [
  632. 'code' => $row['k'],
  633. 'visual_code' => $row['vc'],
  634. 'title' => $row['i'],
  635. 'directory' => $row['dir'],
  636. 'status' => $row['status'],
  637. 'tutor' => $row['t'],
  638. 'subscribe' => $row['subscr'],
  639. 'unsubscribe' => $row['unsubscr'],
  640. 'sort' => $row['sort'],
  641. 'user_course_category' => $row['user_course_cat'],
  642. ];
  643. }
  644. return $courses;
  645. }
  646. /**
  647. * @todo use the template system
  648. *
  649. * @param $title
  650. * @param $content
  651. * @param string $id
  652. * @param array $params
  653. * @param string $idAccordion
  654. * @param string $idCollapse
  655. *
  656. * @return string
  657. */
  658. public function showRightBlock(
  659. $title,
  660. $content,
  661. $id = '',
  662. $params = [],
  663. $idAccordion = '',
  664. $idCollapse = ''
  665. ) {
  666. $html = '';
  667. if (!empty($idAccordion)) {
  668. $html .= '<div class="panel-group" id="'.$idAccordion.'" role="tablist" aria-multiselectable="true">';
  669. $html .= '<div class="panel panel-default" id="'.$id.'">';
  670. $html .= '<div class="panel-heading" role="tab"><h4 class="panel-title">';
  671. $html .= '<a role="button" data-toggle="collapse" data-parent="#'.$idAccordion.'" href="#'.$idCollapse.'" aria-expanded="true" aria-controls="'.$idCollapse.'">'.$title.'</a>';
  672. $html .= '</h4></div>';
  673. $html .= '<div id="'.$idCollapse.'" class="panel-collapse collapse in" role="tabpanel">';
  674. $html .= '<div class="panel-body">'.$content.'</div>';
  675. $html .= '</div></div></div>';
  676. } else {
  677. if (!empty($id)) {
  678. $params['id'] = $id;
  679. }
  680. $params['class'] = 'panel panel-default';
  681. $html = null;
  682. if (!empty($title)) {
  683. $html .= '<div class="panel-heading">'.$title.'</div>';
  684. }
  685. $html .= '<div class="panel-body">'.$content.'</div>';
  686. $html = Display::div($html, $params);
  687. }
  688. return $html;
  689. }
  690. /**
  691. * Adds a form to let users login.
  692. *
  693. * @version 1.1
  694. */
  695. public function display_login_form()
  696. {
  697. return $this->tpl->displayLoginForm();
  698. }
  699. /**
  700. * @todo use FormValidator
  701. *
  702. * @return string
  703. */
  704. public function return_search_block()
  705. {
  706. $html = '';
  707. if (api_get_setting('search_enabled') == 'true') {
  708. $search_btn = get_lang('Search');
  709. $search_content = '<form action="main/search/" method="post">
  710. <div class="form-group">
  711. <input type="text" id="query" class="form-control" name="query" value="" />
  712. <button class="btn btn-default" type="submit" name="submit" value="'.$search_btn.'" />'.
  713. $search_btn.' </button>
  714. </div></form>';
  715. $html .= $this->showRightBlock(get_lang('Search'), $search_content, 'search_block');
  716. }
  717. return $html;
  718. }
  719. /**
  720. * @return string
  721. */
  722. public function returnClassesBlock()
  723. {
  724. if (api_get_setting('show_groups_to_users') !== 'true') {
  725. return '';
  726. }
  727. $items = [];
  728. $usergroup = new UserGroup();
  729. if (api_is_platform_admin()) {
  730. $items[] = [
  731. 'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add',
  732. 'title' => get_lang('AddClasses'),
  733. ];
  734. } else {
  735. if (api_is_teacher() && $usergroup->allowTeachers()) {
  736. $items[] = [
  737. 'link' => api_get_path(WEB_CODE_PATH).'admin/usergroups.php',
  738. 'title' => get_lang('ClassList'),
  739. ];
  740. }
  741. }
  742. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  743. if (!empty($usergroup_list)) {
  744. foreach ($usergroup_list as $group_id) {
  745. $data = $usergroup->get($group_id);
  746. $items[] = [
  747. 'link' => api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id'],
  748. 'title' => $data['name'],
  749. ];
  750. }
  751. }
  752. $html = $this->showRightBlock(
  753. get_lang('Classes'),
  754. self::returnRightBlockItems($items),
  755. 'classes_block'
  756. );
  757. return $html;
  758. }
  759. /**
  760. * @return string
  761. */
  762. public function return_user_image_block()
  763. {
  764. $html = '';
  765. if (!api_is_anonymous()) {
  766. $userPicture = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
  767. $content = null;
  768. if (api_get_setting('allow_social_tool') == 'true') {
  769. $content .= '<a style="text-align:center" href="'.api_get_path(WEB_CODE_PATH).'social/home.php">
  770. <img class="img-circle" src="'.$userPicture.'"></a>';
  771. } else {
  772. $content .= '<a style="text-align:center" href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php">
  773. <img class="img-circle" title="'.get_lang('EditProfile').'" src="'.$userPicture.'"></a>';
  774. }
  775. $html = $this->showRightBlock(
  776. null,
  777. $content,
  778. 'user_image_block',
  779. ['style' => 'text-align:center;']
  780. );
  781. }
  782. return $html;
  783. }
  784. /**
  785. * @return array
  786. */
  787. public function return_profile_block()
  788. {
  789. $userInfo = api_get_user_info();
  790. $userId = api_get_user_id();
  791. if (empty($userId)) {
  792. return;
  793. }
  794. $items = [];
  795. $userGroup = new UserGroup();
  796. // @todo Add a platform setting to add the user image.
  797. if (api_get_setting('allow_message_tool') === 'true') {
  798. // New messages.
  799. $number_of_new_messages = MessageManager::getCountNewMessages();
  800. // New contact invitations.
  801. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(
  802. $userId
  803. );
  804. // New group invitations sent by a moderator.
  805. $group_pending_invitations = $userGroup->get_groups_by_user(
  806. $userId,
  807. GROUP_USER_PERMISSION_PENDING_INVITATION,
  808. false
  809. );
  810. $group_pending_invitations = count($group_pending_invitations);
  811. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  812. $cant_msg = Display::badge($number_of_new_messages);
  813. $items[] = [
  814. 'class' => 'inbox-message-social',
  815. 'icon' => Display::return_icon('inbox.png', get_lang('Inbox')),
  816. 'link' => api_get_path(WEB_CODE_PATH).'messages/inbox.php',
  817. 'title' => get_lang('Inbox').$cant_msg,
  818. ];
  819. $items[] = [
  820. 'class' => 'new-message-social',
  821. 'icon' => Display::return_icon('new-message.png', get_lang('Compose')),
  822. 'link' => api_get_path(WEB_CODE_PATH).'messages/new_message.php',
  823. 'title' => get_lang('Compose'),
  824. ];
  825. if (api_get_setting('allow_social_tool') == 'true') {
  826. $total_invitations = Display::badge($total_invitations);
  827. $items[] = [
  828. 'class' => 'invitations-social',
  829. 'icon' => Display::return_icon('invitations.png', get_lang('PendingInvitations')),
  830. 'link' => api_get_path(WEB_CODE_PATH).'social/invitations.php',
  831. 'title' => get_lang('PendingInvitations').$total_invitations,
  832. ];
  833. }
  834. }
  835. $items[] = [
  836. 'class' => 'personal-data',
  837. 'icon' => Display::return_icon('database.png', get_lang('PersonalDataReport')),
  838. 'link' => api_get_path(WEB_CODE_PATH).'social/personal_data.php',
  839. 'title' => get_lang('PersonalDataReport'),
  840. ];
  841. if (api_get_configuration_value('allow_my_files_link_in_homepage')) {
  842. if (api_get_setting('allow_my_files') !== 'false') {
  843. $items[] = [
  844. 'class' => 'myfiles-social',
  845. 'icon' => Display::return_icon('sn-files.png', get_lang('Files')),
  846. 'link' => api_get_path(WEB_CODE_PATH).'social/myfiles.php',
  847. 'title' => get_lang('MyFiles'),
  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. if (api_get_configuration_value('hide_course_sidebar')) {
  924. return '';
  925. }
  926. $isHrm = api_is_drh();
  927. $show_create_link = false;
  928. $show_course_link = false;
  929. if (api_is_allowed_to_create_course()) {
  930. $show_create_link = true;
  931. }
  932. if (api_get_setting('allow_students_to_browse_courses') === 'true') {
  933. $show_course_link = true;
  934. }
  935. $items = [];
  936. // My account section
  937. if ($show_create_link) {
  938. if (api_get_setting('course_validation') == 'true' && !api_is_platform_admin()) {
  939. $items[] = [
  940. 'class' => 'add-course',
  941. 'icon' => Display::return_icon('new-course.png', get_lang('CreateCourseRequest')),
  942. 'link' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php',
  943. 'title' => get_lang('CreateCourseRequest'),
  944. ];
  945. } else {
  946. $items[] = [
  947. 'class' => 'add-course',
  948. 'icon' => Display::return_icon('new-course.png', get_lang('CourseCreate')),
  949. 'link' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php',
  950. 'title' => get_lang('CourseCreate'),
  951. ];
  952. }
  953. if (SessionManager::allowToManageSessions()) {
  954. $items[] = [
  955. 'class' => 'add-session',
  956. 'icon' => Display::return_icon('session.png', get_lang('AddSession')),
  957. 'link' => api_get_path(WEB_CODE_PATH).'session/session_add.php',
  958. 'title' => get_lang('AddSession'),
  959. ];
  960. }
  961. }
  962. // Sort courses
  963. if (api_get_configuration_value('view_grid_courses') != true) {
  964. $items[] = [
  965. 'class' => 'order-course',
  966. 'icon' => Display::return_icon('order-course.png', get_lang('SortMyCourses')),
  967. 'link' => api_get_path(WEB_CODE_PATH).'auth/sort_my_courses.php',
  968. 'title' => get_lang('SortMyCourses'),
  969. ];
  970. }
  971. // Session history
  972. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  973. $items[] = [
  974. 'class' => 'history-course',
  975. 'icon' => Display::return_icon('history-course.png', get_lang('DisplayTrainingList')),
  976. 'link' => api_get_path(WEB_PATH).'user_portal.php',
  977. 'title' => get_lang('DisplayTrainingList'),
  978. ];
  979. } else {
  980. $items[] = [
  981. 'class' => 'history-course',
  982. 'icon' => Display::return_icon('history-course.png', get_lang('HistoryTrainingSessions')),
  983. 'link' => api_get_path(WEB_PATH).'user_portal.php?history=1',
  984. 'title' => get_lang('HistoryTrainingSessions'),
  985. ];
  986. }
  987. if ($isHrm) {
  988. $items[] = [
  989. 'link' => api_get_path(WEB_CODE_PATH).'auth/hrm_courses.php',
  990. 'title' => get_lang('HrmAssignedUsersCourseList'),
  991. ];
  992. }
  993. // Course catalog
  994. if ($show_course_link) {
  995. if (!api_is_drh()) {
  996. $items[] = [
  997. 'class' => 'list-course',
  998. 'icon' => Display::return_icon('catalog-course.png', get_lang('CourseCatalog')),
  999. 'link' => api_get_path(WEB_CODE_PATH).'auth/courses.php',
  1000. 'title' => get_lang('CourseCatalog'),
  1001. ];
  1002. } else {
  1003. $items[] = [
  1004. 'link' => api_get_path(WEB_CODE_PATH).'dashboard/index.php',
  1005. 'title' => get_lang('Dashboard'),
  1006. ];
  1007. }
  1008. }
  1009. return $items;
  1010. }
  1011. /**
  1012. * Prints the session and course list (user_portal.php).
  1013. *
  1014. * @param int $user_id
  1015. * @param bool $showSessions
  1016. * @param string $categoryCodeFilter
  1017. * @param bool $useUserLanguageFilterIfAvailable
  1018. * @param bool $loadHistory
  1019. *
  1020. * @return array
  1021. */
  1022. public function returnCoursesAndSessions(
  1023. $user_id,
  1024. $showSessions = true,
  1025. $categoryCodeFilter = '',
  1026. $useUserLanguageFilterIfAvailable = true,
  1027. $loadHistory = false
  1028. ) {
  1029. $gameModeIsActive = api_get_setting('gamification_mode');
  1030. $viewGridCourses = api_get_configuration_value('view_grid_courses');
  1031. $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info');
  1032. $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl';
  1033. $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl';
  1034. $showAllSessions = api_get_configuration_value('show_all_sessions_on_my_course_page') === true;
  1035. if ($loadHistory) {
  1036. // Load sessions in category in *history*
  1037. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1038. } else {
  1039. // Load sessions in category
  1040. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1041. }
  1042. $sessionCount = 0;
  1043. $courseCount = 0;
  1044. // Student info code check (shows student progress information on
  1045. // courses list
  1046. $studentInfo = api_get_configuration_value('course_student_info');
  1047. $studentInfoProgress = !empty($studentInfo['progress']) && $studentInfo['progress'] === true;
  1048. $studentInfoScore = !empty($studentInfo['score']) && $studentInfo['score'] === true;
  1049. $studentInfoCertificate = !empty($studentInfo['certificate']) && $studentInfo['certificate'] === true;
  1050. $courseCompleteList = [];
  1051. $coursesInCategoryCount = 0;
  1052. $coursesNotInCategoryCount = 0;
  1053. $listCourse = '';
  1054. $specialCourseList = '';
  1055. // If we're not in the history view...
  1056. if ($loadHistory === false) {
  1057. // Display special courses.
  1058. $specialCourses = CourseManager::returnSpecialCourses(
  1059. $user_id,
  1060. $this->load_directories_preview,
  1061. $useUserLanguageFilterIfAvailable
  1062. );
  1063. // Display courses.
  1064. $courses = CourseManager::returnCourses(
  1065. $user_id,
  1066. $this->load_directories_preview,
  1067. $useUserLanguageFilterIfAvailable
  1068. );
  1069. // Course option (show student progress)
  1070. // This code will add new variables (Progress, Score, Certificate)
  1071. if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) {
  1072. if (!empty($specialCourses)) {
  1073. foreach ($specialCourses as $key => $specialCourseInfo) {
  1074. if ($studentInfoProgress) {
  1075. $progress = Tracking::get_avg_student_progress(
  1076. $user_id,
  1077. $specialCourseInfo['course_code']
  1078. );
  1079. $specialCourses[$key]['student_info']['progress'] = $progress === false ? null : $progress;
  1080. }
  1081. if ($studentInfoScore) {
  1082. $percentage_score = Tracking::get_avg_student_score(
  1083. $user_id,
  1084. $specialCourseInfo['course_code'],
  1085. []
  1086. );
  1087. $specialCourses[$key]['student_info']['score'] = $percentage_score;
  1088. }
  1089. if ($studentInfoCertificate) {
  1090. $category = Category::load(
  1091. null,
  1092. null,
  1093. $specialCourseInfo['course_code'],
  1094. null,
  1095. null,
  1096. null
  1097. );
  1098. $specialCourses[$key]['student_info']['certificate'] = null;
  1099. if (isset($category[0])) {
  1100. if ($category[0]->is_certificate_available($user_id)) {
  1101. $specialCourses[$key]['student_info']['certificate'] = Display::label(
  1102. get_lang('Yes'),
  1103. 'success'
  1104. );
  1105. } else {
  1106. $specialCourses[$key]['student_info']['certificate'] = Display::label(
  1107. get_lang('No'),
  1108. 'danger'
  1109. );
  1110. }
  1111. }
  1112. }
  1113. }
  1114. }
  1115. if (isset($courses['in_category'])) {
  1116. foreach ($courses['in_category'] as $key1 => $value) {
  1117. if (isset($courses['in_category'][$key1]['courses'])) {
  1118. foreach ($courses['in_category'][$key1]['courses'] as $key2 => $courseInCatInfo) {
  1119. $courseCode = $courseInCatInfo['course_code'];
  1120. if ($studentInfoProgress) {
  1121. $progress = Tracking::get_avg_student_progress(
  1122. $user_id,
  1123. $courseCode
  1124. );
  1125. $courses['in_category'][$key1]['courses'][$key2]['student_info']['progress'] = $progress === false ? null : $progress;
  1126. }
  1127. if ($studentInfoScore) {
  1128. $percentage_score = Tracking::get_avg_student_score(
  1129. $user_id,
  1130. $courseCode,
  1131. []
  1132. );
  1133. $courses['in_category'][$key1]['courses'][$key2]['student_info']['score'] = $percentage_score;
  1134. }
  1135. if ($studentInfoCertificate) {
  1136. $category = Category::load(
  1137. null,
  1138. null,
  1139. $courseCode,
  1140. null,
  1141. null,
  1142. null
  1143. );
  1144. $courses['in_category'][$key1]['student_info']['certificate'] = null;
  1145. $isCertificateAvailable = $category[0]->is_certificate_available($user_id);
  1146. if (isset($category[0])) {
  1147. if ($viewGridCourses) {
  1148. if ($isCertificateAvailable) {
  1149. $courses['in_category'][$key1]['student_info']['certificate'] = get_lang(
  1150. 'Yes'
  1151. );
  1152. } else {
  1153. $courses['in_category'][$key1]['student_info']['certificate'] = get_lang(
  1154. 'No'
  1155. );
  1156. }
  1157. } else {
  1158. if ($isCertificateAvailable) {
  1159. $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
  1160. get_lang('Yes'),
  1161. 'success'
  1162. );
  1163. } else {
  1164. $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
  1165. get_lang('No'),
  1166. 'danger'
  1167. );
  1168. }
  1169. }
  1170. }
  1171. }
  1172. }
  1173. }
  1174. }
  1175. }
  1176. if (isset($courses['not_category'])) {
  1177. foreach ($courses['not_category'] as $key => $courseNotInCatInfo) {
  1178. $courseCode = $courseNotInCatInfo['course_code'];
  1179. if ($studentInfoProgress) {
  1180. $progress = Tracking::get_avg_student_progress(
  1181. $user_id,
  1182. $courseCode
  1183. );
  1184. $courses['not_category'][$key]['student_info']['progress'] = $progress === false ? null : $progress;
  1185. }
  1186. if ($studentInfoScore) {
  1187. $percentage_score = Tracking::get_avg_student_score(
  1188. $user_id,
  1189. $courseCode,
  1190. []
  1191. );
  1192. $courses['not_category'][$key]['student_info']['score'] = $percentage_score;
  1193. }
  1194. if ($studentInfoCertificate) {
  1195. $category = Category::load(
  1196. null,
  1197. null,
  1198. $courseCode,
  1199. null,
  1200. null,
  1201. null
  1202. );
  1203. $courses['not_category'][$key]['student_info']['certificate'] = null;
  1204. if (isset($category[0])) {
  1205. $certificateAvailable = $category[0]->is_certificate_available($user_id);
  1206. if ($viewGridCourses) {
  1207. if ($certificateAvailable) {
  1208. $courses['not_category'][$key]['student_info']['certificate'] = get_lang('Yes');
  1209. } else {
  1210. $courses['not_category'][$key]['student_info']['certificate'] = get_lang('No');
  1211. }
  1212. } else {
  1213. if ($certificateAvailable) {
  1214. $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
  1215. get_lang('Yes'),
  1216. 'success'
  1217. );
  1218. } else {
  1219. $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
  1220. get_lang('No'),
  1221. 'danger'
  1222. );
  1223. }
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. if ($viewGridCourses) {
  1231. $coursesWithoutCategoryTemplate = '/user_portal/grid_courses_without_category.tpl';
  1232. $coursesWithCategoryTemplate = '/user_portal/grid_courses_with_category.tpl';
  1233. }
  1234. if ($specialCourses) {
  1235. if ($categoryCodeFilter) {
  1236. $specialCourses = self::filterByCategory($specialCourses, $categoryCodeFilter);
  1237. }
  1238. $this->tpl->assign('courses', $specialCourses);
  1239. $specialCourseList = $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate));
  1240. $courseCompleteList = array_merge($courseCompleteList, $specialCourses);
  1241. }
  1242. if ($courses['in_category'] || $courses['not_category']) {
  1243. foreach ($courses['in_category'] as $courseData) {
  1244. if (!empty($courseData['courses'])) {
  1245. $coursesInCategoryCount += count($courseData['courses']);
  1246. $courseCompleteList = array_merge($courseCompleteList, $courseData['courses']);
  1247. }
  1248. }
  1249. $coursesNotInCategoryCount += count($courses['not_category']);
  1250. $courseCompleteList = array_merge($courseCompleteList, $courses['not_category']);
  1251. if ($categoryCodeFilter) {
  1252. $courses['in_category'] = self::filterByCategory(
  1253. $courses['in_category'],
  1254. $categoryCodeFilter
  1255. );
  1256. $courses['not_category'] = self::filterByCategory(
  1257. $courses['not_category'],
  1258. $categoryCodeFilter
  1259. );
  1260. }
  1261. $this->tpl->assign('courses', $courses['not_category']);
  1262. $this->tpl->assign('categories', $courses['in_category']);
  1263. $listCourse = $this->tpl->fetch($this->tpl->get_template($coursesWithCategoryTemplate));
  1264. $listCourse .= $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate));
  1265. }
  1266. $courseCount = count($specialCourses) + $coursesInCategoryCount + $coursesNotInCategoryCount;
  1267. }
  1268. $sessions_with_category = '';
  1269. $sessions_with_no_category = '';
  1270. $collapsable = api_get_configuration_value('allow_user_session_collapsable');
  1271. $collapsableLink = '';
  1272. if ($collapsable) {
  1273. $collapsableLink = api_get_path(WEB_PATH).'user_portal.php?action=collapse_session';
  1274. }
  1275. $extraFieldValue = new ExtraFieldValue('session');
  1276. if ($showSessions) {
  1277. $coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link');
  1278. $coursesListSessionStyle = $coursesListSessionStyle === false ? 1 : $coursesListSessionStyle;
  1279. if (api_is_drh()) {
  1280. $coursesListSessionStyle = 1;
  1281. }
  1282. $portalShowDescription = api_get_setting('show_session_description') === 'true';
  1283. // Declared listSession variable
  1284. $listSession = [];
  1285. // Get timestamp in UTC to compare to DB values (in UTC by convention)
  1286. $session_now = strtotime(api_get_utc_datetime(time()));
  1287. if (is_array($session_categories)) {
  1288. foreach ($session_categories as $session_category) {
  1289. $session_category_id = $session_category['session_category']['id'];
  1290. // Sessions and courses that are not in a session category
  1291. if (empty($session_category_id) &&
  1292. isset($session_category['sessions'])
  1293. ) {
  1294. // Independent sessions
  1295. foreach ($session_category['sessions'] as $session) {
  1296. $session_id = $session['session_id'];
  1297. // Don't show empty sessions.
  1298. if (count($session['courses']) < 1) {
  1299. continue;
  1300. }
  1301. // Courses inside the current session.
  1302. $date_session_start = $session['access_start_date'];
  1303. $date_session_end = $session['access_end_date'];
  1304. $coachAccessStartDate = $session['coach_access_start_date'];
  1305. $coachAccessEndDate = $session['coach_access_end_date'];
  1306. $count_courses_session = 0;
  1307. // Loop course content
  1308. $html_courses_session = [];
  1309. $atLeastOneCourseIsVisible = false;
  1310. $markAsOld = false;
  1311. $markAsFuture = false;
  1312. foreach ($session['courses'] as $course) {
  1313. $is_coach_course = api_is_coach($session_id, $course['real_id']);
  1314. $allowed_time = 0;
  1315. $allowedEndTime = true;
  1316. if (!empty($date_session_start)) {
  1317. if ($is_coach_course) {
  1318. $allowed_time = api_strtotime($coachAccessStartDate);
  1319. } else {
  1320. $allowed_time = api_strtotime($date_session_start);
  1321. }
  1322. $endSessionToTms = null;
  1323. if (!isset($_GET['history'])) {
  1324. if (!empty($date_session_end)) {
  1325. if ($is_coach_course) {
  1326. // if coach end date is empty we use the default end date
  1327. if (empty($coachAccessEndDate)) {
  1328. $endSessionToTms = api_strtotime($date_session_end);
  1329. if ($session_now > $endSessionToTms) {
  1330. $allowedEndTime = false;
  1331. }
  1332. } else {
  1333. $endSessionToTms = api_strtotime($coachAccessEndDate);
  1334. if ($session_now > $endSessionToTms) {
  1335. $allowedEndTime = false;
  1336. }
  1337. }
  1338. } else {
  1339. $endSessionToTms = api_strtotime($date_session_end);
  1340. if ($session_now > $endSessionToTms) {
  1341. $allowedEndTime = false;
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. if ($showAllSessions) {
  1348. if ($allowed_time < $session_now && $allowedEndTime === false) {
  1349. $markAsOld = true;
  1350. }
  1351. if ($allowed_time > $session_now && $endSessionToTms > $session_now) {
  1352. $markAsFuture = true;
  1353. }
  1354. $allowedEndTime = true;
  1355. $allowed_time = 0;
  1356. }
  1357. if ($session_now >= $allowed_time && $allowedEndTime) {
  1358. // Read only and accessible.
  1359. $atLeastOneCourseIsVisible = true;
  1360. if (api_get_setting('hide_courses_in_sessions') === 'false') {
  1361. $courseUserHtml = CourseManager::get_logged_user_course_html(
  1362. $course,
  1363. $session_id,
  1364. 'session_course_item',
  1365. true,
  1366. $this->load_directories_preview
  1367. );
  1368. if (isset($courseUserHtml[1])) {
  1369. $course_session = $courseUserHtml[1];
  1370. $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
  1371. // Course option (show student progress)
  1372. // This code will add new variables (Progress, Score, Certificate)
  1373. if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) {
  1374. if ($studentInfoProgress) {
  1375. $progress = Tracking::get_avg_student_progress(
  1376. $user_id,
  1377. $course['course_code'],
  1378. [],
  1379. $session_id
  1380. );
  1381. $course_session['student_info']['progress'] = $progress === false ? null : $progress;
  1382. }
  1383. if ($studentInfoScore) {
  1384. $percentage_score = Tracking::get_avg_student_score(
  1385. $user_id,
  1386. $course['course_code'],
  1387. [],
  1388. $session_id
  1389. );
  1390. $course_session['student_info']['score'] = $percentage_score;
  1391. }
  1392. if ($studentInfoCertificate) {
  1393. $category = Category::load(
  1394. null,
  1395. null,
  1396. $course['course_code'],
  1397. null,
  1398. null,
  1399. $session_id
  1400. );
  1401. $course_session['student_info']['certificate'] = null;
  1402. if (isset($category[0])) {
  1403. if ($category[0]->is_certificate_available($user_id)) {
  1404. $course_session['student_info']['certificate'] = Display::label(
  1405. get_lang('Yes'),
  1406. 'success'
  1407. );
  1408. } else {
  1409. $course_session['student_info']['certificate'] = Display::label(
  1410. get_lang('No')
  1411. );
  1412. }
  1413. }
  1414. }
  1415. }
  1416. $html_courses_session[] = $course_session;
  1417. }
  1418. }
  1419. $count_courses_session++;
  1420. }
  1421. }
  1422. // No courses to show.
  1423. if ($atLeastOneCourseIsVisible === false) {
  1424. if (empty($html_courses_session)) {
  1425. continue;
  1426. }
  1427. }
  1428. if ($count_courses_session > 0) {
  1429. $params = [
  1430. 'id' => $session_id,
  1431. ];
  1432. $session_box = Display::getSessionTitleBox($session_id);
  1433. $coachId = $session_box['id_coach'];
  1434. $imageField = $extraFieldValue->get_values_by_handler_and_field_variable(
  1435. $session_id,
  1436. 'image'
  1437. );
  1438. $params['category_id'] = $session_box['category_id'];
  1439. $params['title'] = $session_box['title'];
  1440. $params['id_coach'] = $coachId;
  1441. $params['coach_url'] = api_get_path(WEB_AJAX_PATH).
  1442. 'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId;
  1443. $params['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
  1444. $params['coach_avatar'] = UserManager::getUserPicture(
  1445. $coachId,
  1446. USER_IMAGE_SIZE_SMALL
  1447. );
  1448. $params['date'] = $session_box['dates'];
  1449. $params['image'] = isset($imageField['value']) ? $imageField['value'] : null;
  1450. $params['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
  1451. $params['show_actions'] = SessionManager::cantEditSession($session_id);
  1452. if ($collapsable) {
  1453. $collapsableData = SessionManager::getCollapsableData(
  1454. $user_id,
  1455. $session_id,
  1456. $extraFieldValue,
  1457. $collapsableLink
  1458. );
  1459. $params['collapsed'] = $collapsableData['collapsed'];
  1460. $params['collapsable_link'] = $collapsableData['collapsable_link'];
  1461. }
  1462. $params['show_description'] = $session_box['show_description'] == 1 && $portalShowDescription;
  1463. $params['description'] = $session_box['description'];
  1464. $params['visibility'] = $session_box['visibility'];
  1465. $params['show_simple_session_info'] = $showSimpleSessionInfo;
  1466. $params['course_list_session_style'] = $coursesListSessionStyle;
  1467. $params['num_users'] = $session_box['num_users'];
  1468. $params['num_courses'] = $session_box['num_courses'];
  1469. $params['course_categories'] = CourseManager::getCourseCategoriesFromCourseList(
  1470. $html_courses_session
  1471. );
  1472. $params['courses'] = $html_courses_session;
  1473. $params['is_old'] = $markAsOld;
  1474. $params['is_future'] = $markAsFuture;
  1475. if ($showSimpleSessionInfo) {
  1476. $params['subtitle'] = self::getSimpleSessionDetails(
  1477. $session_box['coach'],
  1478. $session_box['dates'],
  1479. isset($session_box['duration']) ? $session_box['duration'] : null
  1480. );
  1481. }
  1482. if ($gameModeIsActive) {
  1483. $params['stars'] = GamificationUtils::getSessionStars(
  1484. $params['id'],
  1485. $this->user_id
  1486. );
  1487. $params['progress'] = GamificationUtils::getSessionProgress(
  1488. $params['id'],
  1489. $this->user_id
  1490. );
  1491. $params['points'] = GamificationUtils::getSessionPoints(
  1492. $params['id'],
  1493. $this->user_id
  1494. );
  1495. }
  1496. $listSession[] = $params;
  1497. $sessionCount++;
  1498. }
  1499. }
  1500. } else {
  1501. // All sessions included in
  1502. $count_courses_session = 0;
  1503. $html_sessions = '';
  1504. if (isset($session_category['sessions'])) {
  1505. foreach ($session_category['sessions'] as $session) {
  1506. $session_id = $session['session_id'];
  1507. // Don't show empty sessions.
  1508. if (count($session['courses']) < 1) {
  1509. continue;
  1510. }
  1511. $date_session_start = $session['access_start_date'];
  1512. $date_session_end = $session['access_end_date'];
  1513. $coachAccessStartDate = $session['coach_access_start_date'];
  1514. $coachAccessEndDate = $session['coach_access_end_date'];
  1515. $html_courses_session = [];
  1516. $count = 0;
  1517. $markAsOld = false;
  1518. $markAsFuture = false;
  1519. foreach ($session['courses'] as $course) {
  1520. $is_coach_course = api_is_coach($session_id, $course['real_id']);
  1521. $allowed_time = 0;
  1522. $allowedEndTime = true;
  1523. if (!empty($date_session_start)) {
  1524. if ($is_coach_course) {
  1525. $allowed_time = api_strtotime($coachAccessStartDate);
  1526. } else {
  1527. $allowed_time = api_strtotime($date_session_start);
  1528. }
  1529. if (!isset($_GET['history'])) {
  1530. if (!empty($date_session_end)) {
  1531. if ($is_coach_course) {
  1532. // if coach end date is empty we use the default end date
  1533. if (empty($coachAccessEndDate)) {
  1534. $endSessionToTms = api_strtotime($date_session_end);
  1535. if ($session_now > $endSessionToTms) {
  1536. $allowedEndTime = false;
  1537. }
  1538. } else {
  1539. $endSessionToTms = api_strtotime($coachAccessEndDate);
  1540. if ($session_now > $endSessionToTms) {
  1541. $allowedEndTime = false;
  1542. }
  1543. }
  1544. } else {
  1545. $endSessionToTms = api_strtotime($date_session_end);
  1546. if ($session_now > $endSessionToTms) {
  1547. $allowedEndTime = false;
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. if ($showAllSessions) {
  1554. if ($allowed_time < $session_now && $allowedEndTime == false) {
  1555. $markAsOld = true;
  1556. }
  1557. if ($allowed_time > $session_now && $endSessionToTms > $session_now) {
  1558. $markAsFuture = true;
  1559. }
  1560. $allowedEndTime = true;
  1561. $allowed_time = 0;
  1562. }
  1563. if ($session_now >= $allowed_time && $allowedEndTime) {
  1564. if (api_get_setting('hide_courses_in_sessions') === 'false') {
  1565. $c = CourseManager::get_logged_user_course_html(
  1566. $course,
  1567. $session_id,
  1568. 'session_course_item'
  1569. );
  1570. if (isset($c[1])) {
  1571. $html_courses_session[] = $c[1];
  1572. }
  1573. }
  1574. $count_courses_session++;
  1575. $count++;
  1576. }
  1577. }
  1578. $sessionParams = [];
  1579. // Category
  1580. if ($count > 0) {
  1581. $session_box = Display::getSessionTitleBox($session_id);
  1582. $sessionParams[0]['id'] = $session_id;
  1583. $sessionParams[0]['date'] = $session_box['dates'];
  1584. $sessionParams[0]['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
  1585. $sessionParams[0]['course_list_session_style'] = $coursesListSessionStyle;
  1586. $sessionParams[0]['title'] = $session_box['title'];
  1587. $sessionParams[0]['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
  1588. $sessionParams[0]['show_actions'] = SessionManager::cantEditSession($session_id);
  1589. $sessionParams[0]['courses'] = $html_courses_session;
  1590. $sessionParams[0]['show_simple_session_info'] = $showSimpleSessionInfo;
  1591. $sessionParams[0]['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
  1592. $sessionParams[0]['is_old'] = $markAsOld;
  1593. $sessionParams[0]['is_future'] = $markAsFuture;
  1594. if ($collapsable) {
  1595. $collapsableData = SessionManager::getCollapsableData(
  1596. $user_id,
  1597. $session_id,
  1598. $extraFieldValue,
  1599. $collapsableLink
  1600. );
  1601. $sessionParams[0]['collapsable_link'] = $collapsableData['collapsable_link'];
  1602. $sessionParams[0]['collapsed'] = $collapsableData['collapsed'];
  1603. }
  1604. if ($showSimpleSessionInfo) {
  1605. $sessionParams[0]['subtitle'] = self::getSimpleSessionDetails(
  1606. $session_box['coach'],
  1607. $session_box['dates'],
  1608. isset($session_box['duration']) ? $session_box['duration'] : null
  1609. );
  1610. }
  1611. $this->tpl->assign('session', $sessionParams);
  1612. $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false));
  1613. $this->tpl->assign('gamification_mode', $gameModeIsActive);
  1614. $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url'));
  1615. if ($viewGridCourses) {
  1616. $html_sessions .= $this->tpl->fetch(
  1617. $this->tpl->get_template('/user_portal/grid_session.tpl')
  1618. );
  1619. } else {
  1620. $html_sessions .= $this->tpl->fetch(
  1621. $this->tpl->get_template('user_portal/classic_session.tpl')
  1622. );
  1623. }
  1624. $sessionCount++;
  1625. }
  1626. }
  1627. }
  1628. if ($count_courses_session > 0) {
  1629. $categoryParams = [
  1630. 'id' => $session_category['session_category']['id'],
  1631. 'title' => $session_category['session_category']['name'],
  1632. 'show_actions' => api_is_platform_admin(),
  1633. 'subtitle' => '',
  1634. 'sessions' => $html_sessions,
  1635. ];
  1636. $session_category_start_date = $session_category['session_category']['date_start'];
  1637. $session_category_end_date = $session_category['session_category']['date_end'];
  1638. if ($session_category_start_date == '0000-00-00') {
  1639. $session_category_start_date = '';
  1640. }
  1641. if ($session_category_end_date == '0000-00-00') {
  1642. $session_category_end_date = '';
  1643. }
  1644. if (!empty($session_category_start_date) &&
  1645. !empty($session_category_end_date)
  1646. ) {
  1647. $categoryParams['subtitle'] = sprintf(
  1648. get_lang('FromDateXToDateY'),
  1649. $session_category_start_date,
  1650. $session_category_end_date
  1651. );
  1652. } else {
  1653. if (!empty($session_category_start_date)) {
  1654. $categoryParams['subtitle'] = get_lang('From').' '.$session_category_start_date;
  1655. }
  1656. if (!empty($session_category_end_date)) {
  1657. $categoryParams['subtitle'] = get_lang('Until').' '.$session_category_end_date;
  1658. }
  1659. }
  1660. $this->tpl->assign('session_category', $categoryParams);
  1661. $sessions_with_category .= $this->tpl->fetch(
  1662. $this->tpl->get_template('user_portal/session_category.tpl')
  1663. );
  1664. }
  1665. }
  1666. }
  1667. $allCoursesInSessions = [];
  1668. foreach ($listSession as $currentSession) {
  1669. $coursesInSessions = $currentSession['courses'];
  1670. unset($currentSession['courses']);
  1671. foreach ($coursesInSessions as $coursesInSession) {
  1672. $coursesInSession['session'] = $currentSession;
  1673. $allCoursesInSessions[] = $coursesInSession;
  1674. }
  1675. }
  1676. $this->tpl->assign('all_courses', $allCoursesInSessions);
  1677. $this->tpl->assign('session', $listSession);
  1678. $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false));
  1679. $this->tpl->assign('gamification_mode', $gameModeIsActive);
  1680. $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url'));
  1681. if ($viewGridCourses) {
  1682. $sessions_with_no_category = $this->tpl->fetch(
  1683. $this->tpl->get_template('/user_portal/grid_session.tpl')
  1684. );
  1685. } else {
  1686. $sessions_with_no_category = $this->tpl->fetch(
  1687. $this->tpl->get_template('user_portal/classic_session.tpl')
  1688. );
  1689. }
  1690. }
  1691. }
  1692. return [
  1693. 'courses' => $courseCompleteList,
  1694. 'sessions' => $session_categories,
  1695. 'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse),
  1696. 'session_count' => $sessionCount,
  1697. 'course_count' => $courseCount,
  1698. ];
  1699. }
  1700. /**
  1701. * Shows a welcome message when the user doesn't have any content in the course list.
  1702. */
  1703. public function return_welcome_to_course_block()
  1704. {
  1705. $count_courses = CourseManager::count_courses();
  1706. $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
  1707. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  1708. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  1709. $this->tpl->assign('course_catalog_url', $course_catalog_url);
  1710. $this->tpl->assign('course_list_url', $course_list_url);
  1711. $this->tpl->assign('course_catalog_link', Display::url(get_lang('Here'), $course_catalog_url));
  1712. $this->tpl->assign('course_list_link', Display::url(get_lang('Here'), $course_list_url));
  1713. $this->tpl->assign('count_courses', $count_courses);
  1714. return $this->tpl->fetch($tpl);
  1715. }
  1716. /**
  1717. * @return array
  1718. */
  1719. public function return_hot_courses()
  1720. {
  1721. return CourseManager::return_hot_courses(30, 6);
  1722. }
  1723. /**
  1724. * UserPortal view for session, return the HTML of the course list.
  1725. *
  1726. * @param $user_id
  1727. *
  1728. * @return string
  1729. */
  1730. public function returnCoursesAndSessionsViewBySession($user_id)
  1731. {
  1732. $sessionCount = 0;
  1733. $courseCount = 0;
  1734. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  1735. if ($load_history) {
  1736. // Load sessions in category in *history*
  1737. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1738. } else {
  1739. // Load sessions in category
  1740. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1741. }
  1742. $html = '';
  1743. $loadDirs = $this->load_directories_preview;
  1744. // If we're not in the history view...
  1745. $listCoursesInfo = [];
  1746. if (!isset($_GET['history'])) {
  1747. // Display special courses
  1748. $specialCoursesResult = CourseManager::returnSpecialCourses(
  1749. $user_id,
  1750. $loadDirs
  1751. );
  1752. $specialCourses = $specialCoursesResult;
  1753. if ($specialCourses) {
  1754. $this->tpl->assign('courses', $specialCourses);
  1755. $html = $this->tpl->fetch(
  1756. $this->tpl->get_template('/user_portal/classic_courses_without_category.tpl')
  1757. );
  1758. }
  1759. // Display courses
  1760. // [code=>xxx, real_id=>000]
  1761. $listCourses = CourseManager::get_courses_list_by_user_id(
  1762. $user_id,
  1763. false
  1764. );
  1765. foreach ($listCourses as $i => $listCourseCodeId) {
  1766. if (isset($listCourseCodeId['special_course'])) {
  1767. continue;
  1768. }
  1769. $courseCategory = CourseManager::getUserCourseCategoryForCourse(
  1770. $user_id,
  1771. $listCourseCodeId['real_id']
  1772. );
  1773. $userCatTitle = '';
  1774. $userCategoryId = 0;
  1775. if ($courseCategory) {
  1776. $userCategoryId = $courseCategory['user_course_cat'];
  1777. $userCatTitle = $courseCategory['title'];
  1778. }
  1779. $listCourse = api_get_course_info_by_id($listCourseCodeId['real_id']);
  1780. $listCoursesInfo[] = [
  1781. 'course' => $listCourse,
  1782. 'code' => $listCourseCodeId['code'],
  1783. 'id' => $listCourseCodeId['real_id'],
  1784. 'title' => $listCourse['title'],
  1785. 'userCatId' => $userCategoryId,
  1786. 'userCatTitle' => $userCatTitle,
  1787. ];
  1788. $courseCount++;
  1789. }
  1790. usort($listCoursesInfo, 'self::compareByCourse');
  1791. }
  1792. $listCoursesInSession = [];
  1793. if (is_array($session_categories)) {
  1794. // all courses that are in a session
  1795. $listCoursesInSession = SessionManager::getNamedSessionCourseForCoach($user_id);
  1796. }
  1797. // we got all courses
  1798. // for each user category, sorted alphabetically, display courses
  1799. $listUserCategories = CourseManager::get_user_course_categories($user_id);
  1800. $listCoursesAlreadyDisplayed = [];
  1801. uasort($listUserCategories, "self::compareListUserCategory");
  1802. $listUserCategories[0] = '';
  1803. $html .= '<div class="session-view-block">';
  1804. foreach ($listUserCategories as $userCategoryId => $userCat) {
  1805. // add user category
  1806. $userCategoryHtml = '';
  1807. if ($userCategoryId != 0) {
  1808. $userCategoryHtml = '<div class="session-view-well ">';
  1809. $userCategoryHtml .= self::getHtmlForUserCategory($userCategoryId, $userCat['title']);
  1810. }
  1811. // look for course in this userCat in session courses : $listCoursesInSession
  1812. $htmlCategory = '';
  1813. if (isset($listCoursesInSession[$userCategoryId])) {
  1814. // list of courses in this user cat
  1815. foreach ($listCoursesInSession[$userCategoryId]['courseInUserCatList'] as $i => $listCourse) {
  1816. // add course
  1817. $listCoursesAlreadyDisplayed[$listCourse['courseId']] = 1;
  1818. if ($userCategoryId == 0) {
  1819. $htmlCategory .= '<div class="panel panel-default">';
  1820. } else {
  1821. $htmlCategory .= '<div class="panel panel-default">';
  1822. }
  1823. $htmlCategory .= '<div class="panel-body">';
  1824. $coursesInfo = $listCourse['course'];
  1825. $htmlCategory .= self::getHtmlForCourse(
  1826. $coursesInfo,
  1827. $userCategoryId,
  1828. 1,
  1829. $loadDirs
  1830. );
  1831. // list of session category
  1832. $htmlSessionCategory = '<div class="session-view-row" style="display:none;" id="courseblock-'.$coursesInfo['real_id'].'">';
  1833. foreach ($listCourse['sessionCatList'] as $listCategorySession) {
  1834. // add session category
  1835. $htmlSessionCategory .= self::getHtmlSessionCategory(
  1836. $listCategorySession['catSessionId'],
  1837. $listCategorySession['catSessionName']
  1838. );
  1839. // list of session
  1840. $htmlSession = ''; // start
  1841. foreach ($listCategorySession['sessionList'] as $listSession) {
  1842. // add session
  1843. $htmlSession .= '<div class="session-view-row">';
  1844. $htmlSession .= self::getHtmlForSession(
  1845. $listSession['sessionId'],
  1846. $listSession['sessionName'],
  1847. $listCategorySession['catSessionId'],
  1848. $coursesInfo
  1849. );
  1850. $htmlSession .= '</div>';
  1851. $sessionCount++;
  1852. }
  1853. $htmlSession .= ''; // end session block
  1854. $htmlSessionCategory .= $htmlSession;
  1855. }
  1856. $htmlSessionCategory .= '</div>'; // end session cat block
  1857. $htmlCategory .= $htmlSessionCategory.'</div></div>';
  1858. $htmlCategory .= ''; // end course block
  1859. }
  1860. $userCategoryHtml .= $htmlCategory;
  1861. }
  1862. // look for courses in this userCat in not in session courses : $listCoursesInfo
  1863. // if course not already added
  1864. $htmlCategory = '';
  1865. foreach ($listCoursesInfo as $i => $listCourse) {
  1866. if ($listCourse['userCatId'] == $userCategoryId &&
  1867. !isset($listCoursesAlreadyDisplayed[$listCourse['id']])
  1868. ) {
  1869. if ($userCategoryId != 0) {
  1870. $htmlCategory .= '<div class="panel panel-default">';
  1871. } else {
  1872. $htmlCategory .= '<div class="panel panel-default">';
  1873. }
  1874. $htmlCategory .= '<div class="panel-body">';
  1875. $htmlCategory .= self::getHtmlForCourse(
  1876. $listCourse['course'],
  1877. $userCategoryId,
  1878. 0,
  1879. $loadDirs
  1880. );
  1881. $htmlCategory .= '</div></div>';
  1882. }
  1883. }
  1884. $htmlCategory .= '';
  1885. $userCategoryHtml .= $htmlCategory; // end user cat block
  1886. if ($userCategoryId != 0) {
  1887. $userCategoryHtml .= '</div>';
  1888. }
  1889. $html .= $userCategoryHtml;
  1890. }
  1891. $html .= '</div>';
  1892. return [
  1893. 'html' => $html,
  1894. 'sessions' => $session_categories,
  1895. 'courses' => $listCoursesInfo,
  1896. 'session_count' => $sessionCount,
  1897. 'course_count' => $courseCount,
  1898. ];
  1899. }
  1900. /**
  1901. * @param $listA
  1902. * @param $listB
  1903. *
  1904. * @return int
  1905. */
  1906. public static function compareListUserCategory($listA, $listB)
  1907. {
  1908. if ($listA['title'] == $listB['title']) {
  1909. return 0;
  1910. }
  1911. if ($listA['title'] > $listB['title']) {
  1912. return 1;
  1913. }
  1914. return -1;
  1915. }
  1916. /**
  1917. * @param $view
  1918. * @param $userId
  1919. */
  1920. public static function setDefaultMyCourseView($view, $userId)
  1921. {
  1922. setcookie('defaultMyCourseView'.$userId, $view);
  1923. }
  1924. /**
  1925. * @param int $userId
  1926. *
  1927. * @return array
  1928. */
  1929. public function returnCourseCategoryListFromUser($userId)
  1930. {
  1931. $sessionCount = 0;
  1932. $courseList = CourseManager::get_courses_list_by_user_id($userId);
  1933. $categoryCodes = CourseManager::getCourseCategoriesFromCourseList($courseList);
  1934. $categories = [];
  1935. foreach ($categoryCodes as $categoryCode) {
  1936. $categories[] = CourseCategory::getCategory($categoryCode);
  1937. }
  1938. $template = new Template('', false, false, false, true, false, false);
  1939. $layout = $template->get_template('user_portal/course_categories.tpl');
  1940. $template->assign('course_categories', $categories);
  1941. return [
  1942. 'courses' => $courseList,
  1943. 'html' => $template->fetch($layout),
  1944. 'course_count' => count($courseList),
  1945. 'session_count' => $sessionCount,
  1946. ];
  1947. }
  1948. /**
  1949. * Set grade book dependency progress bar see BT#13099.
  1950. *
  1951. * @param $userId
  1952. *
  1953. * @return bool
  1954. */
  1955. public function setGradeBookDependencyBar($userId)
  1956. {
  1957. $allow = api_get_configuration_value('gradebook_dependency');
  1958. if (api_is_anonymous()) {
  1959. return false;
  1960. }
  1961. if ($allow) {
  1962. $courseAndSessions = $this->returnCoursesAndSessions(
  1963. $userId,
  1964. false,
  1965. '',
  1966. false,
  1967. false
  1968. );
  1969. $courseList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
  1970. $courseList = isset($courseList['courses']) ? $courseList['courses'] : [];
  1971. $mandatoryCourse = [];
  1972. if (!empty($courseList)) {
  1973. foreach ($courseList as $courseId) {
  1974. $courseInfo = api_get_course_info_by_id($courseId);
  1975. $mandatoryCourse[] = $courseInfo['code'];
  1976. }
  1977. }
  1978. // @todo improve calls of course info
  1979. $subscribedCourses = !empty($courseAndSessions['courses']) ? $courseAndSessions['courses'] : [];
  1980. $mainCategoryList = [];
  1981. foreach ($subscribedCourses as $courseInfo) {
  1982. $courseCode = $courseInfo['code'];
  1983. $categories = Category::load(null, null, $courseCode);
  1984. /** @var Category $category */
  1985. $category = !empty($categories[0]) ? $categories[0] : [];
  1986. if (!empty($category)) {
  1987. $mainCategoryList[] = $category;
  1988. }
  1989. }
  1990. $result20 = 0;
  1991. $result80 = 0;
  1992. $countCoursesPassedNoDependency = 0;
  1993. /** @var Category $category */
  1994. foreach ($mainCategoryList as $category) {
  1995. $userFinished = Category::userFinishedCourse(
  1996. $userId,
  1997. $category,
  1998. true
  1999. );
  2000. if ($userFinished) {
  2001. if (in_array($category->get_course_code(), $mandatoryCourse)) {
  2002. if ($result20 < 20) {
  2003. $result20 += 10;
  2004. }
  2005. } else {
  2006. $countCoursesPassedNoDependency++;
  2007. if ($result80 < 80) {
  2008. $result80 += 10;
  2009. }
  2010. }
  2011. }
  2012. }
  2013. $finalResult = $result20 + $result80;
  2014. $gradeBookList = api_get_configuration_value('gradebook_badge_sidebar');
  2015. $gradeBookList = isset($gradeBookList['gradebooks']) ? $gradeBookList['gradebooks'] : [];
  2016. $badgeList = [];
  2017. foreach ($gradeBookList as $id) {
  2018. $categories = Category::load($id);
  2019. /** @var Category $category */
  2020. $category = !empty($categories[0]) ? $categories[0] : [];
  2021. $badgeList[$id]['name'] = $category->get_name();
  2022. $badgeList[$id]['finished'] = false;
  2023. $badgeList[$id]['skills'] = [];
  2024. if (!empty($category)) {
  2025. $minToValidate = $category->getMinimumToValidate();
  2026. $dependencies = $category->getCourseListDependency();
  2027. $gradeBooksToValidateInDependence = $category->getGradeBooksToValidateInDependence();
  2028. $countDependenciesPassed = 0;
  2029. foreach ($dependencies as $courseId) {
  2030. $courseInfo = api_get_course_info_by_id($courseId);
  2031. $courseCode = $courseInfo['code'];
  2032. $categories = Category::load(null, null, $courseCode);
  2033. $subCategory = !empty($categories[0]) ? $categories[0] : null;
  2034. if (!empty($subCategory)) {
  2035. $score = Category::userFinishedCourse(
  2036. $userId,
  2037. $subCategory,
  2038. true
  2039. );
  2040. if ($score) {
  2041. $countDependenciesPassed++;
  2042. }
  2043. }
  2044. }
  2045. $userFinished =
  2046. $countDependenciesPassed >= $gradeBooksToValidateInDependence &&
  2047. $countCoursesPassedNoDependency >= $minToValidate;
  2048. if ($userFinished) {
  2049. $badgeList[$id]['finished'] = true;
  2050. }
  2051. $objSkill = new Skill();
  2052. $skills = $category->get_skills();
  2053. $skillList = [];
  2054. foreach ($skills as $skill) {
  2055. $skillList[] = $objSkill->get($skill['id']);
  2056. }
  2057. $badgeList[$id]['skills'] = $skillList;
  2058. }
  2059. }
  2060. $this->tpl->assign(
  2061. 'grade_book_sidebar',
  2062. true
  2063. );
  2064. $this->tpl->assign(
  2065. 'grade_book_progress',
  2066. $finalResult
  2067. );
  2068. $this->tpl->assign('grade_book_badge_list', $badgeList);
  2069. return true;
  2070. }
  2071. return false;
  2072. }
  2073. /**
  2074. * Generate the HTML code for items when displaying the right-side blocks.
  2075. *
  2076. * @param array $items
  2077. *
  2078. * @return string
  2079. */
  2080. private static function returnRightBlockItems(array $items)
  2081. {
  2082. $my_account_content = '';
  2083. foreach ($items as $item) {
  2084. if (empty($item['link']) && empty($item['title'])) {
  2085. continue;
  2086. }
  2087. $my_account_content .= '<li class="list-group-item '.(empty($item['class']) ? '' : $item['class']).'">'
  2088. .(empty($item['icon']) ? '' : '<span class="item-icon">'.$item['icon'].'</span>')
  2089. .'<a href="'.$item['link'].'">'.$item['title'].'</a>'
  2090. .'</li>';
  2091. }
  2092. return '<ul class="list-group">'.$my_account_content.'</ul>';
  2093. }
  2094. /**
  2095. * Return HTML code for personal user course category.
  2096. *
  2097. * @param $id
  2098. * @param $title
  2099. *
  2100. * @return string
  2101. */
  2102. private static function getHtmlForUserCategory($id, $title)
  2103. {
  2104. if ($id == 0) {
  2105. return '';
  2106. }
  2107. $icon = Display::return_icon(
  2108. 'folder_yellow.png',
  2109. $title,
  2110. ['class' => 'sessionView'],
  2111. ICON_SIZE_LARGE
  2112. );
  2113. return "<div class='session-view-user-category'>$icon<span>$title</span></div>";
  2114. }
  2115. /**
  2116. * return HTML code for course display in session view.
  2117. *
  2118. * @param array $courseInfo
  2119. * @param $userCategoryId
  2120. * @param bool $displayButton
  2121. * @param $loadDirs
  2122. *
  2123. * @return string
  2124. */
  2125. private static function getHtmlForCourse(
  2126. $courseInfo,
  2127. $userCategoryId,
  2128. $displayButton = false,
  2129. $loadDirs
  2130. ) {
  2131. if (empty($courseInfo)) {
  2132. return '';
  2133. }
  2134. $id = $courseInfo['real_id'];
  2135. $title = $courseInfo['title'];
  2136. $code = $courseInfo['code'];
  2137. $class = 'session-view-lvl-6';
  2138. if ($userCategoryId != 0 && !$displayButton) {
  2139. $class = 'session-view-lvl-7';
  2140. }
  2141. $class2 = 'session-view-lvl-6';
  2142. if ($displayButton || $userCategoryId != 0) {
  2143. $class2 = 'session-view-lvl-7';
  2144. }
  2145. $button = '';
  2146. if ($displayButton) {
  2147. $button = '<input id="session-view-button-'.intval(
  2148. $id
  2149. ).'" class="btn btn-default btn-sm" type="button" onclick="hideUnhide(\'courseblock-'.intval(
  2150. $id
  2151. ).'\', \'session-view-button-'.intval($id).'\', \'+\', \'-\')" value="+" />';
  2152. }
  2153. $icon = Display::return_icon(
  2154. 'blackboard.png',
  2155. $title,
  2156. ['class' => 'sessionView'],
  2157. ICON_SIZE_LARGE
  2158. );
  2159. $courseLink = $courseInfo['course_public_url'].'?id_session=0';
  2160. // get html course params
  2161. $courseParams = CourseManager::getCourseParamsForDisplay($id, $loadDirs);
  2162. $teachers = '';
  2163. $rightActions = '';
  2164. // teacher list
  2165. if (!empty($courseParams['teachers'])) {
  2166. $teachers = '<p class="'.$class2.' view-by-session-teachers">'.$courseParams['teachers'].'</p>';
  2167. }
  2168. // notification
  2169. if (!empty($courseParams['right_actions'])) {
  2170. $rightActions = '<div class="pull-right">'.$courseParams['right_actions'].'</div>';
  2171. }
  2172. $notifications = isset($courseParams['notifications']) ? $courseParams['notifications'] : '';
  2173. return "<div>
  2174. $button
  2175. <span class='$class'>$icon
  2176. <a class='sessionView' href='$courseLink'>$title</a>
  2177. </span>
  2178. $notifications
  2179. $rightActions
  2180. </div>
  2181. $teachers";
  2182. }
  2183. /**
  2184. * return HTML code for session category.
  2185. *
  2186. * @param $id
  2187. * @param $title
  2188. *
  2189. * @return string
  2190. */
  2191. private static function getHtmlSessionCategory($id, $title)
  2192. {
  2193. if ($id == 0) {
  2194. return '';
  2195. }
  2196. $icon = Display::return_icon(
  2197. 'folder_blue.png',
  2198. $title,
  2199. ['class' => 'sessionView'],
  2200. ICON_SIZE_LARGE
  2201. );
  2202. return "<div class='session-view-session-category'>
  2203. <span class='session-view-lvl-2'>
  2204. $icon
  2205. <span>$title</span>
  2206. </span>
  2207. </div>";
  2208. }
  2209. /**
  2210. * return HTML code for session.
  2211. *
  2212. * @param int $id session id
  2213. * @param string $title session title
  2214. * @param int $categorySessionId
  2215. * @param array $courseInfo
  2216. *
  2217. * @return string
  2218. */
  2219. private static function getHtmlForSession($id, $title, $categorySessionId, $courseInfo)
  2220. {
  2221. $html = '';
  2222. if ($categorySessionId == 0) {
  2223. $class1 = 'session-view-lvl-2'; // session
  2224. $class2 = 'session-view-lvl-4'; // got to course in session link
  2225. } else {
  2226. $class1 = 'session-view-lvl-3'; // session
  2227. $class2 = 'session-view-lvl-5'; // got to course in session link
  2228. }
  2229. $icon = Display::return_icon(
  2230. 'session.png',
  2231. $title,
  2232. ['class' => 'sessionView'],
  2233. ICON_SIZE_LARGE
  2234. );
  2235. $courseLink = $courseInfo['course_public_url'].'?id_session='.intval($id);
  2236. $html .= "<span class='$class1 session-view-session'>$icon$title</span>";
  2237. $html .= '<div class="'.$class2.' session-view-session-go-to-course-in-session">
  2238. <a class="" href="'.$courseLink.'">'.get_lang('GoToCourseInsideSession').'</a></div>';
  2239. return '<div>'.$html.'</div>';
  2240. }
  2241. /**
  2242. * @param $listA
  2243. * @param $listB
  2244. *
  2245. * @return int
  2246. */
  2247. private static function compareByCourse($listA, $listB)
  2248. {
  2249. if ($listA['userCatTitle'] == $listB['userCatTitle']) {
  2250. if ($listA['title'] == $listB['title']) {
  2251. return 0;
  2252. }
  2253. if ($listA['title'] > $listB['title']) {
  2254. return 1;
  2255. }
  2256. return -1;
  2257. }
  2258. if ($listA['userCatTitle'] > $listB['userCatTitle']) {
  2259. return 1;
  2260. }
  2261. return -1;
  2262. }
  2263. /**
  2264. * Get the session coach name, duration or dates
  2265. * when $_configuration['show_simple_session_info'] is enabled.
  2266. *
  2267. * @param string $coachName
  2268. * @param string $dates
  2269. * @param string|null $duration Optional
  2270. *
  2271. * @return string
  2272. */
  2273. private static function getSimpleSessionDetails($coachName, $dates, $duration = null)
  2274. {
  2275. $strDetails = [];
  2276. if (!empty($coachName)) {
  2277. $strDetails[] = $coachName;
  2278. }
  2279. $strDetails[] = !empty($duration) ? $duration : $dates;
  2280. return implode(' | ', $strDetails);
  2281. }
  2282. /**
  2283. * Filter the course list by category code.
  2284. *
  2285. * @param array $courseList course list
  2286. * @param string $categoryCode
  2287. *
  2288. * @return array
  2289. */
  2290. private static function filterByCategory($courseList, $categoryCode)
  2291. {
  2292. return array_filter(
  2293. $courseList,
  2294. function ($courseInfo) use ($categoryCode) {
  2295. if (isset($courseInfo['category_code']) &&
  2296. $courseInfo['category_code'] === $categoryCode
  2297. ) {
  2298. return true;
  2299. }
  2300. return false;
  2301. }
  2302. );
  2303. }
  2304. }