userportal.lib.php 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538
  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. $isHrm = api_is_drh();
  923. $show_create_link = false;
  924. $show_course_link = false;
  925. if (api_is_allowed_to_create_course()) {
  926. $show_create_link = true;
  927. }
  928. if (api_get_setting('allow_students_to_browse_courses') === 'true') {
  929. $show_course_link = true;
  930. }
  931. $items = [];
  932. // My account section
  933. if ($show_create_link) {
  934. if (api_get_setting('course_validation') == 'true' && !api_is_platform_admin()) {
  935. $items[] = [
  936. 'class' => 'add-course',
  937. 'icon' => Display::return_icon('new-course.png', get_lang('CreateCourseRequest')),
  938. 'link' => 'main/create_course/add_course.php',
  939. 'title' => get_lang('CreateCourseRequest'),
  940. ];
  941. } else {
  942. $items[] = [
  943. 'class' => 'add-course',
  944. 'icon' => Display::return_icon('new-course.png', get_lang('CourseCreate')),
  945. 'link' => 'main/create_course/add_course.php',
  946. 'title' => get_lang('CourseCreate'),
  947. ];
  948. }
  949. if (SessionManager::allowToManageSessions()) {
  950. $items[] = [
  951. 'class' => 'add-session',
  952. 'icon' => Display::return_icon('session.png', get_lang('AddSession')),
  953. 'link' => 'main/session/session_add.php',
  954. 'title' => get_lang('AddSession'),
  955. ];
  956. }
  957. }
  958. // Sort courses
  959. if (api_get_configuration_value('view_grid_courses') != true) {
  960. $items[] = [
  961. 'class' => 'order-course',
  962. 'icon' => Display::return_icon('order-course.png', get_lang('SortMyCourses')),
  963. 'link' => api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses',
  964. 'title' => get_lang('SortMyCourses'),
  965. ];
  966. }
  967. // Session history
  968. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  969. $items[] = [
  970. 'class' => 'history-course',
  971. 'icon' => Display::return_icon('history-course.png', get_lang('DisplayTrainingList')),
  972. 'link' => 'user_portal.php',
  973. 'title' => get_lang('DisplayTrainingList'),
  974. ];
  975. } else {
  976. $items[] = [
  977. 'class' => 'history-course',
  978. 'icon' => Display::return_icon('history-course.png', get_lang('HistoryTrainingSessions')),
  979. 'link' => 'user_portal.php?history=1',
  980. 'title' => get_lang('HistoryTrainingSessions'),
  981. ];
  982. }
  983. if ($isHrm) {
  984. $items[] = [
  985. 'link' => api_get_path(WEB_CODE_PATH).'auth/hrm_courses.php',
  986. 'title' => get_lang('HrmAssignedUsersCourseList'),
  987. ];
  988. }
  989. // Course catalog
  990. if ($show_course_link) {
  991. if (!api_is_drh()) {
  992. $items[] = [
  993. 'class' => 'list-course',
  994. 'icon' => Display::return_icon('catalog-course.png', get_lang('CourseCatalog')),
  995. 'link' => 'main/auth/courses.php',
  996. 'title' => get_lang('CourseCatalog'),
  997. ];
  998. } else {
  999. $items[] = [
  1000. 'link' => 'main/dashboard/index.php',
  1001. 'title' => get_lang('Dashboard'),
  1002. ];
  1003. }
  1004. }
  1005. return $items;
  1006. }
  1007. /**
  1008. * Prints the session and course list (user_portal.php).
  1009. *
  1010. * @param int $user_id
  1011. * @param bool $showSessions
  1012. * @param string $categoryCodeFilter
  1013. * @param bool $useUserLanguageFilterIfAvailable
  1014. * @param bool $loadHistory
  1015. *
  1016. * @return array
  1017. */
  1018. public function returnCoursesAndSessions(
  1019. $user_id,
  1020. $showSessions = true,
  1021. $categoryCodeFilter = '',
  1022. $useUserLanguageFilterIfAvailable = true,
  1023. $loadHistory = false
  1024. ) {
  1025. $gameModeIsActive = api_get_setting('gamification_mode');
  1026. $viewGridCourses = api_get_configuration_value('view_grid_courses') === true;
  1027. $showSimpleSessionInfo = api_get_configuration_value('show_simple_session_info');
  1028. $coursesWithoutCategoryTemplate = '/user_portal/classic_courses_without_category.tpl';
  1029. $coursesWithCategoryTemplate = '/user_portal/classic_courses_with_category.tpl';
  1030. $showAllSessions = api_get_configuration_value('show_all_sessions_on_my_course_page') === true;
  1031. if ($loadHistory) {
  1032. // Load sessions in category in *history*
  1033. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1034. } else {
  1035. // Load sessions in category
  1036. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1037. }
  1038. $sessionCount = 0;
  1039. $courseCount = 0;
  1040. // Student info code check (shows student progress information on
  1041. // courses list
  1042. $studentInfo = api_get_configuration_value('course_student_info');
  1043. $viewGrid = api_get_configuration_value('view_grid_courses');
  1044. $studentInfoProgress = !empty($studentInfo['progress']) && $studentInfo['progress'] === true;
  1045. $studentInfoScore = !empty($studentInfo['score']) && $studentInfo['score'] === true;
  1046. $studentInfoCertificate = !empty($studentInfo['certificate']) && $studentInfo['certificate'] === true;
  1047. $courseCompleteList = [];
  1048. $coursesInCategoryCount = 0;
  1049. $coursesNotInCategoryCount = 0;
  1050. $listCourse = '';
  1051. $specialCourseList = '';
  1052. // If we're not in the history view...
  1053. if ($loadHistory == false) {
  1054. // Display special courses.
  1055. $specialCourses = CourseManager::returnSpecialCourses(
  1056. $user_id,
  1057. $this->load_directories_preview,
  1058. $useUserLanguageFilterIfAvailable
  1059. );
  1060. // Display courses.
  1061. $courses = CourseManager::returnCourses(
  1062. $user_id,
  1063. $this->load_directories_preview,
  1064. $useUserLanguageFilterIfAvailable
  1065. );
  1066. // Course option (show student progress)
  1067. // This code will add new variables (Progress, Score, Certificate)
  1068. if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) {
  1069. if (!empty($specialCourses)) {
  1070. foreach ($specialCourses as $key => $specialCourseInfo) {
  1071. if ($studentInfoProgress) {
  1072. $progress = Tracking::get_avg_student_progress(
  1073. $user_id,
  1074. $specialCourseInfo['course_code']
  1075. );
  1076. $specialCourses[$key]['student_info']['progress'] = $progress === false ? null : $progress;
  1077. }
  1078. if ($studentInfoScore) {
  1079. $percentage_score = Tracking::get_avg_student_score(
  1080. $user_id,
  1081. $specialCourseInfo['course_code'],
  1082. []
  1083. );
  1084. $specialCourses[$key]['student_info']['score'] = $percentage_score;
  1085. }
  1086. if ($studentInfoCertificate) {
  1087. $category = Category::load(
  1088. null,
  1089. null,
  1090. $specialCourseInfo['course_code'],
  1091. null,
  1092. null,
  1093. null
  1094. );
  1095. $specialCourses[$key]['student_info']['certificate'] = null;
  1096. if (isset($category[0])) {
  1097. if ($category[0]->is_certificate_available($user_id)) {
  1098. $specialCourses[$key]['student_info']['certificate'] = Display::label(
  1099. get_lang('Yes'),
  1100. 'success'
  1101. );
  1102. } else {
  1103. $specialCourses[$key]['student_info']['certificate'] = Display::label(
  1104. get_lang('No'),
  1105. 'danger'
  1106. );
  1107. }
  1108. }
  1109. }
  1110. }
  1111. }
  1112. if (isset($courses['in_category'])) {
  1113. foreach ($courses['in_category'] as $key1 => $value) {
  1114. if (isset($courses['in_category'][$key1]['courses'])) {
  1115. foreach ($courses['in_category'][$key1]['courses'] as $key2 => $courseInCatInfo) {
  1116. if ($studentInfoProgress) {
  1117. $progress = Tracking::get_avg_student_progress(
  1118. $user_id,
  1119. $courseInCatInfo['course_code']
  1120. );
  1121. $courses['in_category'][$key1]['courses'][$key2]['student_info']['progress'] = $progress === false ? null : $progress;
  1122. }
  1123. if ($studentInfoScore) {
  1124. $percentage_score = Tracking::get_avg_student_score(
  1125. $user_id,
  1126. $specialCourseInfo['course_code'],
  1127. []
  1128. );
  1129. $courses['in_category'][$key1]['courses'][$key2]['student_info']['score'] = $percentage_score;
  1130. }
  1131. if ($studentInfoCertificate) {
  1132. $category = Category::load(
  1133. null,
  1134. null,
  1135. $courseInCatInfo['course_code'],
  1136. null,
  1137. null,
  1138. null
  1139. );
  1140. $courses['in_category'][$key1]['student_info']['certificate'] = null;
  1141. $isCertificateAvailable = $category[0]->is_certificate_available($user_id);
  1142. if (isset($category[0])) {
  1143. if ($viewGrid) {
  1144. if ($isCertificateAvailable) {
  1145. $courses['in_category'][$key1]['student_info']['certificate'] = get_lang(
  1146. 'Yes'
  1147. );
  1148. } else {
  1149. $courses['in_category'][$key1]['student_info']['certificate'] = get_lang(
  1150. 'No'
  1151. );
  1152. }
  1153. } else {
  1154. if ($isCertificateAvailable) {
  1155. $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
  1156. get_lang('Yes'),
  1157. 'success'
  1158. );
  1159. } else {
  1160. $courses['in_category'][$key1]['student_info']['certificate'] = Display::label(
  1161. get_lang('No'),
  1162. 'danger'
  1163. );
  1164. }
  1165. }
  1166. }
  1167. }
  1168. }
  1169. }
  1170. }
  1171. }
  1172. if (isset($courses['not_category'])) {
  1173. foreach ($courses['not_category'] as $key => $courseNotInCatInfo) {
  1174. if ($studentInfoProgress) {
  1175. $progress = Tracking::get_avg_student_progress(
  1176. $user_id,
  1177. $courseNotInCatInfo['course_code']
  1178. );
  1179. $courses['not_category'][$key]['student_info']['progress'] = $progress === false ? null : $progress;
  1180. }
  1181. if ($studentInfoScore) {
  1182. $percentage_score = Tracking::get_avg_student_score(
  1183. $user_id,
  1184. $courseNotInCatInfo['course_code'],
  1185. []
  1186. );
  1187. $courses['not_category'][$key]['student_info']['score'] = $percentage_score;
  1188. }
  1189. if ($studentInfoCertificate) {
  1190. $category = Category::load(
  1191. null,
  1192. null,
  1193. $courseNotInCatInfo['course_code'],
  1194. null,
  1195. null,
  1196. null
  1197. );
  1198. $courses['not_category'][$key]['student_info']['certificate'] = null;
  1199. if (isset($category[0])) {
  1200. $certificateAvailable = $category[0]->is_certificate_available($user_id);
  1201. if ($viewGrid) {
  1202. if ($certificateAvailable) {
  1203. $courses['not_category'][$key]['student_info']['certificate'] = get_lang('Yes');
  1204. } else {
  1205. $courses['not_category'][$key]['student_info']['certificate'] = get_lang('No');
  1206. }
  1207. } else {
  1208. if ($certificateAvailable) {
  1209. $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
  1210. get_lang('Yes'),
  1211. 'success'
  1212. );
  1213. } else {
  1214. $courses['not_category'][$key]['student_info']['certificate'] = Display::label(
  1215. get_lang('No'),
  1216. 'danger'
  1217. );
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }
  1223. }
  1224. }
  1225. if ($viewGridCourses) {
  1226. $coursesWithoutCategoryTemplate = '/user_portal/grid_courses_without_category.tpl';
  1227. $coursesWithCategoryTemplate = '/user_portal/grid_courses_with_category.tpl';
  1228. }
  1229. if ($specialCourses) {
  1230. if ($categoryCodeFilter) {
  1231. $specialCourses = self::filterByCategory($specialCourses, $categoryCodeFilter);
  1232. }
  1233. $this->tpl->assign('courses', $specialCourses);
  1234. $specialCourseList = $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate));
  1235. $courseCompleteList = array_merge($courseCompleteList, $specialCourses);
  1236. }
  1237. if ($courses['in_category'] || $courses['not_category']) {
  1238. foreach ($courses['in_category'] as $courseData) {
  1239. if (!empty($courseData['courses'])) {
  1240. $coursesInCategoryCount += count($courseData['courses']);
  1241. $courseCompleteList = array_merge($courseCompleteList, $courseData['courses']);
  1242. }
  1243. }
  1244. $coursesNotInCategoryCount += count($courses['not_category']);
  1245. $courseCompleteList = array_merge($courseCompleteList, $courses['not_category']);
  1246. if ($categoryCodeFilter) {
  1247. $courses['in_category'] = self::filterByCategory(
  1248. $courses['in_category'],
  1249. $categoryCodeFilter
  1250. );
  1251. $courses['not_category'] = self::filterByCategory(
  1252. $courses['not_category'],
  1253. $categoryCodeFilter
  1254. );
  1255. }
  1256. $this->tpl->assign('courses', $courses['not_category']);
  1257. $this->tpl->assign('categories', $courses['in_category']);
  1258. $listCourse = $this->tpl->fetch($this->tpl->get_template($coursesWithCategoryTemplate));
  1259. $listCourse .= $this->tpl->fetch($this->tpl->get_template($coursesWithoutCategoryTemplate));
  1260. }
  1261. $courseCount = count($specialCourses) + $coursesInCategoryCount + $coursesNotInCategoryCount;
  1262. }
  1263. $sessions_with_category = '';
  1264. $sessions_with_no_category = '';
  1265. $collapsable = api_get_configuration_value('allow_user_session_collapsable');
  1266. $collapsableLink = '';
  1267. if ($collapsable) {
  1268. $collapsableLink = api_get_path(WEB_PATH).'user_portal.php?action=collapse_session';
  1269. }
  1270. $extraFieldValue = new ExtraFieldValue('session');
  1271. if ($showSessions) {
  1272. $coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link');
  1273. $coursesListSessionStyle = $coursesListSessionStyle === false ? 1 : $coursesListSessionStyle;
  1274. if (api_is_drh()) {
  1275. $coursesListSessionStyle = 1;
  1276. }
  1277. $portalShowDescription = api_get_setting('show_session_description') === 'true';
  1278. // Declared listSession variable
  1279. $listSession = [];
  1280. // Get timestamp in UTC to compare to DB values (in UTC by convention)
  1281. $session_now = strtotime(api_get_utc_datetime(time()));
  1282. if (is_array($session_categories)) {
  1283. foreach ($session_categories as $session_category) {
  1284. $session_category_id = $session_category['session_category']['id'];
  1285. // Sessions and courses that are not in a session category
  1286. if (empty($session_category_id) &&
  1287. isset($session_category['sessions'])
  1288. ) {
  1289. // Independent sessions
  1290. foreach ($session_category['sessions'] as $session) {
  1291. $session_id = $session['session_id'];
  1292. // Don't show empty sessions.
  1293. if (count($session['courses']) < 1) {
  1294. continue;
  1295. }
  1296. // Courses inside the current session.
  1297. $date_session_start = $session['access_start_date'];
  1298. $date_session_end = $session['access_end_date'];
  1299. $coachAccessStartDate = $session['coach_access_start_date'];
  1300. $coachAccessEndDate = $session['coach_access_end_date'];
  1301. $count_courses_session = 0;
  1302. // Loop course content
  1303. $html_courses_session = [];
  1304. $atLeastOneCourseIsVisible = false;
  1305. $markAsOld = false;
  1306. $markAsFuture = false;
  1307. foreach ($session['courses'] as $course) {
  1308. $is_coach_course = api_is_coach($session_id, $course['real_id']);
  1309. $allowed_time = 0;
  1310. $allowedEndTime = true;
  1311. if (!empty($date_session_start)) {
  1312. if ($is_coach_course) {
  1313. $allowed_time = api_strtotime($coachAccessStartDate);
  1314. } else {
  1315. $allowed_time = api_strtotime($date_session_start);
  1316. }
  1317. $endSessionToTms = null;
  1318. if (!isset($_GET['history'])) {
  1319. if (!empty($date_session_end)) {
  1320. if ($is_coach_course) {
  1321. // if coach end date is empty we use the default end date
  1322. if (empty($coachAccessEndDate)) {
  1323. $endSessionToTms = api_strtotime($date_session_end);
  1324. if ($session_now > $endSessionToTms) {
  1325. $allowedEndTime = false;
  1326. }
  1327. } else {
  1328. $endSessionToTms = api_strtotime($coachAccessEndDate);
  1329. if ($session_now > $endSessionToTms) {
  1330. $allowedEndTime = false;
  1331. }
  1332. }
  1333. } else {
  1334. $endSessionToTms = api_strtotime($date_session_end);
  1335. if ($session_now > $endSessionToTms) {
  1336. $allowedEndTime = false;
  1337. }
  1338. }
  1339. }
  1340. }
  1341. }
  1342. if ($showAllSessions) {
  1343. if ($allowed_time < $session_now && $allowedEndTime === false) {
  1344. $markAsOld = true;
  1345. }
  1346. if ($allowed_time > $session_now && $endSessionToTms > $session_now) {
  1347. $markAsFuture = true;
  1348. }
  1349. $allowedEndTime = true;
  1350. $allowed_time = 0;
  1351. }
  1352. if ($session_now >= $allowed_time && $allowedEndTime) {
  1353. // Read only and accessible.
  1354. $atLeastOneCourseIsVisible = true;
  1355. if (api_get_setting('hide_courses_in_sessions') === 'false') {
  1356. $courseUserHtml = CourseManager::get_logged_user_course_html(
  1357. $course,
  1358. $session_id,
  1359. 'session_course_item',
  1360. true,
  1361. $this->load_directories_preview
  1362. );
  1363. if (isset($courseUserHtml[1])) {
  1364. $course_session = $courseUserHtml[1];
  1365. $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
  1366. // Course option (show student progress)
  1367. // This code will add new variables (Progress, Score, Certificate)
  1368. if ($studentInfoProgress || $studentInfoScore || $studentInfoCertificate) {
  1369. if ($studentInfoProgress) {
  1370. $progress = Tracking::get_avg_student_progress(
  1371. $user_id,
  1372. $course['course_code'],
  1373. [],
  1374. $session_id
  1375. );
  1376. $course_session['student_info']['progress'] = $progress === false ? null : $progress;
  1377. }
  1378. if ($studentInfoScore) {
  1379. $percentage_score = Tracking::get_avg_student_score(
  1380. $user_id,
  1381. $course['course_code'],
  1382. [],
  1383. $session_id
  1384. );
  1385. $course_session['student_info']['score'] = $percentage_score;
  1386. }
  1387. if ($studentInfoCertificate) {
  1388. $category = Category::load(
  1389. null,
  1390. null,
  1391. $course['course_code'],
  1392. null,
  1393. null,
  1394. $session_id
  1395. );
  1396. $course_session['student_info']['certificate'] = null;
  1397. if (isset($category[0])) {
  1398. if ($category[0]->is_certificate_available($user_id)) {
  1399. $course_session['student_info']['certificate'] = Display::label(
  1400. get_lang('Yes'),
  1401. 'success'
  1402. );
  1403. } else {
  1404. $course_session['student_info']['certificate'] = Display::label(
  1405. get_lang('No')
  1406. );
  1407. }
  1408. }
  1409. }
  1410. }
  1411. $html_courses_session[] = $course_session;
  1412. }
  1413. }
  1414. $count_courses_session++;
  1415. }
  1416. }
  1417. // No courses to show.
  1418. if ($atLeastOneCourseIsVisible === false) {
  1419. if (empty($html_courses_session)) {
  1420. continue;
  1421. }
  1422. }
  1423. if ($count_courses_session > 0) {
  1424. $params = [
  1425. 'id' => $session_id,
  1426. ];
  1427. $session_box = Display::getSessionTitleBox($session_id);
  1428. $coachId = $session_box['id_coach'];
  1429. $imageField = $extraFieldValue->get_values_by_handler_and_field_variable(
  1430. $session_id,
  1431. 'image'
  1432. );
  1433. $params['category_id'] = $session_box['category_id'];
  1434. $params['title'] = $session_box['title'];
  1435. $params['id_coach'] = $coachId;
  1436. $params['coach_url'] = api_get_path(WEB_AJAX_PATH).
  1437. 'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId;
  1438. $params['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
  1439. $params['coach_avatar'] = UserManager::getUserPicture(
  1440. $coachId,
  1441. USER_IMAGE_SIZE_SMALL
  1442. );
  1443. $params['date'] = $session_box['dates'];
  1444. $params['image'] = isset($imageField['value']) ? $imageField['value'] : null;
  1445. $params['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
  1446. $params['show_actions'] = SessionManager::cantEditSession($session_id);
  1447. if ($collapsable) {
  1448. $collapsableData = SessionManager::getCollapsableData(
  1449. $user_id,
  1450. $session_id,
  1451. $extraFieldValue,
  1452. $collapsableLink
  1453. );
  1454. $params['collapsed'] = $collapsableData['collapsed'];
  1455. $params['collapsable_link'] = $collapsableData['collapsable_link'];
  1456. }
  1457. $params['show_description'] = $session_box['show_description'] == 1 && $portalShowDescription;
  1458. $params['description'] = $session_box['description'];
  1459. $params['visibility'] = $session_box['visibility'];
  1460. $params['show_simple_session_info'] = $showSimpleSessionInfo;
  1461. $params['course_list_session_style'] = $coursesListSessionStyle;
  1462. $params['num_users'] = $session_box['num_users'];
  1463. $params['num_courses'] = $session_box['num_courses'];
  1464. $params['course_categories'] = CourseManager::getCourseCategoriesFromCourseList(
  1465. $html_courses_session
  1466. );
  1467. $params['courses'] = $html_courses_session;
  1468. $params['is_old'] = $markAsOld;
  1469. $params['is_future'] = $markAsFuture;
  1470. if ($showSimpleSessionInfo) {
  1471. $params['subtitle'] = self::getSimpleSessionDetails(
  1472. $session_box['coach'],
  1473. $session_box['dates'],
  1474. isset($session_box['duration']) ? $session_box['duration'] : null
  1475. );
  1476. }
  1477. if ($gameModeIsActive) {
  1478. $params['stars'] = GamificationUtils::getSessionStars(
  1479. $params['id'],
  1480. $this->user_id
  1481. );
  1482. $params['progress'] = GamificationUtils::getSessionProgress(
  1483. $params['id'],
  1484. $this->user_id
  1485. );
  1486. $params['points'] = GamificationUtils::getSessionPoints(
  1487. $params['id'],
  1488. $this->user_id
  1489. );
  1490. }
  1491. $listSession[] = $params;
  1492. $sessionCount++;
  1493. }
  1494. }
  1495. } else {
  1496. // All sessions included in
  1497. $count_courses_session = 0;
  1498. $html_sessions = '';
  1499. if (isset($session_category['sessions'])) {
  1500. foreach ($session_category['sessions'] as $session) {
  1501. $session_id = $session['session_id'];
  1502. // Don't show empty sessions.
  1503. if (count($session['courses']) < 1) {
  1504. continue;
  1505. }
  1506. $date_session_start = $session['access_start_date'];
  1507. $date_session_end = $session['access_end_date'];
  1508. $coachAccessStartDate = $session['coach_access_start_date'];
  1509. $coachAccessEndDate = $session['coach_access_end_date'];
  1510. $html_courses_session = [];
  1511. $count = 0;
  1512. $markAsOld = false;
  1513. $markAsFuture = false;
  1514. foreach ($session['courses'] as $course) {
  1515. $is_coach_course = api_is_coach($session_id, $course['real_id']);
  1516. $allowed_time = 0;
  1517. $allowedEndTime = true;
  1518. if (!empty($date_session_start)) {
  1519. if ($is_coach_course) {
  1520. $allowed_time = api_strtotime($coachAccessStartDate);
  1521. } else {
  1522. $allowed_time = api_strtotime($date_session_start);
  1523. }
  1524. if (!isset($_GET['history'])) {
  1525. if (!empty($date_session_end)) {
  1526. if ($is_coach_course) {
  1527. // if coach end date is empty we use the default end date
  1528. if (empty($coachAccessEndDate)) {
  1529. $endSessionToTms = api_strtotime($date_session_end);
  1530. if ($session_now > $endSessionToTms) {
  1531. $allowedEndTime = false;
  1532. }
  1533. } else {
  1534. $endSessionToTms = api_strtotime($coachAccessEndDate);
  1535. if ($session_now > $endSessionToTms) {
  1536. $allowedEndTime = false;
  1537. }
  1538. }
  1539. } else {
  1540. $endSessionToTms = api_strtotime($date_session_end);
  1541. if ($session_now > $endSessionToTms) {
  1542. $allowedEndTime = false;
  1543. }
  1544. }
  1545. }
  1546. }
  1547. }
  1548. if ($showAllSessions) {
  1549. if ($allowed_time < $session_now && $allowedEndTime == false) {
  1550. $markAsOld = true;
  1551. }
  1552. if ($allowed_time > $session_now && $endSessionToTms > $session_now) {
  1553. $markAsFuture = true;
  1554. }
  1555. $allowedEndTime = true;
  1556. $allowed_time = 0;
  1557. }
  1558. if ($session_now >= $allowed_time && $allowedEndTime) {
  1559. if (api_get_setting('hide_courses_in_sessions') === 'false') {
  1560. $c = CourseManager::get_logged_user_course_html(
  1561. $course,
  1562. $session_id,
  1563. 'session_course_item'
  1564. );
  1565. if (isset($c[1])) {
  1566. $html_courses_session[] = $c[1];
  1567. }
  1568. }
  1569. $count_courses_session++;
  1570. $count++;
  1571. }
  1572. }
  1573. $sessionParams = [];
  1574. // Category
  1575. if ($count > 0) {
  1576. $session_box = Display::getSessionTitleBox($session_id);
  1577. $sessionParams[0]['id'] = $session_id;
  1578. $sessionParams[0]['date'] = $session_box['dates'];
  1579. $sessionParams[0]['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
  1580. $sessionParams[0]['course_list_session_style'] = $coursesListSessionStyle;
  1581. $sessionParams[0]['title'] = $session_box['title'];
  1582. $sessionParams[0]['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
  1583. $sessionParams[0]['show_actions'] = SessionManager::cantEditSession($session_id);
  1584. $sessionParams[0]['courses'] = $html_courses_session;
  1585. $sessionParams[0]['show_simple_session_info'] = $showSimpleSessionInfo;
  1586. $sessionParams[0]['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
  1587. $sessionParams[0]['is_old'] = $markAsOld;
  1588. $sessionParams[0]['is_future'] = $markAsFuture;
  1589. if ($collapsable) {
  1590. $collapsableData = SessionManager::getCollapsableData(
  1591. $user_id,
  1592. $session_id,
  1593. $extraFieldValue,
  1594. $collapsableLink
  1595. );
  1596. $sessionParams[0]['collapsable_link'] = $collapsableData['collapsable_link'];
  1597. $sessionParams[0]['collapsed'] = $collapsableData['collapsed'];
  1598. }
  1599. if ($showSimpleSessionInfo) {
  1600. $sessionParams[0]['subtitle'] = self::getSimpleSessionDetails(
  1601. $session_box['coach'],
  1602. $session_box['dates'],
  1603. isset($session_box['duration']) ? $session_box['duration'] : null
  1604. );
  1605. }
  1606. $this->tpl->assign('session', $sessionParams);
  1607. if ($viewGridCourses) {
  1608. $html_sessions .= $this->tpl->fetch(
  1609. $this->tpl->get_template('/user_portal/grid_session.tpl')
  1610. );
  1611. } else {
  1612. $html_sessions .= $this->tpl->fetch(
  1613. $this->tpl->get_template('user_portal/classic_session.tpl')
  1614. );
  1615. }
  1616. $sessionCount++;
  1617. }
  1618. }
  1619. }
  1620. if ($count_courses_session > 0) {
  1621. $categoryParams = [
  1622. 'id' => $session_category['session_category']['id'],
  1623. 'title' => $session_category['session_category']['name'],
  1624. 'show_actions' => api_is_platform_admin(),
  1625. 'subtitle' => '',
  1626. 'sessions' => $html_sessions,
  1627. ];
  1628. $session_category_start_date = $session_category['session_category']['date_start'];
  1629. $session_category_end_date = $session_category['session_category']['date_end'];
  1630. if ($session_category_start_date == '0000-00-00') {
  1631. $session_category_start_date = '';
  1632. }
  1633. if ($session_category_end_date == '0000-00-00') {
  1634. $session_category_end_date = '';
  1635. }
  1636. if (!empty($session_category_start_date) &&
  1637. !empty($session_category_end_date)
  1638. ) {
  1639. $categoryParams['subtitle'] = sprintf(
  1640. get_lang('FromDateXToDateY'),
  1641. $session_category_start_date,
  1642. $session_category_end_date
  1643. );
  1644. } else {
  1645. if (!empty($session_category_start_date)) {
  1646. $categoryParams['subtitle'] = get_lang('From').' '.$session_category_start_date;
  1647. }
  1648. if (!empty($session_category_end_date)) {
  1649. $categoryParams['subtitle'] = get_lang('Until').' '.$session_category_end_date;
  1650. }
  1651. }
  1652. $this->tpl->assign('session_category', $categoryParams);
  1653. $sessions_with_category .= $this->tpl->fetch(
  1654. $this->tpl->get_template('user_portal/session_category.tpl')
  1655. );
  1656. }
  1657. }
  1658. }
  1659. $allCoursesInSessions = [];
  1660. foreach ($listSession as $currentSession) {
  1661. $coursesInSessions = $currentSession['courses'];
  1662. unset($currentSession['courses']);
  1663. foreach ($coursesInSessions as $coursesInSession) {
  1664. $coursesInSession['session'] = $currentSession;
  1665. $allCoursesInSessions[] = $coursesInSession;
  1666. }
  1667. }
  1668. $this->tpl->assign('all_courses', $allCoursesInSessions);
  1669. $this->tpl->assign('session', $listSession);
  1670. $this->tpl->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false));
  1671. $this->tpl->assign('gamification_mode', $gameModeIsActive);
  1672. $this->tpl->assign('remove_session_url', api_get_configuration_value('remove_session_url'));
  1673. if ($viewGridCourses) {
  1674. $sessions_with_no_category = $this->tpl->fetch(
  1675. $this->tpl->get_template('/user_portal/grid_session.tpl')
  1676. );
  1677. } else {
  1678. $sessions_with_no_category = $this->tpl->fetch(
  1679. $this->tpl->get_template('user_portal/classic_session.tpl')
  1680. );
  1681. }
  1682. }
  1683. }
  1684. return [
  1685. 'courses' => $courseCompleteList,
  1686. 'sessions' => $session_categories,
  1687. 'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse),
  1688. 'session_count' => $sessionCount,
  1689. 'course_count' => $courseCount,
  1690. ];
  1691. }
  1692. /**
  1693. * Shows a welcome message when the user doesn't have any content in the course list.
  1694. */
  1695. public function return_welcome_to_course_block()
  1696. {
  1697. $count_courses = CourseManager::count_courses();
  1698. $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
  1699. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  1700. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  1701. $this->tpl->assign('course_catalog_url', $course_catalog_url);
  1702. $this->tpl->assign('course_list_url', $course_list_url);
  1703. $this->tpl->assign('course_catalog_link', Display::url(get_lang('Here'), $course_catalog_url));
  1704. $this->tpl->assign('course_list_link', Display::url(get_lang('Here'), $course_list_url));
  1705. $this->tpl->assign('count_courses', $count_courses);
  1706. return $this->tpl->fetch($tpl);
  1707. }
  1708. /**
  1709. * @return array
  1710. */
  1711. public function return_hot_courses()
  1712. {
  1713. return CourseManager::return_hot_courses(30, 6);
  1714. }
  1715. /**
  1716. * UserPortal view for session, return the HTML of the course list.
  1717. *
  1718. * @param $user_id
  1719. *
  1720. * @return string
  1721. */
  1722. public function returnCoursesAndSessionsViewBySession($user_id)
  1723. {
  1724. $sessionCount = 0;
  1725. $courseCount = 0;
  1726. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  1727. if ($load_history) {
  1728. // Load sessions in category in *history*
  1729. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1730. } else {
  1731. // Load sessions in category
  1732. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1733. }
  1734. $html = '';
  1735. $loadDirs = $this->load_directories_preview;
  1736. // If we're not in the history view...
  1737. $listCoursesInfo = [];
  1738. if (!isset($_GET['history'])) {
  1739. // Display special courses
  1740. $specialCoursesResult = CourseManager::returnSpecialCourses(
  1741. $user_id,
  1742. $loadDirs
  1743. );
  1744. $specialCourses = $specialCoursesResult;
  1745. if ($specialCourses) {
  1746. $this->tpl->assign('courses', $specialCourses);
  1747. $html = $this->tpl->fetch(
  1748. $this->tpl->get_template('/user_portal/classic_courses_without_category.tpl')
  1749. );
  1750. }
  1751. // Display courses
  1752. // [code=>xxx, real_id=>000]
  1753. $listCourses = CourseManager::get_courses_list_by_user_id(
  1754. $user_id,
  1755. false
  1756. );
  1757. foreach ($listCourses as $i => $listCourseCodeId) {
  1758. if (isset($listCourseCodeId['special_course'])) {
  1759. continue;
  1760. }
  1761. $courseCategory = CourseManager::getUserCourseCategoryForCourse(
  1762. $user_id,
  1763. $listCourseCodeId['real_id']
  1764. );
  1765. $userCatTitle = '';
  1766. $userCategoryId = 0;
  1767. if ($courseCategory) {
  1768. $userCategoryId = $courseCategory['user_course_cat'];
  1769. $userCatTitle = $courseCategory['title'];
  1770. }
  1771. $listCourse = api_get_course_info_by_id($listCourseCodeId['real_id']);
  1772. $listCoursesInfo[] = [
  1773. 'course' => $listCourse,
  1774. 'code' => $listCourseCodeId['code'],
  1775. 'id' => $listCourseCodeId['real_id'],
  1776. 'title' => $listCourse['title'],
  1777. 'userCatId' => $userCategoryId,
  1778. 'userCatTitle' => $userCatTitle,
  1779. ];
  1780. $courseCount++;
  1781. }
  1782. usort($listCoursesInfo, 'self::compareByCourse');
  1783. }
  1784. $listCoursesInSession = [];
  1785. if (is_array($session_categories)) {
  1786. // all courses that are in a session
  1787. $listCoursesInSession = SessionManager::getNamedSessionCourseForCoach($user_id);
  1788. }
  1789. // we got all courses
  1790. // for each user category, sorted alphabetically, display courses
  1791. $listUserCategories = CourseManager::get_user_course_categories($user_id);
  1792. $listCoursesAlreadyDisplayed = [];
  1793. uasort($listUserCategories, "self::compareListUserCategory");
  1794. $listUserCategories[0] = '';
  1795. $html .= '<div class="session-view-block">';
  1796. foreach ($listUserCategories as $userCategoryId => $userCat) {
  1797. // add user category
  1798. $userCategoryHtml = '';
  1799. if ($userCategoryId != 0) {
  1800. $userCategoryHtml = '<div class="session-view-well ">';
  1801. $userCategoryHtml .= self::getHtmlForUserCategory($userCategoryId, $userCat['title']);
  1802. }
  1803. // look for course in this userCat in session courses : $listCoursesInSession
  1804. $htmlCategory = '';
  1805. if (isset($listCoursesInSession[$userCategoryId])) {
  1806. // list of courses in this user cat
  1807. foreach ($listCoursesInSession[$userCategoryId]['courseInUserCatList'] as $i => $listCourse) {
  1808. // add course
  1809. $listCoursesAlreadyDisplayed[$listCourse['courseId']] = 1;
  1810. if ($userCategoryId == 0) {
  1811. $htmlCategory .= '<div class="panel panel-default">';
  1812. } else {
  1813. $htmlCategory .= '<div class="panel panel-default">';
  1814. }
  1815. $htmlCategory .= '<div class="panel-body">';
  1816. $coursesInfo = $listCourse['course'];
  1817. $htmlCategory .= self::getHtmlForCourse(
  1818. $coursesInfo,
  1819. $userCategoryId,
  1820. 1,
  1821. $loadDirs
  1822. );
  1823. // list of session category
  1824. $htmlSessionCategory = '<div class="session-view-row" style="display:none;" id="courseblock-'.$coursesInfo['real_id'].'">';
  1825. foreach ($listCourse['sessionCatList'] as $listCategorySession) {
  1826. // add session category
  1827. $htmlSessionCategory .= self::getHtmlSessionCategory(
  1828. $listCategorySession['catSessionId'],
  1829. $listCategorySession['catSessionName']
  1830. );
  1831. // list of session
  1832. $htmlSession = ''; // start
  1833. foreach ($listCategorySession['sessionList'] as $listSession) {
  1834. // add session
  1835. $htmlSession .= '<div class="session-view-row">';
  1836. $htmlSession .= self::getHtmlForSession(
  1837. $listSession['sessionId'],
  1838. $listSession['sessionName'],
  1839. $listCategorySession['catSessionId'],
  1840. $coursesInfo
  1841. );
  1842. $htmlSession .= '</div>';
  1843. $sessionCount++;
  1844. }
  1845. $htmlSession .= ''; // end session block
  1846. $htmlSessionCategory .= $htmlSession;
  1847. }
  1848. $htmlSessionCategory .= '</div>'; // end session cat block
  1849. $htmlCategory .= $htmlSessionCategory.'</div></div>';
  1850. $htmlCategory .= ''; // end course block
  1851. }
  1852. $userCategoryHtml .= $htmlCategory;
  1853. }
  1854. // look for courses in this userCat in not in session courses : $listCoursesInfo
  1855. // if course not already added
  1856. $htmlCategory = '';
  1857. foreach ($listCoursesInfo as $i => $listCourse) {
  1858. if ($listCourse['userCatId'] == $userCategoryId &&
  1859. !isset($listCoursesAlreadyDisplayed[$listCourse['id']])
  1860. ) {
  1861. if ($userCategoryId != 0) {
  1862. $htmlCategory .= '<div class="panel panel-default">';
  1863. } else {
  1864. $htmlCategory .= '<div class="panel panel-default">';
  1865. }
  1866. $htmlCategory .= '<div class="panel-body">';
  1867. $htmlCategory .= self::getHtmlForCourse(
  1868. $listCourse['course'],
  1869. $userCategoryId,
  1870. 0,
  1871. $loadDirs
  1872. );
  1873. $htmlCategory .= '</div></div>';
  1874. }
  1875. }
  1876. $htmlCategory .= '';
  1877. $userCategoryHtml .= $htmlCategory; // end user cat block
  1878. if ($userCategoryId != 0) {
  1879. $userCategoryHtml .= '</div>';
  1880. }
  1881. $html .= $userCategoryHtml;
  1882. }
  1883. $html .= '</div>';
  1884. return [
  1885. 'html' => $html,
  1886. 'sessions' => $session_categories,
  1887. 'courses' => $listCoursesInfo,
  1888. 'session_count' => $sessionCount,
  1889. 'course_count' => $courseCount,
  1890. ];
  1891. }
  1892. /**
  1893. * @param $listA
  1894. * @param $listB
  1895. *
  1896. * @return int
  1897. */
  1898. public static function compareListUserCategory($listA, $listB)
  1899. {
  1900. if ($listA['title'] == $listB['title']) {
  1901. return 0;
  1902. }
  1903. if ($listA['title'] > $listB['title']) {
  1904. return 1;
  1905. }
  1906. return -1;
  1907. }
  1908. /**
  1909. * @param $view
  1910. * @param $userId
  1911. */
  1912. public static function setDefaultMyCourseView($view, $userId)
  1913. {
  1914. setcookie('defaultMyCourseView'.$userId, $view);
  1915. }
  1916. /**
  1917. * @param int $userId
  1918. *
  1919. * @return array
  1920. */
  1921. public function returnCourseCategoryListFromUser($userId)
  1922. {
  1923. $sessionCount = 0;
  1924. $courseList = CourseManager::get_courses_list_by_user_id($userId);
  1925. $categoryCodes = CourseManager::getCourseCategoriesFromCourseList($courseList);
  1926. $categories = [];
  1927. foreach ($categoryCodes as $categoryCode) {
  1928. $categories[] = CourseCategory::getCategory($categoryCode);
  1929. }
  1930. $template = new Template('', false, false, false, true, false, false);
  1931. $layout = $template->get_template('user_portal/course_categories.tpl');
  1932. $template->assign('course_categories', $categories);
  1933. return [
  1934. 'courses' => $courseList,
  1935. 'html' => $template->fetch($layout),
  1936. 'course_count' => count($courseList),
  1937. 'session_count' => $sessionCount,
  1938. ];
  1939. }
  1940. /**
  1941. * Set grade book dependency progress bar see BT#13099.
  1942. *
  1943. * @param $userId
  1944. *
  1945. * @return bool
  1946. */
  1947. public function setGradeBookDependencyBar($userId)
  1948. {
  1949. $allow = api_get_configuration_value('gradebook_dependency');
  1950. if (api_is_anonymous()) {
  1951. return false;
  1952. }
  1953. if ($allow) {
  1954. $courseAndSessions = $this->returnCoursesAndSessions(
  1955. $userId,
  1956. false,
  1957. '',
  1958. false,
  1959. false
  1960. );
  1961. $courseList = api_get_configuration_value('gradebook_dependency_mandatory_courses');
  1962. $courseList = isset($courseList['courses']) ? $courseList['courses'] : [];
  1963. $mandatoryCourse = [];
  1964. if (!empty($courseList)) {
  1965. foreach ($courseList as $courseId) {
  1966. $courseInfo = api_get_course_info_by_id($courseId);
  1967. $mandatoryCourse[] = $courseInfo['code'];
  1968. }
  1969. }
  1970. // @todo improve calls of course info
  1971. $subscribedCourses = !empty($courseAndSessions['courses']) ? $courseAndSessions['courses'] : [];
  1972. $mainCategoryList = [];
  1973. foreach ($subscribedCourses as $courseInfo) {
  1974. $courseCode = $courseInfo['code'];
  1975. $categories = Category::load(null, null, $courseCode);
  1976. /** @var Category $category */
  1977. $category = !empty($categories[0]) ? $categories[0] : [];
  1978. if (!empty($category)) {
  1979. $mainCategoryList[] = $category;
  1980. }
  1981. }
  1982. $result20 = 0;
  1983. $result80 = 0;
  1984. $countCoursesPassedNoDependency = 0;
  1985. /** @var Category $category */
  1986. foreach ($mainCategoryList as $category) {
  1987. $userFinished = Category::userFinishedCourse(
  1988. $userId,
  1989. $category,
  1990. true
  1991. );
  1992. if ($userFinished) {
  1993. if (in_array($category->get_course_code(), $mandatoryCourse)) {
  1994. if ($result20 < 20) {
  1995. $result20 += 10;
  1996. }
  1997. } else {
  1998. $countCoursesPassedNoDependency++;
  1999. if ($result80 < 80) {
  2000. $result80 += 10;
  2001. }
  2002. }
  2003. }
  2004. }
  2005. $finalResult = $result20 + $result80;
  2006. $gradeBookList = api_get_configuration_value('gradebook_badge_sidebar');
  2007. $gradeBookList = isset($gradeBookList['gradebooks']) ? $gradeBookList['gradebooks'] : [];
  2008. $badgeList = [];
  2009. foreach ($gradeBookList as $id) {
  2010. $categories = Category::load($id);
  2011. /** @var Category $category */
  2012. $category = !empty($categories[0]) ? $categories[0] : [];
  2013. $badgeList[$id]['name'] = $category->get_name();
  2014. $badgeList[$id]['finished'] = false;
  2015. $badgeList[$id]['skills'] = [];
  2016. if (!empty($category)) {
  2017. $minToValidate = $category->getMinimumToValidate();
  2018. $dependencies = $category->getCourseListDependency();
  2019. $gradeBooksToValidateInDependence = $category->getGradeBooksToValidateInDependence();
  2020. $countDependenciesPassed = 0;
  2021. foreach ($dependencies as $courseId) {
  2022. $courseInfo = api_get_course_info_by_id($courseId);
  2023. $courseCode = $courseInfo['code'];
  2024. $categories = Category::load(null, null, $courseCode);
  2025. $subCategory = !empty($categories[0]) ? $categories[0] : null;
  2026. if (!empty($subCategory)) {
  2027. $score = Category::userFinishedCourse(
  2028. $userId,
  2029. $subCategory,
  2030. true
  2031. );
  2032. if ($score) {
  2033. $countDependenciesPassed++;
  2034. }
  2035. }
  2036. }
  2037. $userFinished =
  2038. $countDependenciesPassed >= $gradeBooksToValidateInDependence &&
  2039. $countCoursesPassedNoDependency >= $minToValidate;
  2040. if ($userFinished) {
  2041. $badgeList[$id]['finished'] = true;
  2042. }
  2043. $objSkill = new Skill();
  2044. $skills = $category->get_skills();
  2045. $skillList = [];
  2046. foreach ($skills as $skill) {
  2047. $skillList[] = $objSkill->get($skill['id']);
  2048. }
  2049. $badgeList[$id]['skills'] = $skillList;
  2050. }
  2051. }
  2052. $this->tpl->assign(
  2053. 'grade_book_sidebar',
  2054. true
  2055. );
  2056. $this->tpl->assign(
  2057. 'grade_book_progress',
  2058. $finalResult
  2059. );
  2060. $this->tpl->assign('grade_book_badge_list', $badgeList);
  2061. return true;
  2062. }
  2063. return false;
  2064. }
  2065. /**
  2066. * Generate the HTML code for items when displaying the right-side blocks.
  2067. *
  2068. * @param array $items
  2069. *
  2070. * @return string
  2071. */
  2072. private static function returnRightBlockItems(array $items)
  2073. {
  2074. $my_account_content = '';
  2075. foreach ($items as $item) {
  2076. if (empty($item['link']) && empty($item['title'])) {
  2077. continue;
  2078. }
  2079. $my_account_content .= '<li class="list-group-item '.(empty($item['class']) ? '' : $item['class']).'">'
  2080. .(empty($item['icon']) ? '' : '<span class="item-icon">'.$item['icon'].'</span>')
  2081. .'<a href="'.$item['link'].'">'.$item['title'].'</a>'
  2082. .'</li>';
  2083. }
  2084. return '<ul class="list-group">'.$my_account_content.'</ul>';
  2085. }
  2086. /**
  2087. * Return HTML code for personal user course category.
  2088. *
  2089. * @param $id
  2090. * @param $title
  2091. *
  2092. * @return string
  2093. */
  2094. private static function getHtmlForUserCategory($id, $title)
  2095. {
  2096. if ($id == 0) {
  2097. return '';
  2098. }
  2099. $icon = Display::return_icon(
  2100. 'folder_yellow.png',
  2101. $title,
  2102. ['class' => 'sessionView'],
  2103. ICON_SIZE_LARGE
  2104. );
  2105. return "<div class='session-view-user-category'>$icon<span>$title</span></div>";
  2106. }
  2107. /**
  2108. * return HTML code for course display in session view.
  2109. *
  2110. * @param array $courseInfo
  2111. * @param $userCategoryId
  2112. * @param bool $displayButton
  2113. * @param $loadDirs
  2114. *
  2115. * @return string
  2116. */
  2117. private static function getHtmlForCourse(
  2118. $courseInfo,
  2119. $userCategoryId,
  2120. $displayButton = false,
  2121. $loadDirs
  2122. ) {
  2123. if (empty($courseInfo)) {
  2124. return '';
  2125. }
  2126. $id = $courseInfo['real_id'];
  2127. $title = $courseInfo['title'];
  2128. $code = $courseInfo['code'];
  2129. $class = 'session-view-lvl-6';
  2130. if ($userCategoryId != 0 && !$displayButton) {
  2131. $class = 'session-view-lvl-7';
  2132. }
  2133. $class2 = 'session-view-lvl-6';
  2134. if ($displayButton || $userCategoryId != 0) {
  2135. $class2 = 'session-view-lvl-7';
  2136. }
  2137. $button = '';
  2138. if ($displayButton) {
  2139. $button = '<input id="session-view-button-'.intval(
  2140. $id
  2141. ).'" class="btn btn-default btn-sm" type="button" onclick="hideUnhide(\'courseblock-'.intval(
  2142. $id
  2143. ).'\', \'session-view-button-'.intval($id).'\', \'+\', \'-\')" value="+" />';
  2144. }
  2145. $icon = Display::return_icon(
  2146. 'blackboard.png',
  2147. $title,
  2148. ['class' => 'sessionView'],
  2149. ICON_SIZE_LARGE
  2150. );
  2151. $courseLink = $courseInfo['course_public_url'].'?id_session=0';
  2152. // get html course params
  2153. $courseParams = CourseManager::getCourseParamsForDisplay($id, $loadDirs);
  2154. $teachers = '';
  2155. $rightActions = '';
  2156. // teacher list
  2157. if (!empty($courseParams['teachers'])) {
  2158. $teachers = '<p class="'.$class2.' view-by-session-teachers">'.$courseParams['teachers'].'</p>';
  2159. }
  2160. // notification
  2161. if (!empty($courseParams['right_actions'])) {
  2162. $rightActions = '<div class="pull-right">'.$courseParams['right_actions'].'</div>';
  2163. }
  2164. $notifications = isset($courseParams['notifications']) ? $courseParams['notifications'] : '';
  2165. return "<div>
  2166. $button
  2167. <span class='$class'>$icon
  2168. <a class='sessionView' href='$courseLink'>$title</a>
  2169. </span>
  2170. $notifications
  2171. $rightActions
  2172. </div>
  2173. $teachers";
  2174. }
  2175. /**
  2176. * return HTML code for session category.
  2177. *
  2178. * @param $id
  2179. * @param $title
  2180. *
  2181. * @return string
  2182. */
  2183. private static function getHtmlSessionCategory($id, $title)
  2184. {
  2185. if ($id == 0) {
  2186. return '';
  2187. }
  2188. $icon = Display::return_icon(
  2189. 'folder_blue.png',
  2190. $title,
  2191. ['class' => 'sessionView'],
  2192. ICON_SIZE_LARGE
  2193. );
  2194. return "<div class='session-view-session-category'>
  2195. <span class='session-view-lvl-2'>
  2196. $icon
  2197. <span>$title</span>
  2198. </span>
  2199. </div>";
  2200. }
  2201. /**
  2202. * return HTML code for session.
  2203. *
  2204. * @param int $id session id
  2205. * @param string $title session title
  2206. * @param int $categorySessionId
  2207. * @param array $courseInfo
  2208. *
  2209. * @return string
  2210. */
  2211. private static function getHtmlForSession($id, $title, $categorySessionId, $courseInfo)
  2212. {
  2213. $html = '';
  2214. if ($categorySessionId == 0) {
  2215. $class1 = 'session-view-lvl-2'; // session
  2216. $class2 = 'session-view-lvl-4'; // got to course in session link
  2217. } else {
  2218. $class1 = 'session-view-lvl-3'; // session
  2219. $class2 = 'session-view-lvl-5'; // got to course in session link
  2220. }
  2221. $icon = Display::return_icon(
  2222. 'blackboard_blue.png',
  2223. $title,
  2224. ['class' => 'sessionView'],
  2225. ICON_SIZE_LARGE
  2226. );
  2227. $courseLink = $courseInfo['course_public_url'].'?id_session='.intval($id);
  2228. $html .= "<span class='$class1 session-view-session'>$icon$title</span>";
  2229. $html .= '<div class="'.$class2.' session-view-session-go-to-course-in-session">
  2230. <a class="" href="'.$courseLink.'">'.get_lang('GoToCourseInsideSession').'</a></div>';
  2231. return '<div>'.$html.'</div>';
  2232. }
  2233. /**
  2234. * @param $listA
  2235. * @param $listB
  2236. *
  2237. * @return int
  2238. */
  2239. private static function compareByCourse($listA, $listB)
  2240. {
  2241. if ($listA['userCatTitle'] == $listB['userCatTitle']) {
  2242. if ($listA['title'] == $listB['title']) {
  2243. return 0;
  2244. }
  2245. if ($listA['title'] > $listB['title']) {
  2246. return 1;
  2247. }
  2248. return -1;
  2249. }
  2250. if ($listA['userCatTitle'] > $listB['userCatTitle']) {
  2251. return 1;
  2252. }
  2253. return -1;
  2254. }
  2255. /**
  2256. * Get the session coach name, duration or dates
  2257. * when $_configuration['show_simple_session_info'] is enabled.
  2258. *
  2259. * @param string $coachName
  2260. * @param string $dates
  2261. * @param string|null $duration Optional
  2262. *
  2263. * @return string
  2264. */
  2265. private static function getSimpleSessionDetails($coachName, $dates, $duration = null)
  2266. {
  2267. $strDetails = [];
  2268. if (!empty($coachName)) {
  2269. $strDetails[] = $coachName;
  2270. }
  2271. $strDetails[] = !empty($duration) ? $duration : $dates;
  2272. return implode(' | ', $strDetails);
  2273. }
  2274. /**
  2275. * Filter the course list by category code.
  2276. *
  2277. * @param array $courseList course list
  2278. * @param string $categoryCode
  2279. *
  2280. * @return array
  2281. */
  2282. private static function filterByCategory($courseList, $categoryCode)
  2283. {
  2284. return array_filter(
  2285. $courseList,
  2286. function ($courseInfo) use ($categoryCode) {
  2287. if (isset($courseInfo['category_code']) &&
  2288. $courseInfo['category_code'] === $categoryCode
  2289. ) {
  2290. return true;
  2291. }
  2292. return false;
  2293. }
  2294. );
  2295. }
  2296. }