userportal.lib.php 109 KB

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