userportal.lib.php 107 KB

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