userportal.lib.php 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  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. public $tpl = false;
  12. public $name = '';
  13. public $home = '';
  14. public $default_home = 'home/';
  15. /**
  16. * Construct
  17. * @param string $title
  18. */
  19. public function __construct($title)
  20. {
  21. $this->tpl = new Template($title);
  22. $this->home = api_get_home_path();
  23. $this->user_id = api_get_user_id();
  24. $this->load_directories_preview = false;
  25. if (api_get_setting('show_documents_preview') == 'true') {
  26. $this->load_directories_preview = true;
  27. }
  28. }
  29. /**
  30. * @param bool $setLoginForm
  31. */
  32. function set_login_form($setLoginForm = true)
  33. {
  34. global $loginFailed;
  35. $this->tpl->setLoginForm($setLoginForm);
  36. }
  37. function return_exercise_block($personal_course_list)
  38. {
  39. $exercise_list = array();
  40. if (!empty($personal_course_list)) {
  41. foreach($personal_course_list as $course_item) {
  42. $course_code = $course_item['c'];
  43. $session_id = $course_item['id_session'];
  44. $exercises = ExerciseLib::get_exercises_to_be_taken(
  45. $course_code,
  46. $session_id
  47. );
  48. foreach($exercises as $exercise_item) {
  49. $exercise_item['course_code'] = $course_code;
  50. $exercise_item['session_id'] = $session_id;
  51. $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC');
  52. $exercise_list[] = $exercise_item;
  53. }
  54. }
  55. if (!empty($exercise_list)) {
  56. $exercise_list = msort($exercise_list, 'tms');
  57. $my_exercise = $exercise_list[0];
  58. $url = Display::url($my_exercise['title'], api_get_path(WEB_CODE_PATH).'exercice/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']);
  59. $this->tpl->assign('exercise_url', $url);
  60. $this->tpl->assign('exercise_end_date', api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT));
  61. }
  62. }
  63. }
  64. function return_announcements($show_slide = true)
  65. {
  66. //// Display System announcements
  67. $hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected');
  68. $currentUserId = api_get_user_id();
  69. if ($hideAnnouncements == 'true' && empty($currentUserId)) {
  70. return null;
  71. }
  72. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
  73. $announcement = intval($announcement);
  74. if (!api_is_anonymous() && $this->user_id) {
  75. $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
  76. if ($show_slide) {
  77. $announcements = SystemAnnouncementManager:: display_announcements_slider(
  78. $visibility,
  79. $announcement
  80. );
  81. } else {
  82. $announcements = SystemAnnouncementManager:: display_all_announcements(
  83. $visibility,
  84. $announcement
  85. );
  86. }
  87. } else {
  88. if ($show_slide) {
  89. $announcements = SystemAnnouncementManager:: display_announcements_slider(
  90. SystemAnnouncementManager::VISIBLE_GUEST,
  91. $announcement
  92. );
  93. } else {
  94. $announcements = SystemAnnouncementManager:: display_all_announcements(
  95. SystemAnnouncementManager::VISIBLE_GUEST,
  96. $announcement
  97. );
  98. }
  99. }
  100. return $announcements;
  101. }
  102. /**
  103. * Alias for the online_logout() function
  104. * @param bool $redirect Whether to ask online_logout to redirect to index.php or not
  105. */
  106. function logout($redirect = true)
  107. {
  108. online_logout($this->user_id, true);
  109. }
  110. /**
  111. * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
  112. *
  113. * @param string $category
  114. * @return boolean
  115. */
  116. function category_has_open_courses($category)
  117. {
  118. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  119. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  120. $category = Database::escape_string($category);
  121. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  122. $sql_result = Database::query($sql_query);
  123. while ($course = Database::fetch_array($sql_result)) {
  124. if (!$setting_show_also_closed_courses) {
  125. if ((api_get_user_id() > 0 && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  126. return true; //at least one open course
  127. }
  128. } else {
  129. if (isset($course['visibility'])) {
  130. return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
  131. }
  132. }
  133. }
  134. return false;
  135. }
  136. function return_teacher_link()
  137. {
  138. $html = '';
  139. $show_menu = false;
  140. if (!empty($this->user_id)) {
  141. // tabs that are deactivated are added here
  142. $show_menu = false;
  143. $show_create_link = false;
  144. $show_course_link = false;
  145. if (api_is_allowed_to_create_course()) {
  146. $show_menu = true;
  147. $show_course_link = true;
  148. $show_create_link = true;
  149. } else {
  150. if (api_get_setting('allow_students_to_browse_courses') === 'true') {
  151. $show_menu = true;
  152. $show_course_link = true;
  153. }
  154. if (api_get_setting('allow_users_to_create_courses') === 'true') {
  155. $show_create_link = true;
  156. }
  157. }
  158. if ($show_menu && ($show_create_link || $show_course_link )) {
  159. $show_menu = true;
  160. } else {
  161. $show_menu = false;
  162. }
  163. }
  164. // My Account section
  165. if ($show_menu) {
  166. $html .= '<ul class="nav nav-pills nav-stacked">';
  167. if ($show_create_link) {
  168. $html .= '<li class="add-course"><a href="' . api_get_path(WEB_CODE_PATH) . 'create_course/add_course.php">'.Display::return_icon('new-course.png', get_lang('CourseCreate')).(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
  169. }
  170. if ($show_course_link) {
  171. if (!api_is_drh() && !api_is_session_admin()) {
  172. $html .= '<li class="list-course"><a href="'. api_get_path(WEB_CODE_PATH) . 'auth/courses.php">'. Display::return_icon('catalog-course.png', get_lang('CourseCatalog')) .get_lang('CourseCatalog').'</a></li>';
  173. } else {
  174. $html .= '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  175. }
  176. }
  177. $html .= '</ul>';
  178. }
  179. if (!empty($html)) {
  180. $html = self::show_right_block(get_lang('Courses'), $html, 'teacher_block', null, 'teachers', 'teachersCollapse');
  181. }
  182. return $html;
  183. }
  184. /**
  185. * Includes a created page
  186. * @return string
  187. */
  188. public function return_home_page()
  189. {
  190. $userId = api_get_user_id();
  191. // Including the page for the news
  192. $html = '';
  193. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  194. $open = @(string)file_get_contents(api_get_path(SYS_PATH).$this->home.$_GET['include']);
  195. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  196. } else {
  197. // Hiding home top when user not connected.
  198. $hideTop = api_get_setting('hide_home_top_when_connected');
  199. if ($hideTop == 'true' && !empty($userId)) {
  200. return $html;
  201. }
  202. if (!empty($_SESSION['user_language_choice'])) {
  203. $user_selected_language = $_SESSION['user_language_choice'];
  204. } elseif (!empty($_SESSION['_user']['language'])) {
  205. $user_selected_language = $_SESSION['_user']['language'];
  206. } else {
  207. $user_selected_language = api_get_setting('platformLanguage');
  208. }
  209. $home_top_temp = '';
  210. // Try language specific home
  211. if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
  212. $home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
  213. }
  214. // Try default language home
  215. if (empty($home_top_temp)) {
  216. if (file_exists($this->home.'home_top.html')) {
  217. $home_top_temp = file_get_contents($this->home.'home_top.html');
  218. } else {
  219. if (file_exists($this->default_home.'home_top.html')) {
  220. $home_top_temp = file_get_contents($this->default_home . 'home_top.html');
  221. }
  222. }
  223. }
  224. if (trim($home_top_temp) == '' && api_is_platform_admin()) {
  225. $home_top_temp = '<div class="welcome-mascot">' . get_lang('PortalHomepageDefaultIntroduction') . '</div>';
  226. } else {
  227. $home_top_temp = '<div class="welcome-home-top-temp">' . $home_top_temp . '</div>';
  228. }
  229. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  230. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  231. }
  232. return $html;
  233. }
  234. function return_notice()
  235. {
  236. $sys_path = api_get_path(SYS_PATH);
  237. $user_selected_language = api_get_interface_language();
  238. $html = '';
  239. // Notice
  240. $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice_'.$user_selected_language.'.html');
  241. if (empty($home_notice)) {
  242. $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice.html');
  243. }
  244. if (!empty($home_notice)) {
  245. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  246. //$home_notice = Display::div($home_notice, array('class' => 'homepage_notice'));
  247. $html = self::show_right_block(
  248. get_lang('Notice'),
  249. $home_notice,
  250. 'notice_block',
  251. null,
  252. 'notices',
  253. 'noticesCollapse'
  254. );
  255. }
  256. return $html;
  257. }
  258. function return_help()
  259. {
  260. $user_selected_language = api_get_interface_language();
  261. $sys_path = api_get_path(SYS_PATH);
  262. $platformLanguage = api_get_setting('platformLanguage');
  263. // Help section.
  264. /* Hide right menu "general" and other parts on anonymous right menu. */
  265. if (!isset($user_selected_language)) {
  266. $user_selected_language = $platformLanguage;
  267. }
  268. $html = null;
  269. $home_menu = @(string)file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html');
  270. if (!empty($home_menu)) {
  271. $home_menu_content = '<ul class="nav nav-pills nav-stacked">';
  272. $home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  273. $home_menu_content .= '</ul>';
  274. $html .= self::show_right_block(
  275. get_lang('MenuGeneral'),
  276. $home_menu_content,
  277. 'help_block',
  278. null,
  279. 'helps',
  280. 'helpsCollapse'
  281. );
  282. }
  283. return $html;
  284. }
  285. function return_skills_links()
  286. {
  287. $content = '';
  288. $content .= '<ul class="nav nav-pills nav-stacked">';
  289. /**
  290. * Generate the block for show a panel with links to My Certificates and Certificates Search pages
  291. * @return string The HTML code for the panel
  292. */
  293. $certificatesItem = '';
  294. if (!api_is_anonymous()) {
  295. $allow = api_get_configuration_value('hide_my_certificate_link');
  296. if ($allow === false) {
  297. $certificatesItem = Display::tag(
  298. 'li',
  299. Display::url(
  300. Display::return_icon(
  301. 'graduation.png',
  302. get_lang('MyCertificates'),
  303. null,
  304. ICON_SIZE_SMALL
  305. ).
  306. get_lang('MyCertificates'),
  307. api_get_path(WEB_CODE_PATH)."gradebook/my_certificates.php"
  308. )
  309. );
  310. }
  311. }
  312. $searchItem = '';
  313. if (api_get_setting('allow_public_certificates') == 'true') {
  314. $searchItem = Display::tag(
  315. 'li',
  316. Display::url(Display::return_icon('search_graduation.png',get_lang('Search'),null,ICON_SIZE_SMALL).
  317. get_lang('Search'),
  318. api_get_path(WEB_CODE_PATH) . "gradebook/search.php"
  319. )
  320. );
  321. }
  322. if (empty($certificatesItem) && empty($searchItem)) {
  323. return '';
  324. } else {
  325. $content.= $certificatesItem;
  326. $content.= $searchItem;
  327. }
  328. if (api_get_setting('allow_skills_tool') == 'true') {
  329. $content .= Display::tag('li', Display::url(Display::return_icon('skill-badges.png',get_lang('MySkills'),null,ICON_SIZE_SMALL).get_lang('MySkills'), api_get_path(WEB_CODE_PATH).'social/my_skills_report.php'));
  330. $allowSkillsManagement = api_get_setting('allow_hr_skills_management') == 'true';
  331. if (($allowSkillsManagement && api_is_drh()) || api_is_platform_admin()) {
  332. $content .= Display::tag('li',
  333. Display::url(Display::return_icon('edit-skill.png', get_lang('MySkills'), null,
  334. ICON_SIZE_SMALL) . get_lang('ManageSkills'),
  335. api_get_path(WEB_CODE_PATH) . 'admin/skills_wheel.php'));
  336. }
  337. }
  338. $content .= '</ul>';
  339. $html = self::show_right_block(
  340. get_lang("Skills"),
  341. $content,
  342. 'skill_block',
  343. null,
  344. 'skills',
  345. 'skillsCollapse'
  346. );
  347. return $html;
  348. }
  349. /**
  350. * Reacts on a failed login:
  351. * Displays an explanation with a link to the registration form.
  352. *
  353. * @version 1.0.1
  354. */
  355. function handle_login_failed()
  356. {
  357. return $this->tpl->handleLoginFailed();
  358. }
  359. /**
  360. * Display list of courses in a category.
  361. * (for anonymous users)
  362. *
  363. * @version 1.1
  364. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  365. * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
  366. */
  367. function return_courses_in_categories()
  368. {
  369. $result = '';
  370. $stok = Security::get_token();
  371. // Initialization.
  372. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  373. $web_course_path = api_get_path(WEB_COURSE_PATH);
  374. $category = isset($_GET['category']) ? Database::escape_string($_GET['category']) : '';
  375. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  376. // Database table definitions.
  377. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  378. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  379. // Get list of courses in category $category.
  380. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  381. WHERE category_code = '" . $category . "'
  382. ORDER BY title, UPPER(visual_code)";
  383. // Showing only the courses of the current access_url_id.
  384. if (api_is_multiple_url_enabled()) {
  385. $url_access_id = api_get_current_access_url_id();
  386. if ($url_access_id != -1) {
  387. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  388. $sql_get_course_list = "SELECT * FROM $main_course_table as course
  389. INNER JOIN $tbl_url_rel_course as url_rel_course
  390. ON (url_rel_course.c_id = course.id)
  391. WHERE
  392. access_url_id = $url_access_id AND
  393. category_code = '".Database::escape_string($_GET['category'])."'
  394. ORDER BY title, UPPER(visual_code)";
  395. }
  396. }
  397. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  398. $sql_result_courses = Database::query($sql_get_course_list);
  399. while ($course_result = Database::fetch_array($sql_result_courses)) {
  400. $course_list[] = $course_result;
  401. }
  402. // $setting_show_also_closed_courses
  403. if ($user_identified) {
  404. if ($setting_show_also_closed_courses) {
  405. $platform_visible_courses = '';
  406. } else {
  407. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  408. }
  409. } else {
  410. if ($setting_show_also_closed_courses) {
  411. $platform_visible_courses = '';
  412. } else {
  413. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  414. }
  415. }
  416. $sqlGetSubCatList = "
  417. SELECT t1.name,
  418. t1.code,
  419. t1.parent_id,
  420. t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  421. FROM $main_category_table t1
  422. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  423. LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses)
  424. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  425. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  426. // Showing only the category of courses of the current access_url_id
  427. if (api_is_multiple_url_enabled()) {
  428. $courseCategoryCondition = null;
  429. if (isMultipleUrlSupport()) {
  430. $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
  431. $courseCategoryCondition = " INNER JOIN $table a ON (t1.id = a.course_category_id)";
  432. }
  433. $url_access_id = api_get_current_access_url_id();
  434. if ($url_access_id != -1) {
  435. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  436. $sqlGetSubCatList = "
  437. SELECT t1.name,
  438. t1.code,
  439. t1.parent_id,
  440. t1.children_count,
  441. COUNT(DISTINCT t3.code) AS nbCourse
  442. FROM $main_category_table t1
  443. $courseCategoryCondition
  444. LEFT JOIN $main_category_table t2 ON t1.code = t2.parent_id
  445. LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses)
  446. INNER JOIN $tbl_url_rel_course as url_rel_course
  447. ON (url_rel_course.c_id = t3.id)
  448. WHERE
  449. url_rel_course.access_url_id = $url_access_id AND
  450. t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  451. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count
  452. ORDER BY t1.tree_pos, t1.name";
  453. }
  454. }
  455. $resCats = Database::query($sqlGetSubCatList);
  456. $thereIsSubCat = false;
  457. if (Database::num_rows($resCats) > 0) {
  458. $htmlListCat = Display::page_header(get_lang('CatList'));
  459. $htmlListCat .= '<ul>';
  460. $htmlTitre = '';
  461. while ($catLine = Database::fetch_array($resCats)) {
  462. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  463. if ($category_has_open_courses) {
  464. // The category contains courses accessible to anonymous visitors.
  465. $htmlListCat .= '<li>';
  466. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  467. if (api_get_setting('show_number_of_courses') == 'true') {
  468. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  469. }
  470. $htmlListCat .= "</li>";
  471. $thereIsSubCat = true;
  472. } elseif ($catLine['children_count'] > 0) {
  473. // The category has children, subcategories.
  474. $htmlListCat .= '<li>';
  475. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  476. $htmlListCat .= "</li>";
  477. $thereIsSubCat = true;
  478. } elseif (api_get_setting('show_empty_course_categories') == 'true') {
  479. /* End changed code to eliminate the (0 courses) after empty categories. */
  480. $htmlListCat .= '<li>';
  481. $htmlListCat .= $catLine['name'];
  482. $htmlListCat .= "</li>";
  483. $thereIsSubCat = true;
  484. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  485. // TODO: deprecate this useless feature - this includes removing system variable
  486. if (empty($htmlTitre)) {
  487. $htmlTitre = '<p>';
  488. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  489. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  490. }
  491. $htmlTitre .= "</p>";
  492. }
  493. }
  494. $htmlListCat .= "</ul>";
  495. }
  496. $result .= $htmlTitre;
  497. if ($thereIsSubCat) {
  498. $result .= $htmlListCat;
  499. }
  500. while ($categoryName = Database::fetch_array($resCats)) {
  501. $result .= '<h3>' . $categoryName['name'] . "</h3>\n";
  502. }
  503. $numrows = Database::num_rows($sql_result_courses);
  504. $courses_list_string = '';
  505. $courses_shown = 0;
  506. if ($numrows > 0) {
  507. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  508. $courses_list_string .= "<ul>";
  509. if (api_get_user_id()) {
  510. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  511. }
  512. foreach ($course_list as $course) {
  513. // $setting_show_also_closed_courses
  514. if ($course['visibility'] == COURSE_VISIBILITY_HIDDEN) { continue; }
  515. if (!$setting_show_also_closed_courses) {
  516. // If we do not show the closed courses
  517. // we only show the courses that are open to the world (to everybody)
  518. // and the courses that are open to the platform (if the current user is a registered user.
  519. if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  520. $courses_shown++;
  521. $courses_list_string .= "<li>";
  522. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  523. $course_details = array();
  524. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  525. $course_details[] = $course['visual_code'];
  526. }
  527. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  528. $course_details[] = CourseManager::get_teacher_list_from_course_code_to_string($course['code']);
  529. }
  530. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  531. $course_details[] = $course['course_language'];
  532. }
  533. $courses_list_string .= implode(' - ', $course_details);
  534. $courses_list_string .= "</li>";
  535. }
  536. } else {
  537. // We DO show the closed courses.
  538. // The course is accessible if (link to the course homepage):
  539. // 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);
  540. // 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);
  541. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  542. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  543. // 5. the user is the platform admin api_is_platform_admin().
  544. $courses_shown++;
  545. $courses_list_string .= "<li>";
  546. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  547. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  548. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  549. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  550. || $courses_of_user[$course['code']]['status'] == '1'
  551. || api_is_platform_admin()) {
  552. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  553. }
  554. $courses_list_string .= $course['title'];
  555. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  556. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  557. || ($user_identified && array_key_exists($course['code'], $courses_of_user)
  558. && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  559. || $courses_of_user[$course['code']]['status'] == '1'
  560. || api_is_platform_admin()) {
  561. $courses_list_string .= '</a><br />';
  562. }
  563. $course_details = array();
  564. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  565. $course_details[] = $course['visual_code'];
  566. }
  567. // if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  568. // $courses_list_string .= ' - ';
  569. // }
  570. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  571. if (!empty($course['tutor_name'])) {
  572. $course_details[] = $course['tutor_name'];
  573. }
  574. }
  575. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  576. $course_details[] = $course['course_language'];
  577. }
  578. $courses_list_string .= implode(' - ', $course_details);
  579. // We display a subscription link if:
  580. // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
  581. // 2.
  582. if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) {
  583. if ($course['subscribe'] == '1') {
  584. $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($_GET['category']).'">'.get_lang('Subscribe').'</a><br />';
  585. } else {
  586. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  587. }
  588. }
  589. $courses_list_string .= "</li>";
  590. } //end else
  591. } // end foreach
  592. $courses_list_string .= "</ul>";
  593. }
  594. if ($courses_shown > 0) {
  595. // Only display the list of courses and categories if there was more than
  596. // 0 courses visible to the world (we're in the anonymous list here).
  597. $result .= $courses_list_string;
  598. }
  599. if ($category != '') {
  600. $result .= '<p><a href="'.api_get_self().'"> ' .
  601. Display :: return_icon('back.png', get_lang('BackToHomePage')).
  602. get_lang('BackToHomePage') . '</a></p>';
  603. }
  604. return $result;
  605. }
  606. /**
  607. * retrieves all the courses that the user has already subscribed to
  608. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  609. * @param int $user_id: the id of the user
  610. * @return array an array containing all the information of the courses of the given user
  611. */
  612. public function get_courses_of_user($user_id)
  613. {
  614. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  615. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  616. // Secondly we select the courses that are in a category (user_course_cat <> 0)
  617. // and sort these according to the sort of the category
  618. $user_id = intval($user_id);
  619. $sql_select_courses = "SELECT
  620. course.code k,
  621. course.visual_code vc,
  622. course.subscribe subscr,
  623. course.unsubscribe unsubscr,
  624. course.title i,
  625. course.tutor_name t,
  626. course.directory dir,
  627. course_rel_user.status status,
  628. course_rel_user.sort sort,
  629. course_rel_user.user_course_cat user_course_cat
  630. FROM
  631. $table_course course,
  632. $table_course_user course_rel_user
  633. WHERE
  634. course.id = course_rel_user.c_id AND
  635. course_rel_user.user_id = '".$user_id."' AND
  636. course_rel_user.relation_type <> ".COURSE_RELATION_TYPE_RRHH."
  637. ORDER BY course_rel_user.sort ASC";
  638. $result = Database::query($sql_select_courses);
  639. $courses = array();
  640. while ($row = Database::fetch_array($result)) {
  641. // We only need the database name of the course.
  642. $courses[$row['k']] = array(
  643. 'code' => $row['k'],
  644. 'visual_code' => $row['vc'],
  645. 'title' => $row['i'],
  646. 'directory' => $row['dir'],
  647. 'status' => $row['status'],
  648. 'tutor' => $row['t'],
  649. 'subscribe' => $row['subscr'],
  650. 'unsubscribe' => $row['unsubscr'],
  651. 'sort' => $row['sort'],
  652. 'user_course_category' => $row['user_course_cat']
  653. );
  654. }
  655. return $courses;
  656. }
  657. /**
  658. * @todo use the template system
  659. * @param $title
  660. * @param $content
  661. * @param string $id
  662. * @param array $params
  663. * @param string $idAccordion
  664. * @param string $idCollapse
  665. * @return null|string
  666. */
  667. public function show_right_block(
  668. $title,
  669. $content,
  670. $id = '',
  671. $params = [],
  672. $idAccordion = '',
  673. $idCollapse = ''
  674. ) {
  675. if (!empty($idAccordion)) {
  676. $html = null;
  677. $html .= '<div class="panel-group" id="'.$idAccordion.'" role="tablist" aria-multiselectable="true">' . PHP_EOL;
  678. $html .= '<div class="panel panel-default" id="'.$id.'">' . PHP_EOL;
  679. $html .= '<div class="panel-heading" role="tab"><h4 class="panel-title">' . PHP_EOL;
  680. $html .= '<a role="button" data-toggle="collapse" data-parent="#'.$idAccordion.'" href="#'.$idCollapse.'" aria-expanded="true" aria-controls="'.$idCollapse.'">'.$title.'</a>' . PHP_EOL;
  681. $html .= '</h4></div>' . PHP_EOL;
  682. $html .= '<div id="'.$idCollapse.'" class="panel-collapse collapse in" role="tabpanel">' . PHP_EOL;
  683. $html .= '<div class="panel-body">'.$content.'</div>' . PHP_EOL;
  684. $html .= '</div></div></div>' . PHP_EOL;
  685. } else {
  686. if (!empty($id)) {
  687. $params['id'] = $id;
  688. }
  689. $params['class'] = 'panel panel-default';
  690. $html = null;
  691. if (!empty($title)) {
  692. $html .= '<div class="panel-heading">'.$title.'</div>' . PHP_EOL;
  693. }
  694. $html.= '<div class="panel-body">'.$content.'</div>' . PHP_EOL;
  695. $html = Display::div($html, $params);
  696. }
  697. return $html;
  698. }
  699. /**
  700. * Adds a form to let users login
  701. * @version 1.1
  702. */
  703. public function display_login_form()
  704. {
  705. return $this->tpl->displayLoginForm();
  706. }
  707. /**
  708. * @todo use FormValidator
  709. * @return string
  710. */
  711. public function return_search_block()
  712. {
  713. $html = '';
  714. if (api_get_setting('search_enabled') == 'true') {
  715. $search_btn = get_lang('Search');
  716. $search_content = '<form action="main/search/" method="post">
  717. <div class="form-group">
  718. <input type="text" id="query" class="form-control" name="query" value="" />
  719. <button class="btn btn-default" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  720. </div></form>';
  721. $html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block');
  722. }
  723. return $html;
  724. }
  725. /**
  726. * @return string
  727. */
  728. public function return_classes_block()
  729. {
  730. $html = '';
  731. if (api_get_setting('show_groups_to_users') == 'true') {
  732. $usergroup = new UserGroup();
  733. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  734. $classes = '';
  735. if (!empty($usergroup_list)) {
  736. foreach($usergroup_list as $group_id) {
  737. $data = $usergroup->get($group_id);
  738. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  739. $classes .= Display::tag('li', $data['name']);
  740. }
  741. }
  742. if (api_is_platform_admin()) {
  743. $classes .= Display::tag(
  744. 'li',
  745. Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add')
  746. );
  747. }
  748. if (!empty($classes)) {
  749. $classes = Display::tag('ul', $classes, array('class'=>'nav nav-pills nav-stacked'));
  750. $html .= self::show_right_block(get_lang('Classes'), $classes, 'classes_block');
  751. }
  752. }
  753. return $html;
  754. }
  755. /**
  756. * @return null|string
  757. */
  758. public function return_user_image_block()
  759. {
  760. $html = null;
  761. if (!api_is_anonymous()) {
  762. $userPicture = UserManager::getUserPicture(api_get_user_id());
  763. $content = null;
  764. if (api_get_setting('allow_social_tool') == 'true') {
  765. $content .= '<a style="text-align:center" href="' . api_get_path(WEB_PATH) . 'main/social/home.php">
  766. <img class="img-circle" src="' . $userPicture . '" ></a>';
  767. } else {
  768. $content .= '<a style="text-align:center" href="' . api_get_path(WEB_PATH) . 'main/auth/profile.php">
  769. <img class="img-circle" title="' . get_lang('EditProfile') . '" src="' . $userPicture. '" ></a>';
  770. }
  771. $html = self::show_right_block(
  772. null,
  773. $content,
  774. 'user_image_block',
  775. array('style' => 'text-align:center;')
  776. );
  777. }
  778. return $html;
  779. }
  780. /**
  781. * @return null|string|void
  782. */
  783. public function return_profile_block()
  784. {
  785. global $_configuration;
  786. $user_id = api_get_user_id();
  787. if (empty($user_id)) {
  788. return;
  789. }
  790. $userGroup = new UserGroup();
  791. $profile_content = '<ul class="nav nav-pills nav-stacked">';
  792. // @todo Add a platform setting to add the user image.
  793. if (api_get_setting('allow_message_tool') == 'true') {
  794. // New messages.
  795. $number_of_new_messages = MessageManager::get_new_messages();
  796. // New contact invitations.
  797. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  798. // New group invitations sent by a moderator.
  799. $group_pending_invitations = $userGroup->get_groups_by_user(
  800. api_get_user_id(),
  801. GROUP_USER_PERMISSION_PENDING_INVITATION,
  802. false
  803. );
  804. $group_pending_invitations = count($group_pending_invitations);
  805. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  806. $cant_msg = Display::badge($number_of_new_messages);
  807. $link = '';
  808. if (api_get_setting('allow_social_tool') == 'true') {
  809. $link = '?f=social';
  810. }
  811. $profile_content .= '<li class="inbox-message-social"><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.Display::return_icon('inbox.png',get_lang('Inbox'),null,ICON_SIZE_SMALL).get_lang('Inbox').$cant_msg.' </a></li>';
  812. $profile_content .= '<li class="new-message-social"><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.Display::return_icon('new-message.png',get_lang('Compose'),null,ICON_SIZE_SMALL).get_lang('Compose').' </a></li>';
  813. if (api_get_setting('allow_social_tool') == 'true') {
  814. $total_invitations = Display::badge($total_invitations);
  815. $profile_content .= '<li class="invitations-social"><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.Display::return_icon('invitations.png',get_lang('PendingInvitations'),null,ICON_SIZE_SMALL).get_lang('PendingInvitations').$total_invitations.'</a></li>';
  816. }
  817. if (isset($_configuration['allow_my_files_link_in_homepage']) && $_configuration['allow_my_files_link_in_homepage']) {
  818. $myFiles = '<li class="myfiles-social"><a href="'.api_get_path(WEB_PATH).'main/social/myfiles.php">'.get_lang('MyFiles').'</a></li>';
  819. if (api_get_setting('allow_my_files') === 'false') {
  820. $myFiles = '';
  821. }
  822. $profile_content .= $myFiles;
  823. }
  824. }
  825. $editProfileUrl = Display::getProfileEditionLink($user_id);
  826. $profile_content .= '<li class="profile-social"><a href="' . $editProfileUrl . '">'.Display::return_icon('edit-profile.png',get_lang('EditProfile'),null,ICON_SIZE_SMALL).get_lang('EditProfile').'</a></li>';
  827. $profile_content .= '</ul>';
  828. $html = self::show_right_block(
  829. get_lang('Profile'),
  830. $profile_content,
  831. 'profile_block',
  832. null,
  833. 'profile',
  834. 'profileCollapse'
  835. );
  836. return $html;
  837. }
  838. public function return_navigation_links()
  839. {
  840. $html = '';
  841. // Deleting the myprofile link.
  842. if (api_get_setting('allow_social_tool') == 'true') {
  843. unset($this->tpl->menu_navigation['myprofile']);
  844. }
  845. // Main navigation section.
  846. // Tabs that are deactivated are added here.
  847. if (!empty($this->tpl->menu_navigation)) {
  848. $content = '<ul class="nav nav-pills nav-stacked">';
  849. foreach ($this->tpl->menu_navigation as $section => $navigation_info) {
  850. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  851. $content .= '<li'.$current.'>';
  852. $content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  853. $content .= '</li>';
  854. }
  855. $content .= '</ul>';
  856. $html = self::show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
  857. }
  858. return $html;
  859. }
  860. /**
  861. * @return null|string
  862. */
  863. public function return_course_block()
  864. {
  865. $html = '';
  866. $show_create_link = false;
  867. $show_course_link = false;
  868. if (api_is_allowed_to_create_course()) {
  869. $show_create_link = true;
  870. }
  871. if (api_get_setting('allow_students_to_browse_courses') === 'true') {
  872. $show_course_link = true;
  873. }
  874. // My account section
  875. $my_account_content = '<ul class="nav nav-pills nav-stacked">';
  876. if ($show_create_link) {
  877. $my_account_content .= '<li class="add-course"><a href="main/create_course/add_course.php">';
  878. if (api_get_setting('course_validation') == 'true' && !api_is_platform_admin()) {
  879. $my_account_content .= Display::return_icon('new-course.png',get_lang('CreateCourseRequest'),null,ICON_SIZE_SMALL);
  880. $my_account_content .= get_lang('CreateCourseRequest');
  881. } else {
  882. $my_account_content .= Display::return_icon('new-course.png',get_lang('CourseCreate'),null,ICON_SIZE_SMALL);
  883. $my_account_content .= get_lang('CourseCreate');
  884. }
  885. $my_account_content .= '</a></li>';
  886. if (SessionManager::allowToManageSessions()) {
  887. $my_account_content .= '<li class="add-course"><a href="main/session/session_add.php">';
  888. $my_account_content .= Display::return_icon('session.png',get_lang('AddSession'),null,ICON_SIZE_SMALL);
  889. $my_account_content .= get_lang('AddSession');
  890. $my_account_content .= '</a></li>';
  891. }
  892. }
  893. //Sort courses
  894. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  895. $img_order= Display::return_icon('order-course.png',get_lang('SortMyCourses'),null,ICON_SIZE_SMALL);
  896. $my_account_content .= '<li class="order-course">'.Display::url($img_order.get_lang('SortMyCourses'), $url, array('class' => 'sort course')).'</li>';
  897. // Session history
  898. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  899. $my_account_content .= '<li class="history-course"><a href="user_portal.php">'.Display::return_icon('history-course.png',get_lang('DisplayTrainingList'),null,ICON_SIZE_SMALL).get_lang('DisplayTrainingList').'</a></li>';
  900. } else {
  901. $my_account_content .= '<li class="history-course"><a href="user_portal.php?history=1" >'.Display::return_icon('history-course.png',get_lang('HistoryTrainingSessions'),null,ICON_SIZE_SMALL).get_lang('HistoryTrainingSessions').'</a></li>';
  902. }
  903. // Course catalog
  904. if ($show_course_link) {
  905. if (!api_is_drh()) {
  906. $my_account_content .= '<li class="list-course"><a href="main/auth/courses.php" >'.Display::return_icon('catalog-course.png',get_lang('CourseCatalog'),null,ICON_SIZE_SMALL).get_lang('CourseCatalog').'</a></li>';
  907. } else {
  908. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  909. }
  910. }
  911. $my_account_content .= '</ul>';
  912. if (!empty($my_account_content)) {
  913. $html = self::show_right_block(
  914. get_lang('Courses'),
  915. $my_account_content,
  916. 'course_block',
  917. null,
  918. 'course',
  919. 'courseCollapse'
  920. );
  921. }
  922. return $html;
  923. }
  924. /**
  925. * Prints the session and course list (user_portal.php)
  926. * @param int $user_id
  927. * @return string
  928. */
  929. public function returnCoursesAndSessions($user_id)
  930. {
  931. global $_configuration;
  932. $gamificationModeIsActive = api_get_setting('gamification_mode');
  933. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  934. if ($load_history) {
  935. // Load sessions in category in *history*
  936. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  937. } else {
  938. // Load sessions in category
  939. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  940. }
  941. $html = '';
  942. // Showing history title
  943. if ($load_history) {
  944. $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  945. if (empty($session_categories)) {
  946. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  947. }
  948. }
  949. $courses_html = '';
  950. $special_courses = '';
  951. $sessionCount = 0;
  952. $courseCount = 0;
  953. // If we're not in the history view...
  954. if (!isset($_GET['history'])) {
  955. // Display special courses.
  956. $specialCourses = CourseManager::display_special_courses(
  957. $user_id,
  958. $this->load_directories_preview
  959. );
  960. $special_courses = $specialCourses['html'];
  961. // Display courses.
  962. $courses = CourseManager::display_courses(
  963. $user_id,
  964. $this->load_directories_preview
  965. );
  966. $courses_html .= $courses['html'];
  967. $courseCount = $specialCourses['course_count'] + $courses['course_count'];
  968. }
  969. $sessions_with_category = '';
  970. $sessions_with_no_category = '';
  971. $coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link');
  972. $coursesListSessionStyle = $coursesListSessionStyle === false ? 1 : $coursesListSessionStyle;
  973. if (api_is_drh()) {
  974. $coursesListSessionStyle = 1;
  975. }
  976. if (is_array($session_categories)) {
  977. foreach ($session_categories as $session_category) {
  978. $session_category_id = $session_category['session_category']['id'];
  979. // Sessions and courses that are not in a session category
  980. if (
  981. empty($session_category_id) &&
  982. isset($session_category['sessions'])
  983. ) {
  984. // Independent sessions
  985. foreach ($session_category['sessions'] as $session) {
  986. $session_id = $session['session_id'];
  987. // Don't show empty sessions.
  988. if (count($session['courses']) < 1) {
  989. continue;
  990. }
  991. // Courses inside the current session.
  992. $date_session_start = $session['access_start_date'];
  993. $date_session_end = $session['access_end_date'];
  994. $coachAccessStartDate = $session['coach_access_start_date'];
  995. $coachAccessEndDate = $session['coach_access_end_date'];
  996. $session_now = time();
  997. $count_courses_session = 0;
  998. // Loop course content
  999. $html_courses_session = [];
  1000. $atLeastOneCourseIsVisible = false;
  1001. foreach ($session['courses'] as $course) {
  1002. $is_coach_course = api_is_coach($session_id, $course['real_id']);
  1003. $allowed_time = 0;
  1004. $allowedEndTime = true;
  1005. if (!empty($date_session_start) && $date_session_start != '0000-00-00 00:00:00') {
  1006. if ($is_coach_course) {
  1007. $allowed_time = api_strtotime($coachAccessStartDate);
  1008. } else {
  1009. $allowed_time = api_strtotime($date_session_start);
  1010. }
  1011. if (!isset($_GET['history'])) {
  1012. if (!empty($date_session_end) && $date_session_end != '0000-00-00 00:00:00') {
  1013. $endSessionToTms = api_strtotime($date_session_end);
  1014. if ($session_now > $endSessionToTms) {
  1015. $allowedEndTime = false;
  1016. }
  1017. }
  1018. }
  1019. }
  1020. if ($session_now >= $allowed_time && $allowedEndTime) {
  1021. // Read only and accessible.
  1022. $atLeastOneCourseIsVisible = true;
  1023. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1024. $courseUserHtml = CourseManager::get_logged_user_course_html(
  1025. $course,
  1026. $session_id,
  1027. 'session_course_item',
  1028. true,
  1029. $this->load_directories_preview
  1030. );
  1031. if (isset($courseUserHtml[1])) {
  1032. $course_session = $courseUserHtml[1];
  1033. $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
  1034. $html_courses_session[] = $course_session;
  1035. }
  1036. }
  1037. $count_courses_session++;
  1038. }
  1039. }
  1040. // No courses to show.
  1041. if ($atLeastOneCourseIsVisible == false) {
  1042. if (empty($html_courses_session)) {
  1043. continue;
  1044. }
  1045. }
  1046. if ($count_courses_session > 0) {
  1047. $params = array(
  1048. 'id' => $session_id
  1049. );
  1050. $session_box = Display::get_session_title_box($session_id);
  1051. $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null;
  1052. $extra_info .= !empty($session_box['coach'])
  1053. ? ' - ' . $session_box['dates']
  1054. : $session_box['dates'];
  1055. $extra_info .= isset($session_box['duration'])
  1056. ? ' ' . $session_box['duration']
  1057. : null;
  1058. $params['extra_fields'] = $session_box['extra_fields'];
  1059. $params['course_list_session_style'] = $coursesListSessionStyle;
  1060. $params['title'] = $session_box['title'];
  1061. $params['subtitle'] = $extra_info;
  1062. $params['show_actions'] = api_is_platform_admin() ? true : false;
  1063. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1064. // $params['extra'] .= $html_courses_session;
  1065. }
  1066. $params['description'] = $session_box['description'];
  1067. $params['show_description'] = $session_box['show_description'];
  1068. $params['courses'] = $html_courses_session;
  1069. $params['show_simple_session_info'] = false;
  1070. if (
  1071. isset($_configuration['show_simple_session_info']) &&
  1072. $_configuration['show_simple_session_info']
  1073. ) {
  1074. $params['show_simple_session_info'] = true;
  1075. }
  1076. if ($gamificationModeIsActive) {
  1077. $params['stars'] = GamificationUtils::getSessionStars($params['id'], $this->user_id);
  1078. $params['progress'] = GamificationUtils::getSessionProgress($params['id'], $this->user_id);
  1079. $params['points'] = GamificationUtils::getSessionPoints($params['id'], $this->user_id);
  1080. }
  1081. $this->tpl->assign('session', $params);
  1082. $this->tpl->assign('gamification_mode', $gamificationModeIsActive);
  1083. $sessions_with_no_category .= $this->tpl->fetch(
  1084. $this->tpl->get_template('/user_portal/session.tpl')
  1085. );
  1086. $sessionCount++;
  1087. }
  1088. }
  1089. } else {
  1090. // All sessions included in
  1091. $count_courses_session = 0;
  1092. $html_sessions = '';
  1093. if (isset($session_category['sessions'])) {
  1094. foreach ($session_category['sessions'] as $session) {
  1095. $session_id = $session['session_id'];
  1096. // Don't show empty sessions.
  1097. if (count($session['courses']) < 1) {
  1098. continue;
  1099. }
  1100. $date_session_start = $session['access_start_date'];
  1101. $date_session_end = $session['access_end_date'];
  1102. $coachAccessStartDate = $session['coach_access_start_date'];
  1103. $coachAccessEndDate = $session['coach_access_end_date'];
  1104. $session_now = time();
  1105. $html_courses_session = [];
  1106. $count = 0;
  1107. foreach ($session['courses'] as $course) {
  1108. $is_coach_course = api_is_coach(
  1109. $session_id,
  1110. $course['real_id']
  1111. );
  1112. $allowedEndTime = true;
  1113. if ($is_coach_course) {
  1114. if ($date_session_start != '0000-00-00 00:00:00') {
  1115. $allowed_time = api_strtotime($coachAccessStartDate);
  1116. }
  1117. if (!isset($_GET['history'])) {
  1118. if ($date_session_end != '0000-00-00 00:00:00') {
  1119. $endSessionToTms = api_strtotime($date_session_end);
  1120. if ($session_now > $endSessionToTms) {
  1121. $allowedEndTime = false;
  1122. }
  1123. }
  1124. }
  1125. } else {
  1126. $allowed_time = api_strtotime(
  1127. $date_session_start
  1128. );
  1129. }
  1130. if ($session_now >= $allowed_time && $allowedEndTime) {
  1131. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1132. $c = CourseManager:: get_logged_user_course_html(
  1133. $course,
  1134. $session_id,
  1135. 'session_course_item'
  1136. );
  1137. $html_courses_session[] = $c[1];
  1138. }
  1139. $count_courses_session++;
  1140. $count++;
  1141. }
  1142. }
  1143. $sessionParams = array();
  1144. // Category
  1145. if ($count > 0) {
  1146. $session_box = Display:: get_session_title_box($session_id);
  1147. $sessionParams['id'] = $session_id;
  1148. //$sessionParams['show_link_to_session'] = !api_is_drh() && $sessionTitleLink;
  1149. $sessionParams['course_list_session_style'] = $coursesListSessionStyle;
  1150. $sessionParams['title'] = $session_box['title'];
  1151. $sessionParams['subtitle'] = (!empty($session_box['coach'])
  1152. ? $session_box['coach'] . ' | '
  1153. : '') . $session_box['dates'];
  1154. $sessionParams['show_actions'] = api_is_platform_admin();
  1155. $sessionParams['courses'] = $html_courses_session;
  1156. $sessionParams['show_simple_session_info'] = false;
  1157. if (
  1158. isset($_configuration['show_simple_session_info']) &&
  1159. $_configuration['show_simple_session_info']
  1160. ) {
  1161. $sessionParams['show_simple_session_info'] = true;
  1162. }
  1163. $this->tpl->assign('session', $sessionParams);
  1164. $html_sessions .= $this->tpl->fetch(
  1165. $this->tpl->get_template('user_portal/session.tpl')
  1166. );
  1167. $sessionCount++;
  1168. }
  1169. }
  1170. }
  1171. if ($count_courses_session > 0) {
  1172. $categoryParams = array(
  1173. 'id' => $session_category['session_category']['id'],
  1174. 'title' => $session_category['session_category']['name'],
  1175. 'show_actions' => api_is_platform_admin(),
  1176. 'subtitle' => null,
  1177. 'sessions' => $html_sessions
  1178. );
  1179. $session_category_start_date = $session_category['session_category']['date_start'];
  1180. $session_category_end_date = $session_category['session_category']['date_end'];
  1181. if (
  1182. !empty($session_category_start_date) &&
  1183. $session_category_start_date != '0000-00-00' &&
  1184. !empty($session_category_end_date) &&
  1185. $session_category_end_date != '0000-00-00'
  1186. ) {
  1187. $categoryParams['subtitle'] = sprintf(
  1188. get_lang('FromDateXToDateY'),
  1189. $session_category['session_category']['date_start'],
  1190. $session_category['session_category']['date_end']
  1191. );
  1192. } else {
  1193. if (
  1194. !empty($session_category_start_date) &&
  1195. $session_category_start_date != '0000-00-00'
  1196. ) {
  1197. $categoryParams['subtitle'] = get_lang('From') . ' ' . $session_category_start_date;
  1198. }
  1199. if (
  1200. !empty($session_category_end_date) &&
  1201. $session_category_end_date != '0000-00-00'
  1202. ) {
  1203. $categoryParams['subtitle'] = get_lang('Until') . ' ' . $session_category_end_date;
  1204. }
  1205. }
  1206. $this->tpl->assign('session_category', $categoryParams);
  1207. $sessions_with_category .= $this->tpl->fetch(
  1208. "{$this->tpl->templateFolder}/user_portal/session_category.tpl"
  1209. );
  1210. }
  1211. }
  1212. }
  1213. }
  1214. return [
  1215. 'html' => $sessions_with_category.$sessions_with_no_category.$courses_html.$special_courses,
  1216. 'session_count' => $sessionCount,
  1217. 'course_count' => $courseCount
  1218. ];
  1219. }
  1220. /**
  1221. * Shows a welcome message when the user doesn't have any content in the course list
  1222. */
  1223. public function return_welcome_to_course_block()
  1224. {
  1225. $count_courses = CourseManager::count_courses();
  1226. $tpl = $this->tpl->get_template('layout/welcome_to_course.tpl');
  1227. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  1228. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  1229. $this->tpl->assign('course_catalog_url', $course_catalog_url);
  1230. $this->tpl->assign('course_list_url', $course_list_url);
  1231. $this->tpl->assign('course_catalog_link', Display::url(get_lang('Here'), $course_catalog_url));
  1232. $this->tpl->assign('course_list_link', Display::url(get_lang('Here'), $course_list_url));
  1233. $this->tpl->assign('count_courses', $count_courses);
  1234. return $this->tpl->fetch($tpl);
  1235. }
  1236. /**
  1237. * @return array
  1238. */
  1239. public function return_hot_courses()
  1240. {
  1241. return CourseManager::return_hot_courses(30, 6);
  1242. }
  1243. /**
  1244. * UserPortal view for session, return the HTLK of the course list
  1245. * @param $user_id
  1246. * @return string
  1247. */
  1248. public function returnCoursesAndSessionsViewBySession($user_id)
  1249. {
  1250. $sessionCount = 0;
  1251. $courseCount = 0;
  1252. $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
  1253. if ($load_history) {
  1254. //Load sessions in category in *history*
  1255. $session_categories = UserManager::get_sessions_by_category($user_id, true);
  1256. } else {
  1257. //Load sessions in category
  1258. $session_categories = UserManager::get_sessions_by_category($user_id, false);
  1259. }
  1260. $html = '';
  1261. //Showing history title
  1262. if ($load_history) {
  1263. $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  1264. if (empty($session_categories)) {
  1265. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  1266. }
  1267. }
  1268. $specialCourses = '';
  1269. $loadDirs = $this->load_directories_preview;
  1270. // If we're not in the history view...
  1271. $listCoursesInfo = array();
  1272. if (!isset($_GET['history'])) {
  1273. // Display special courses
  1274. $specialCoursesResult = CourseManager::display_special_courses(
  1275. $user_id,
  1276. $loadDirs
  1277. );
  1278. $specialCourses = $specialCoursesResult['html'];
  1279. // Display courses
  1280. // [code=>xxx, real_id=>000]
  1281. $listCourses = CourseManager::get_courses_list_by_user_id($user_id, false);
  1282. foreach ($listCourses as $i => $listCourseCodeId) {
  1283. list($userCategoryId, $userCatTitle) = CourseManager::getUserCourseCategoryForCourse(
  1284. $user_id,
  1285. $listCourseCodeId['real_id']
  1286. );
  1287. $listCourse = api_get_course_info_by_id($listCourseCodeId['real_id']);
  1288. $listCoursesInfo[] = array(
  1289. 'course' => $listCourse,
  1290. 'code' => $listCourseCodeId['code'],
  1291. 'id' => $listCourseCodeId['real_id'],
  1292. 'title' => $listCourse['title'],
  1293. 'userCatId' => $userCategoryId,
  1294. 'userCatTitle' => $userCatTitle
  1295. );
  1296. $courseCount++;
  1297. }
  1298. usort($listCoursesInfo, 'self::compareByCourse');
  1299. }
  1300. if (is_array($session_categories)) {
  1301. // all courses that are in a session
  1302. $listCoursesInSession = SessionManager::getNamedSessionCourseForCoach($user_id);
  1303. }
  1304. // we got all courses
  1305. // for each user category, sorted alphabetically, display courses
  1306. $listUserCategories = CourseManager::get_user_course_categories($user_id);
  1307. $listCoursesAlreadyDisplayed = array();
  1308. uasort($listUserCategories, "self::compareListUserCategory");
  1309. $listUserCategories[0] = '';
  1310. $html = '<div class="session-view-block">';
  1311. foreach ($listUserCategories as $userCategoryId => $userCatTitle) {
  1312. // add user category
  1313. $userCategoryHtml = '';
  1314. if ($userCategoryId != 0) {
  1315. $userCategoryHtml = '<div class="session-view-well ">';
  1316. }
  1317. $userCategoryHtml .= self::getHtmlForUserCategory($userCategoryId, $userCatTitle);
  1318. // look for course in this userCat in session courses : $listCoursesInSession
  1319. $htmlCategory = '';
  1320. if (isset($listCoursesInSession[$userCategoryId])) {
  1321. // list of courses in this user cat
  1322. foreach ($listCoursesInSession[$userCategoryId]['courseInUserCatList'] as $i => $listCourse) {
  1323. // add course
  1324. $listCoursesAlreadyDisplayed[$listCourse['courseId']] = 1;
  1325. if ($userCategoryId == 0) {
  1326. $htmlCategory .= '<div class="session-view-well session-view-row well" >';
  1327. } else {
  1328. $htmlCategory .= '<div class="session-view-row" >';
  1329. }
  1330. $coursesInfo = $listCourse['course'];
  1331. $htmlCategory .= self::getHtmlForCourse(
  1332. $coursesInfo,
  1333. $userCategoryId,
  1334. 1,
  1335. $loadDirs
  1336. );
  1337. // list of session category
  1338. $htmlSessionCategory = '<div class="session-view-row" style="display:none;" id="courseblock-'.$coursesInfo['real_id'].'">';
  1339. foreach ($listCourse['sessionCatList'] as $j => $listCategorySession) {
  1340. // add session category
  1341. $htmlSessionCategory .= self::getHtmlSessionCategory(
  1342. $listCategorySession['catSessionId'],
  1343. $listCategorySession['catSessionName']
  1344. );
  1345. // list of session
  1346. $htmlSession = ''; // start
  1347. foreach ($listCategorySession['sessionList'] as $k => $listSession) {
  1348. // add session
  1349. $htmlSession .= '<div class="session-view-row">';
  1350. $htmlSession .= self::getHtmlForSession(
  1351. $listSession['sessionId'],
  1352. $listSession['sessionName'],
  1353. $listCategorySession['catSessionId'],
  1354. $coursesInfo
  1355. );
  1356. $htmlSession .= '</div>';
  1357. $sessionCount++;
  1358. }
  1359. $htmlSession .= ''; // end session block
  1360. $htmlSessionCategory .= $htmlSession;
  1361. }
  1362. $htmlSessionCategory .= '</div>'; // end session cat block
  1363. $htmlCategory .= $htmlSessionCategory .'</div>' ;
  1364. $htmlCategory .= ''; // end course block
  1365. }
  1366. $userCategoryHtml .= $htmlCategory;
  1367. }
  1368. // look for courses in this userCat in not in session courses : $listCoursesInfo
  1369. // if course not already added
  1370. $htmlCategory = '';
  1371. foreach ($listCoursesInfo as $i => $listCourse) {
  1372. if ($listCourse['userCatId'] == $userCategoryId && !isset($listCoursesAlreadyDisplayed[$listCourse['id']])) {
  1373. if ($userCategoryId != 0) {
  1374. $htmlCategory .= '<div class="session-view-row" >';
  1375. } else {
  1376. $htmlCategory .= '<div class="session-view-well well">';
  1377. }
  1378. $htmlCategory .= self::getHtmlForCourse(
  1379. $listCourse['course'],
  1380. $userCategoryId,
  1381. 0,
  1382. $loadDirs
  1383. );
  1384. $htmlCategory .= '</div>';
  1385. }
  1386. }
  1387. $htmlCategory .= '';
  1388. $userCategoryHtml .= $htmlCategory; // end user cat block
  1389. if ($userCategoryId != 0) {
  1390. $userCategoryHtml .= '</div>';
  1391. }
  1392. $html .= $userCategoryHtml; //
  1393. }
  1394. $html .= '</div>';
  1395. return [
  1396. 'html' => $html.$specialCourses,
  1397. 'session_count' => $sessionCount,
  1398. 'course_count' => $courseCount
  1399. ];
  1400. }
  1401. /**
  1402. * Return HTML code for personal user course category
  1403. * @param $id
  1404. * @param $title
  1405. * @return string
  1406. */
  1407. private static function getHtmlForUserCategory($id, $title)
  1408. {
  1409. if ($id == 0) {
  1410. return '';
  1411. }
  1412. $icon = Display::return_icon(
  1413. 'folder_yellow.png',
  1414. $title,
  1415. array('class' => 'sessionView'),
  1416. ICON_SIZE_LARGE
  1417. );
  1418. return "<div class='session-view-user-category'>$icon<span>$title</span></div>";
  1419. }
  1420. /**
  1421. * return HTML code for course display in session view
  1422. * @param array $courseInfo
  1423. * @param $userCategoryId
  1424. * @param bool $displayButton
  1425. * @param $loadDirs
  1426. * @return string
  1427. */
  1428. private static function getHtmlForCourse(
  1429. $courseInfo,
  1430. $userCategoryId,
  1431. $displayButton = false,
  1432. $loadDirs
  1433. ) {
  1434. if (empty($courseInfo)) {
  1435. return '';
  1436. }
  1437. $id = $courseInfo['real_id'];
  1438. $title = $courseInfo['title'];
  1439. $code = $courseInfo['code'];
  1440. $class = 'session-view-lvl-6';
  1441. if ($userCategoryId != 0 && !$displayButton) {
  1442. $class = 'session-view-lvl-7';
  1443. }
  1444. $class2 = 'session-view-lvl-6';
  1445. if ($displayButton || $userCategoryId != 0) {
  1446. $class2 = 'session-view-lvl-7';
  1447. }
  1448. $button = '';
  1449. if ($displayButton) {
  1450. $button = '<input id="session-view-button-'.intval($id).'" class="session-view-button btn btn-default" type="button" onclick="hideUnhide(\'courseblock-'.intval($id).'\', \'session-view-button-'.intval($id).'\', \'+\', \'-\')" value="+" />';
  1451. }
  1452. $icon = Display::return_icon(
  1453. 'blackboard.png',
  1454. $title,
  1455. array('class' => 'sessionView'),
  1456. ICON_SIZE_LARGE
  1457. );
  1458. $courseLink = $courseInfo['course_public_url'].'?id_session=0';
  1459. // get html course params
  1460. // ['right_actions'] ['teachers'] ['notifications']
  1461. $tabParams = CourseManager::getCourseParamsForDisplay($id, $loadDirs);
  1462. // teacher list
  1463. if (!empty($tabParams['teachers'])) {
  1464. $teachers = '<p class="'.$class2.' view-by-session-teachers">'.$tabParams['teachers'].'</p>';
  1465. }
  1466. // notification
  1467. if (!empty($tabParams['right_actions'])) {
  1468. $rightActions = '<div class="view-by-session-right-actions">'.$tabParams['right_actions'].'</div>';
  1469. }
  1470. return "<div>
  1471. $button
  1472. <span class='$class'>$icon
  1473. <a class='sessionView' href='$courseLink'>$title</a>
  1474. </span>".$tabParams['notifications']."$rightActions
  1475. </div>
  1476. $teachers";
  1477. }
  1478. /**
  1479. * return HTML code for session category
  1480. * @param $id
  1481. * @param $title
  1482. * @return string
  1483. */
  1484. private static function getHtmlSessionCategory($id, $title)
  1485. {
  1486. if ($id == 0) {
  1487. return '';
  1488. }
  1489. $icon = Display::return_icon(
  1490. 'folder_blue.png',
  1491. $title,
  1492. array('class' => 'sessionView'),
  1493. ICON_SIZE_LARGE
  1494. );
  1495. return "<div class='session-view-session-category'>
  1496. <span class='session-view-lvl-2'>
  1497. $icon
  1498. <span>$title</span>
  1499. </span>
  1500. </div>";
  1501. }
  1502. /**
  1503. * return HTML code for session
  1504. * @param int $id session id
  1505. * @param string $title session title
  1506. * @param int $categorySessionId
  1507. * @param array $courseInfo
  1508. *
  1509. * @return string
  1510. */
  1511. private static function getHtmlForSession($id, $title, $categorySessionId, $courseInfo)
  1512. {
  1513. $html = '';
  1514. if ($categorySessionId == 0) {
  1515. $class1 = 'session-view-lvl-2'; // session
  1516. $class2 = 'session-view-lvl-4'; // got to course in session link
  1517. } else {
  1518. $class1 = 'session-view-lvl-3'; // session
  1519. $class2 = 'session-view-lvl-5'; // got to course in session link
  1520. }
  1521. $icon = Display::return_icon(
  1522. 'blackboard_blue.png',
  1523. $title,
  1524. array('class' => 'sessionView'),
  1525. ICON_SIZE_LARGE
  1526. );
  1527. $courseLink = $courseInfo['course_public_url'].'?id_session='.intval($id);
  1528. $html .= "<span class='$class1 session-view-session'>$icon$title</span>";
  1529. $html .= '<div class="'.$class2.' session-view-session-go-to-course-in-session">
  1530. <a class="" href="'.$courseLink.'">'.get_lang('GoToCourseInsideSession').'</a></div>';
  1531. return '<div>'.$html.'</div>';
  1532. }
  1533. /**
  1534. * @param $listA
  1535. * @param $listB
  1536. * @return int
  1537. */
  1538. private static function compareByCourse($listA, $listB)
  1539. {
  1540. if ($listA['userCatTitle'] == $listB['userCatTitle']) {
  1541. if ($listA['title'] == $listB['title']) {
  1542. return 0;
  1543. } else if($listA['title'] > $listB['title']) {
  1544. return 1;
  1545. } else {
  1546. return -1;
  1547. }
  1548. } else if ($listA['userCatTitle'] > $listB['userCatTitle']) {
  1549. return 1;
  1550. } else {
  1551. return -1;
  1552. }
  1553. }
  1554. /**
  1555. * @param $listA
  1556. * @param $listB
  1557. * @return int
  1558. */
  1559. public static function compareListUserCategory($listA, $listB)
  1560. {
  1561. if ($listA['title'] == $listB['title']) {
  1562. return 0;
  1563. } else if($listA['title'] > $listB['title']) {
  1564. return 1;
  1565. } else {
  1566. return -1;
  1567. }
  1568. }
  1569. /**
  1570. * @param $view
  1571. * @param $userId
  1572. */
  1573. public static function setDefaultMyCourseView($view, $userId)
  1574. {
  1575. setcookie('defaultMyCourseView'.$userId, $view);
  1576. }
  1577. }