page.lib.php 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. <?php
  2. /**
  3. * Controller for pages presentation in general
  4. * @license see /license.txt
  5. * @package chamilo.page.controller
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. */
  8. /**
  9. * Page controller
  10. */
  11. use Silex\Application;
  12. use Pagerfanta\Adapter\FixedAdapter;
  13. use Pagerfanta\Pagerfanta;
  14. use Pagerfanta\View\TwitterBootstrapView;
  15. class PageController
  16. {
  17. public $app;
  18. public $maxPerPage = 2;
  19. function __construct(Application $app) {
  20. $this->app = $app;
  21. }
  22. /**
  23. * Returns an HTML block with the user picture (as a link in a <div>)
  24. * @param int User ID (if not provided, will use the user ID from session)
  25. * @return string HTML div with a link to the user's profile
  26. * @uses UserManager::get_user_pictur_path_by_id() to get the image path
  27. * @uses UserManager::get_picture_user() to get the details of the image in a specific format
  28. * @uses PageController::show_right_block() to include the image in a larger user block
  29. * @assert (-1) === false
  30. */
  31. public function return_user_image_block($user_id = null) {
  32. if (empty($user_id)) {
  33. $user_id = api_get_user_id();
  34. }
  35. //Always show the user image
  36. $img_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true, true);
  37. $no_image = false;
  38. if ($img_array['file'] == 'unknown.jpg') {
  39. $no_image = true;
  40. }
  41. $img_array = UserManager::get_picture_user($user_id, $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  42. $profile_content = null;
  43. if (api_get_setting('allow_social_tool') == 'true') {
  44. if (!$no_image) {
  45. $profile_content .='<a style="text-align:center" href="'.api_get_path(WEB_CODE_PATH).'social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' ></a>';
  46. } else {
  47. $profile_content .='<a style="text-align:center" href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].'></a>';
  48. }
  49. }
  50. $this->show_right_block(null, null, 'user_image_block', array('content' => $profile_content));
  51. }
  52. /**
  53. * Return a block with course-related links. The resulting HTML block's
  54. * contents are only based on the user defined by the active session.
  55. *
  56. * @return string HTML <div> with links
  57. * @assert () != ''
  58. */
  59. public function return_course_block($filter = null) {
  60. $show_create_link = false;
  61. $show_course_link = false;
  62. if ((api_get_setting('allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) || api_is_student()) {
  63. $display_add_course_link = false;
  64. } else {
  65. $display_add_course_link = true;
  66. }
  67. if ($display_add_course_link) {
  68. $show_create_link = true;
  69. }
  70. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  71. $show_course_link = true;
  72. } else {
  73. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  74. $show_course_link = true;
  75. }
  76. }
  77. // My account section
  78. $my_account_content = array();
  79. if ($show_create_link) {
  80. $my_account_content[] = array(
  81. 'href' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php',
  82. 'title' => api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate'));
  83. }
  84. //Sort courses
  85. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  86. $my_account_content[] = array(
  87. 'href' => $url,
  88. 'title' => get_lang('SortMyCourses')
  89. );
  90. //Course management
  91. if ($show_course_link) {
  92. if (!api_is_drh()) {
  93. $my_account_content[] = array('href' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'title' => get_lang('CourseCatalog'));
  94. if (isset($filter) && $filter == 'history') {
  95. $my_account_content[] = array(
  96. 'href' => api_get_path(WEB_PUBLIC_PATH).'userportal',
  97. 'title' => get_lang('DisplayTrainingList')
  98. );
  99. } else {
  100. $my_account_content[] = array(
  101. 'href' => api_get_path(WEB_PUBLIC_PATH).'userportal/history',
  102. 'title' => get_lang('HistoryTrainingSessions')
  103. );
  104. }
  105. } else {
  106. $my_account_content .= array(
  107. 'href' => api_get_path(WEB_CODE_PATH).'dashboard/index.php',
  108. 'title' => get_lang('Dashboard')
  109. );
  110. }
  111. }
  112. $this->show_right_block(get_lang('Courses'), $my_account_content, 'course_block');
  113. }
  114. /**
  115. * Returns the profile block, showing links to the messaging and social
  116. * network tools. The user ID is taken from the active session
  117. * @return string HTML <div> block
  118. * @assert () != ''
  119. */
  120. public function return_profile_block() {
  121. if (api_get_setting('allow_message_tool') == 'true') {
  122. if (api_get_setting('allow_social_tool') == 'true') {
  123. $this->show_right_block(get_lang('Profile'), array(), 'profile_social_block');
  124. } else {
  125. $this->show_right_block(get_lang('Profile'), array(), 'profile_block');
  126. }
  127. }
  128. }
  129. function getSectionCourseBlock() {
  130. $app = $this->app;
  131. $courseURL = $app['url_generator']->generate('userportal', array('type' => 'courses'));
  132. $sessionURL = $app['url_generator']->generate('userportal', array('type' => 'sessions'));
  133. $myCourseCategoriesURL = $app['url_generator']->generate('userportal', array('type' => 'mycoursecategories'));
  134. $specialCoursesURL = $app['url_generator']->generate('userportal', array('type' => 'specialcourses'));
  135. $sessionCategoriesURL = $app['url_generator']->generate('userportal', array('type' => 'sessioncategories'));
  136. $params = array(
  137. array('href' => $courseURL, 'title' => get_lang('Courses')),
  138. array('href' => $specialCoursesURL, 'title' => get_lang('SpecialCourses')),
  139. array('href' => $myCourseCategoriesURL, 'title' => get_lang('MyCourseCategories')),
  140. array('href' => $sessionURL, 'title' => get_lang('Sessions')),
  141. array('href' => $sessionCategoriesURL, 'title' => get_lang('SessionsCategories')),
  142. );
  143. $this->show_right_block(get_lang('CourseSessionBlock'), $params, 'course_session_block');
  144. }
  145. /**
  146. * Returns a list of the most popular courses of the moment (also called
  147. * "hot courses").
  148. * @uses CourseManager::return_hot_courses() in fact, the current method is only a bypass to this method
  149. * @return string HTML <div> with the most popular courses
  150. * @assert () != ''
  151. */
  152. public function return_hot_courses() {
  153. return CourseManager::return_hot_courses();
  154. }
  155. /**
  156. * Returns an online help block read from the home/home_menu_[lang].html
  157. * file
  158. * @return string HTML block
  159. * @assert () != ''
  160. */
  161. public function return_help() {
  162. $home = api_get_home_path();
  163. $user_selected_language = api_get_interface_language();
  164. $sys_path = api_get_path(SYS_PATH);
  165. $platformLanguage = api_get_setting('platformLanguage');
  166. if (!isset($user_selected_language)) {
  167. $user_selected_language = $platformLanguage;
  168. }
  169. $home_menu = @(string) file_get_contents($sys_path.$home.'home_menu_'.$user_selected_language.'.html');
  170. if (!empty($home_menu)) {
  171. $home_menu_content = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  172. $this->show_right_block(get_lang('MenuGeneral'), null, 'help_block', array('content' => $home_menu_content));
  173. }
  174. }
  175. /**
  176. * Returns an HTML block with links to the skills tools
  177. * @return string HTML <div> block
  178. * @assert () != ''
  179. */
  180. public function return_skills_links() {
  181. if (api_get_setting('allow_skills_tool') == 'true') {
  182. $content = array();
  183. $content[]= array('title' => get_lang('MySkills'), 'href' => api_get_path(WEB_CODE_PATH).'social/skills_wheel.php');
  184. if (api_get_setting('allow_hr_skills_management') == 'true' || api_is_platform_admin()) {
  185. $content[]= array('title' => get_lang('ManageSkills'), 'href' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php');
  186. }
  187. $this->show_right_block(get_lang("Skills"), $content, 'skill_block');
  188. }
  189. }
  190. /**
  191. * Returns an HTML block with the notice, as found in the
  192. * home/home_notice_[lang].html file
  193. * @return string HTML <div> block
  194. * @assert () != ''
  195. */
  196. public function return_notice() {
  197. $sys_path = api_get_path(SYS_PATH);
  198. $user_selected_language = api_get_interface_language();
  199. $home = api_get_home_path();
  200. // Notice
  201. $home_notice = @(string) file_get_contents($sys_path.$home.'home_notice_'.$user_selected_language.'.html');
  202. if (empty($home_notice)) {
  203. $home_notice = @(string) file_get_contents($sys_path.$home.'home_notice.html');
  204. }
  205. if (!empty($home_notice)) {
  206. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  207. $home_notice = Display::div($home_notice, array('class' => 'homepage_notice'));
  208. $this->show_right_block(get_lang('Notice'), null, 'notice_block', array('content' => $home_notice));
  209. }
  210. }
  211. /**
  212. * Returns the received content packaged in <div> block, with the title as
  213. * <h4>
  214. * @param string Title to include as h4
  215. * @param string Longer content to show (usually a <ul> list)
  216. * @param string ID to be added to the HTML attributes for the block
  217. * @param array Array of attributes to add to the HTML block
  218. * @return string HTML <div> block
  219. * @assert ('a','') != ''
  220. * @todo use the menu builder
  221. */
  222. public function show_right_block($title, $content, $id, $params = null) {
  223. $app = $this->app;
  224. if (!empty($id)) {
  225. $params['id'] = $id;
  226. }
  227. $block_menu = array(
  228. 'id' => $params['id'],
  229. 'title' => $title,
  230. 'elements' => $content,
  231. 'content' => isset($params['content']) ? $params['content'] : null
  232. );
  233. $app['template']->assign($id, $block_menu);
  234. }
  235. /**
  236. * Adds a form to let users login
  237. * @return string An HTML string with the user login form
  238. * @assert () != ''
  239. * @version 1.1
  240. */
  241. public function display_login_form() {
  242. $form = new FormValidator('formLogin', 'POST', null, null, array('class' => 'form-vertical'));
  243. // 'placeholder'=>get_lang('UserName')
  244. //'autocomplete'=>"off",
  245. $form->addElement('text', 'login', get_lang('UserName'), array('class' => 'span2 autocapitalize_off', 'autofocus' => 'autofocus'));
  246. $form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2'));
  247. $form->addElement('style_submit_button', 'submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));
  248. $html = $form->return_form();
  249. if (api_get_setting('openid_authentication') == 'true') {
  250. include_once 'main/auth/openid/login.php';
  251. $html .= '<div>'.openid_form().'</div>';
  252. }
  253. return $html;
  254. }
  255. /**
  256. * Returns a content search form in an HTML <div>, pointing at the
  257. * main/search/ directory. If search_enabled is not set, then it returns
  258. * an empty string
  259. * @return string HTML <div> block showing the search form, or an empty string if search not enabled
  260. * @assert () !== false
  261. */
  262. public function return_search_block() {
  263. $html = '';
  264. if (api_get_setting('search_enabled') == 'true') {
  265. $html .= '<div class="searchbox">';
  266. $search_btn = get_lang('Search');
  267. $search_content = '<br />
  268. <form action="main/search/" method="post">
  269. <input type="text" id="query" class="span2" name="query" value="" />
  270. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  271. </form></div>';
  272. $html .= $this->show_right_block(get_lang('Search'), $search_content, 'search_block');
  273. }
  274. return $html;
  275. }
  276. /**
  277. * Returns a list of announcements
  278. * @param int User ID
  279. * @param bool True: show the announcements as a slider. False: show them as a vertical list
  280. * @return string HTML list of announcements
  281. * @assert () != ''
  282. * @assert (1) != ''
  283. */
  284. public function return_announcements($user_id = null, $show_slide = true) {
  285. // Display System announcements
  286. $announcement = isset($_GET['announcement']) ? intval($_GET['announcement']) : null;
  287. if (!api_is_anonymous() && $user_id) {
  288. $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
  289. if ($show_slide) {
  290. $announcements = SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);
  291. } else {
  292. $announcements = SystemAnnouncementManager :: display_all_announcements($visibility, $announcement);
  293. }
  294. } else {
  295. if ($show_slide) {
  296. $announcements = SystemAnnouncementManager :: display_announcements_slider(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
  297. } else {
  298. $announcements = SystemAnnouncementManager :: display_all_announcements(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
  299. }
  300. }
  301. return $announcements;
  302. }
  303. /**
  304. * Return the homepage, including announcements
  305. * @return string The portal's homepage as an HTML string
  306. * @assert () != ''
  307. */
  308. public function return_home_page() {
  309. // Including the page for the news
  310. $html = null;
  311. $home = api_get_home_path();
  312. $home_top_temp = null;
  313. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  314. $open = @(string) file_get_contents(api_get_path(SYS_PATH).$home.$_GET['include']);
  315. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  316. } else {
  317. if (!empty($_SESSION['user_language_choice'])) {
  318. $user_selected_language = $_SESSION['user_language_choice'];
  319. } elseif (!empty($_SESSION['_user']['language'])) {
  320. $user_selected_language = $_SESSION['_user']['language'];
  321. } else {
  322. $user_selected_language = api_get_setting('platformLanguage');
  323. }
  324. if (!file_exists($home.'home_news_'.$user_selected_language.'.html')) {
  325. if (file_exists($home.'home_top.html')) {
  326. $home_top_temp = file($home.'home_top.html');
  327. } else {
  328. //$home_top_temp = file('home/'.'home_top.html');
  329. }
  330. if (!empty($home_top_temp)) {
  331. $home_top_temp = implode('', $home_top_temp);
  332. }
  333. } else {
  334. if (file_exists($home.'home_top_'.$user_selected_language.'.html')) {
  335. $home_top_temp = file_get_contents($home.'home_top_'.$user_selected_language.'.html');
  336. } else {
  337. $home_top_temp = file_get_contents($home.'home_top.html');
  338. }
  339. }
  340. //trim($home_top_temp) == ''
  341. if (empty($home_top_temp) && api_is_platform_admin()) {
  342. $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
  343. }
  344. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  345. if (!empty($open)) {
  346. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  347. }
  348. }
  349. return $html;
  350. }
  351. /**
  352. * Returns the reservation block (if the reservation tool is enabled)
  353. * @return string HTML block, or empty string if reservation tool is disabled
  354. * @assert () == ''
  355. */
  356. public function return_reservation_block() {
  357. $html = '';
  358. $booking_content = null;
  359. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  360. $booking_content .='<ul class="nav nav-list">';
  361. $booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  362. $booking_content .='</ul>';
  363. $html .= $this->show_right_block(get_lang('Booking'), $booking_content, 'reservation_block');
  364. }
  365. return $html;
  366. }
  367. /**
  368. * Returns an HTML block with classes (if show_groups_to_users is true)
  369. * @return string A list of links to users classes tools, or an empty string if show_groups_to_users is disabled
  370. * @assert () == ''
  371. */
  372. public function return_classes_block() {
  373. $html = '';
  374. if (api_get_setting('show_groups_to_users') == 'true') {
  375. $usergroup = new Usergroup();
  376. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  377. $classes = '';
  378. if (!empty($usergroup_list)) {
  379. foreach ($usergroup_list as $group_id) {
  380. $data = $usergroup->get($group_id);
  381. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  382. $classes .= Display::tag('li', $data['name']);
  383. }
  384. }
  385. if (api_is_platform_admin()) {
  386. $classes .= Display::tag('li', Display::url(get_lang('AddClasses'), api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
  387. }
  388. if (!empty($classes)) {
  389. $classes = Display::tag('ul', $classes, array('class' => 'nav nav-list'));
  390. $html .= $this->show_right_block(get_lang('Classes'), $classes, 'classes_block');
  391. }
  392. }
  393. return $html;
  394. }
  395. /**
  396. * Prepares a block with all the pending exercises in all courses
  397. * @param array Array of courses (arrays) of the user
  398. * @return void Doesn't return anything but prepares and HTML block for use in templates
  399. * @assert () !== 1
  400. */
  401. public function return_exercise_block($personal_course_list, $tpl) {
  402. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  403. $exercise_list = array();
  404. if (!empty($personal_course_list)) {
  405. foreach ($personal_course_list as $course_item) {
  406. $course_code = $course_item['c'];
  407. $session_id = $course_item['id_session'];
  408. $exercises = get_exercises_to_be_taken($course_code, $session_id);
  409. foreach ($exercises as $exercise_item) {
  410. $exercise_item['course_code'] = $course_code;
  411. $exercise_item['session_id'] = $session_id;
  412. $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC');
  413. $exercise_list[] = $exercise_item;
  414. }
  415. }
  416. if (!empty($exercise_list)) {
  417. $exercise_list = ArrayClass::msort($exercise_list, 'tms');
  418. $my_exercise = $exercise_list[0];
  419. $url = Display::url($my_exercise['title'], api_get_path(WEB_CODE_PATH).'exercice/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']);
  420. $tpl->assign('exercise_url', $url);
  421. $tpl->assign('exercise_end_date', api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT));
  422. }
  423. }
  424. }
  425. /**
  426. * Returns links to teachers tools (create course, etc) based on the user
  427. * in the active session
  428. * @return string HTML <div> block
  429. * @assert () == ''
  430. */
  431. public function return_teacher_link() {
  432. $user_id = api_get_user_id();
  433. if (!empty($user_id)) {
  434. // tabs that are deactivated are added here
  435. $show_menu = false;
  436. $show_create_link = false;
  437. $show_course_link = false;
  438. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  439. $show_menu = true;
  440. $show_course_link = true;
  441. } else {
  442. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  443. $show_menu = true;
  444. $show_course_link = true;
  445. }
  446. }
  447. if ($show_menu && ($show_create_link || $show_course_link )) {
  448. $show_menu = true;
  449. } else {
  450. $show_menu = false;
  451. }
  452. }
  453. // My Account section
  454. $elements = array();
  455. if ($show_menu) {
  456. if ($show_create_link) {
  457. $elements[] = array(
  458. 'href' => api_get_path(WEB_CODE_PATH).'create_course/add_course.php',
  459. 'title' => (api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')));
  460. }
  461. if ($show_course_link) {
  462. if (!api_is_drh() && !api_is_session_admin()) {
  463. $elements[] = array('href' => api_get_path(WEB_CODE_PATH).'auth/courses.php', 'title' => get_lang('CourseCatalog'));
  464. } else {
  465. $elements[] = array('href' => api_get_path(WEB_CODE_PATH).'dashboard/index.php', 'title' => get_lang('Dashboard'));
  466. }
  467. }
  468. }
  469. $this->show_right_block(get_lang('Courses'), $elements, 'teacher_block');
  470. }
  471. /**
  472. * Display list of courses in a category.
  473. * (for anonymous users)
  474. *
  475. * @version 1.1
  476. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  477. * @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
  478. * @assert () !== 0
  479. */
  480. public function return_courses_in_categories() {
  481. $result = '';
  482. $stok = Security::get_token();
  483. // Initialization.
  484. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  485. $web_course_path = api_get_path(WEB_COURSE_PATH);
  486. $category = Database::escape_string($_GET['category']);
  487. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  488. // Database table definitions.
  489. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  490. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  491. // Get list of courses in category $category.
  492. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  493. WHERE category_code = '".Database::escape_string($_GET['category'])."'
  494. ORDER BY title, UPPER(visual_code)";
  495. // Showing only the courses of the current access_url_id.
  496. if (api_is_multiple_url_enabled()) {
  497. $url_access_id = api_get_current_access_url_id();
  498. if ($url_access_id != -1) {
  499. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  500. $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
  501. ON (url_rel_course.course_code=course.code)
  502. WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string($_GET['category'])."' ORDER BY title, UPPER(visual_code)";
  503. }
  504. }
  505. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  506. $sql_result_courses = Database::query($sql_get_course_list);
  507. while ($course_result = Database::fetch_array($sql_result_courses)) {
  508. $course_list[] = $course_result;
  509. }
  510. $platform_visible_courses = '';
  511. // $setting_show_also_closed_courses
  512. if ($user_identified) {
  513. if ($setting_show_also_closed_courses) {
  514. $platform_visible_courses = '';
  515. } else {
  516. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  517. }
  518. } else {
  519. if ($setting_show_also_closed_courses) {
  520. $platform_visible_courses = '';
  521. } else {
  522. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  523. }
  524. }
  525. $sqlGetSubCatList = "
  526. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  527. FROM $main_category_table t1
  528. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  529. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  530. WHERE t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  531. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  532. // Showing only the category of courses of the current access_url_id
  533. if (api_is_multiple_url_enabled()) {
  534. $url_access_id = api_get_current_access_url_id();
  535. if ($url_access_id != -1) {
  536. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  537. $sqlGetSubCatList = "
  538. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  539. FROM $main_category_table t1
  540. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  541. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  542. INNER JOIN $tbl_url_rel_course as url_rel_course
  543. ON (url_rel_course.course_code=t3.code)
  544. WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  545. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  546. }
  547. }
  548. $resCats = Database::query($sqlGetSubCatList);
  549. $thereIsSubCat = false;
  550. if (Database::num_rows($resCats) > 0) {
  551. $htmlListCat = Display::page_header(get_lang('CatList'));
  552. $htmlListCat .= '<ul>';
  553. while ($catLine = Database::fetch_array($resCats)) {
  554. if ($catLine['code'] != $category) {
  555. $category_has_open_courses = $this->category_has_open_courses($catLine['code']);
  556. if ($category_has_open_courses) {
  557. // The category contains courses accessible to anonymous visitors.
  558. $htmlListCat .= '<li>';
  559. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  560. if (api_get_setting('show_number_of_courses') == 'true') {
  561. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  562. }
  563. $htmlListCat .= "</li>";
  564. $thereIsSubCat = true;
  565. } elseif ($catLine['children_count'] > 0) {
  566. // The category has children, subcategories.
  567. $htmlListCat .= '<li>';
  568. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  569. $htmlListCat .= "</li>";
  570. $thereIsSubCat = true;
  571. }
  572. /* End changed code to eliminate the (0 courses) after empty categories. */ elseif (api_get_setting('show_empty_course_categories') == 'true') {
  573. $htmlListCat .= '<li>';
  574. $htmlListCat .= $catLine['name'];
  575. $htmlListCat .= "</li>";
  576. $thereIsSubCat = true;
  577. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  578. } else {
  579. $htmlTitre = '<p>';
  580. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  581. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  582. }
  583. if (!is_null($catLine['parent_id']) || (api_get_setting('show_back_link_on_top_of_tree') != 'true' && !is_null($catLine['code']))) {
  584. $htmlTitre .= '<a href="'.api_get_self().'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
  585. }
  586. $htmlTitre .= "</p>";
  587. if ($category != "" && !is_null($catLine['code'])) {
  588. $htmlTitre .= '<h3>'.$catLine['name']."</h3>";
  589. } else {
  590. $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>";
  591. }
  592. }
  593. }
  594. $htmlListCat .= "</ul>";
  595. }
  596. $result .= $htmlTitre;
  597. if ($thereIsSubCat) {
  598. $result .= $htmlListCat;
  599. }
  600. while ($categoryName = Database::fetch_array($resCats)) {
  601. $result .= '<h3>'.$categoryName['name']."</h3>\n";
  602. }
  603. $numrows = Database::num_rows($sql_result_courses);
  604. $courses_list_string = '';
  605. $courses_shown = 0;
  606. if ($numrows > 0) {
  607. $courses_list_string .= Display::page_header(get_lang('CourseList'));
  608. $courses_list_string .= "<ul>";
  609. if (api_get_user_id()) {
  610. $courses_of_user = $this->get_courses_of_user(api_get_user_id());
  611. }
  612. foreach ($course_list as $course) {
  613. // $setting_show_also_closed_courses
  614. if (!$setting_show_also_closed_courses) {
  615. // If we do not show the closed courses
  616. // we only show the courses that are open to the world (to everybody)
  617. // and the courses that are open to the platform (if the current user is a registered user.
  618. if (($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  619. $courses_shown++;
  620. $courses_list_string .= "<li>\n";
  621. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  622. $course_details = array();
  623. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  624. $course_details[] = $course['visual_code'];
  625. }
  626. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  627. $course_details[] = $course['tutor_name'];
  628. }
  629. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  630. $course_details[] = $course['course_language'];
  631. }
  632. $courses_list_string .= implode(' - ', $course_details);
  633. $courses_list_string .= "</li>\n";
  634. }
  635. } else {
  636. // We DO show the closed courses.
  637. // The course is accessible if (link to the course homepage):
  638. // 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);
  639. // 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);
  640. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  641. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  642. // 5. the user is the platform admin api_is_platform_admin().
  643. //
  644. $courses_shown++;
  645. $courses_list_string .= "<li>\n";
  646. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  647. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  648. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  649. || $courses_of_user[$course['code']]['status'] == '1'
  650. || api_is_platform_admin()) {
  651. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  652. }
  653. $courses_list_string .= $course['title'];
  654. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  655. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  656. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  657. || $courses_of_user[$course['code']]['status'] == '1'
  658. || api_is_platform_admin()) {
  659. $courses_list_string .= '</a><br />';
  660. }
  661. $course_details = array();
  662. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  663. $course_details[] = $course['visual_code'];
  664. }
  665. // if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  666. // $courses_list_string .= ' - ';
  667. // }
  668. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  669. $course_details[] = $course['tutor_name'];
  670. }
  671. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  672. $course_details[] = $course['course_language'];
  673. }
  674. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  675. $course_details[] = $course['course_language'];
  676. }
  677. $courses_list_string .= implode(' - ', $course_details);
  678. // We display a subscription link if:
  679. // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
  680. // 2.
  681. if ($user_identified && !key_exists($course['code'], $courses_of_user)) {
  682. if ($course['subscribe'] == '1') {
  683. $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS($_GET['category']).'" method="post">';
  684. $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
  685. $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
  686. $courses_list_string .= '<input type="image" name="unsub" src="main/img/enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'</form>';
  687. } else {
  688. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  689. }
  690. }
  691. $courses_list_string .= "</li>";
  692. } //end else
  693. } // end foreach
  694. $courses_list_string .= "</ul>";
  695. }
  696. if ($courses_shown > 0) {
  697. // Only display the list of courses and categories if there was more than
  698. // 0 courses visible to the world (we're in the anonymous list here).
  699. $result .= $courses_list_string;
  700. }
  701. if ($category != '') {
  702. $result .= '<p><a href="'.api_get_self().'"> '.Display :: return_icon('back.png', get_lang('BackToHomePage')).get_lang('BackToHomePage').'</a></p>';
  703. }
  704. return $result;
  705. }
  706. public function returnMyCourseCategories($user_id, $filter, $page) {
  707. if (empty($user_id)) {
  708. return false;
  709. }
  710. $loadDirs = api_get_setting('show_documents_preview') == 'true' ? true : false;
  711. $start = ($page -1) * $this->maxPerPage;
  712. $nbResults = (int) CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, true);
  713. $html = CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
  714. $adapter = new FixedAdapter($nbResults, array());
  715. $pagerfanta = new Pagerfanta($adapter);
  716. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  717. $pagerfanta->setCurrentPage($page); // 1 by default
  718. $view = new TwitterBootstrapView();
  719. $app = $this->app;
  720. //{type}/{category}/{filter}/{page}
  721. $routeGenerator = function($page) use ($app, $filter) {
  722. return $app['url_generator']->generate('userportal', array(
  723. 'filter' => $filter,
  724. 'type' => 'courses',
  725. 'page' => $page)
  726. );
  727. };
  728. $pagination = $view->render($pagerfanta, $routeGenerator, array(
  729. 'proximity' => 3,
  730. ));
  731. return $html.$pagination;
  732. }
  733. function returnSpecialCourses($user_id, $filter, $page)
  734. {
  735. if (empty($user_id)) {
  736. return false;
  737. }
  738. $loadDirs = api_get_setting('show_documents_preview') == 'true' ? true : false;
  739. $start = ($page -1) * $this->maxPerPage;
  740. $nbResults = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, true);
  741. $html = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
  742. if (!empty($html)) {
  743. $adapter = new FixedAdapter($nbResults, array());
  744. $pagerfanta = new Pagerfanta($adapter);
  745. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  746. $pagerfanta->setCurrentPage($page); // 1 by default
  747. $view = new TwitterBootstrapView();
  748. $app = $this->app;
  749. $routeGenerator = function($page) use ($app, $filter) {
  750. return $app['url_generator']->generate('userportal', array(
  751. 'filter' => $filter,
  752. 'type' => 'courses',
  753. 'page' => $page)
  754. );
  755. };
  756. $pagination = $view->render($pagerfanta, $routeGenerator, array(
  757. 'proximity' => 3,
  758. ));
  759. $html .= $pagination;
  760. }
  761. return $html;
  762. }
  763. /**
  764. * The most important function here, prints the session and course list (user_portal.php)
  765. *
  766. * @param int User ID
  767. * @param string filter
  768. * @param int page
  769. * @return string HTML list of sessions and courses
  770. * @assert () === false
  771. *
  772. */
  773. public function returnCourses($user_id, $filter, $page)
  774. {
  775. if (empty($user_id)) {
  776. return false;
  777. }
  778. $loadDirs = api_get_setting('show_documents_preview') == 'true' ? true : false;
  779. $start = ($page -1) * $this->maxPerPage;
  780. $nbResults = CourseManager::displayCourses($user_id, $filter, $loadDirs, true);
  781. $html = CourseManager::displayCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
  782. if (!empty($html)) {
  783. $adapter = new FixedAdapter($nbResults, array());
  784. $pagerfanta = new Pagerfanta($adapter);
  785. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  786. $pagerfanta->setCurrentPage($page); // 1 by default
  787. $view = new TwitterBootstrapView();
  788. $app = $this->app;
  789. $routeGenerator = function($page) use ($app, $filter) {
  790. return $app['url_generator']->generate('userportal', array(
  791. 'filter' => $filter,
  792. 'type' => 'courses',
  793. 'page' => $page)
  794. );
  795. };
  796. $pagination = $view->render($pagerfanta, $routeGenerator, array(
  797. 'proximity' => 3,
  798. ));
  799. $html .= $pagination;
  800. }
  801. return $html;
  802. }
  803. public function returnSessionsCategories($user_id, $filter, $page)
  804. {
  805. if (empty($user_id)) {
  806. return false;
  807. }
  808. $load_history = (isset($filter) && $filter == 'history') ? true : false;
  809. $start = ($page -1) * $this->maxPerPage;
  810. $nbResults = UserManager::getCategories($user_id, false, true, true);
  811. $session_categories = UserManager::getCategories($user_id, false, false, true, $start, $this->maxPerPage);
  812. $html = null;
  813. //Showing history title
  814. if ($load_history) {
  815. $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  816. if (empty($session_categories)) {
  817. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  818. }
  819. }
  820. $load_directories_preview = api_get_setting('show_documents_preview') == 'true' ? true : false;
  821. $sessions_with_category = $html;
  822. if (isset($session_categories) && !empty($session_categories)) {
  823. foreach ($session_categories as $session_category) {
  824. $session_category_id = $session_category['session_category']['id'];
  825. // All sessions included in
  826. $count_courses_session = 0;
  827. $html_sessions = '';
  828. foreach ($session_category['sessions'] as $session) {
  829. $session_id = $session['session_id'];
  830. // Don't show empty sessions.
  831. if (count($session['courses']) < 1) {
  832. continue;
  833. }
  834. $html_courses_session = '';
  835. $count = 0;
  836. foreach ($session['courses'] as $course) {
  837. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  838. $html_courses_session .= CourseManager::get_logged_user_course_html($course, $session_id);
  839. }
  840. $count_courses_session++;
  841. $count++;
  842. }
  843. $params = array();
  844. if ($count > 0) {
  845. $params['icon'] = Display::return_icon('window_list.png', $session['session_name'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
  846. //Default session name
  847. $session_link = $session['session_name'];
  848. $params['link'] = null;
  849. if (api_get_setting('session_page_enabled') == 'true' && !api_is_drh()) {
  850. //session name with link
  851. $session_link = Display::tag('a', $session['session_name'], array('href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
  852. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  853. }
  854. $params['title'] = $session_link;
  855. $moved_status = SessionManager::get_session_change_user_reason($session['moved_status']);
  856. $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
  857. $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
  858. $params['dates'] = $session['date_message'];
  859. if (api_is_platform_admin()) {
  860. $params['right_actions'] = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
  861. }
  862. $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
  863. }
  864. }
  865. if ($count_courses_session > 0) {
  866. $params = array();
  867. $params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
  868. if (api_is_platform_admin()) {
  869. $params['right_actions'] = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
  870. }
  871. $params['title'] = $session_category['session_category']['name'];
  872. if (api_is_platform_admin()) {
  873. $params['link'] = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
  874. }
  875. $session_category_start_date = $session_category['session_category']['date_start'];
  876. $session_category_end_date = $session_category['session_category']['date_end'];
  877. if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
  878. $params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
  879. } else {
  880. if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
  881. $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
  882. }
  883. if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
  884. $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
  885. }
  886. }
  887. $sessions_with_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_sessions);
  888. }
  889. }
  890. $adapter = new FixedAdapter($nbResults, array());
  891. $pagerfanta = new Pagerfanta($adapter);
  892. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  893. $pagerfanta->setCurrentPage($page); // 1 by default
  894. $view = new TwitterBootstrapView();
  895. $app = $this->app;
  896. $routeGenerator = function($page) use ($app, $filter) {
  897. return $app['url_generator']->generate('userportal', array(
  898. 'filter' => $filter,
  899. 'type' => 'sessioncategories',
  900. 'page' => $page
  901. ));
  902. };
  903. $pagination = $view->render($pagerfanta, $routeGenerator, array(
  904. 'proximity' => 3,
  905. ));
  906. $sessions_with_category .= $pagination;
  907. }
  908. return $sessions_with_category;
  909. }
  910. public function returnSessions($user_id, $filter, $page) {
  911. if (empty($user_id)) {
  912. return false;
  913. }
  914. $app = $this->app;
  915. $loadHistory = (isset($filter) && $filter == 'history') ? true : false;
  916. $app['session_menu'] = function($app) use ($loadHistory) {
  917. $menu = $app['knp_menu.factory']->createItem('root');
  918. $menu->setUri($app['request']->getRequestUri());
  919. $menu->setChildrenAttributes(array(
  920. 'class' => 'nav nav-tabs',
  921. 'currentClass' => 'active'
  922. ));
  923. $current = $menu->addChild(get_lang('Current'), array(
  924. 'route' => 'userportal',
  925. 'routeParameters' => array(
  926. 'filter' => 'current',
  927. 'type' => 'sessions'
  928. )
  929. )
  930. );
  931. $history = $menu->addChild(get_lang('HistoryTrainingSession'), array(
  932. 'route' => 'userportal',
  933. 'routeParameters' => array(
  934. 'filter' => 'history',
  935. 'type' => 'sessions'
  936. )
  937. )
  938. );
  939. //@todo use URIVoter
  940. if ($loadHistory) {
  941. $history->setCurrent(true);
  942. } else {
  943. $current->setCurrent(true);
  944. }
  945. return $menu;
  946. };
  947. //@todo move this in template
  948. $app['knp_menu.menus'] = array('actions_menu' => 'session_menu');
  949. $start = ($page -1) * $this->maxPerPage;
  950. if ($loadHistory) {
  951. //Load sessions in category in *history*
  952. $nbResults = (int) UserManager::get_sessions_by_category($user_id, true, true, true, null, null, 'no_category');
  953. $session_categories = UserManager::get_sessions_by_category($user_id, true, false, true, $start, $this->maxPerPage, 'no_category');
  954. } else {
  955. //Load sessions in category
  956. $nbResults = (int) UserManager::get_sessions_by_category($user_id, false, true, false, null, null, 'no_category');
  957. $session_categories = UserManager::get_sessions_by_category($user_id, false, false, false, $start, $this->maxPerPage, 'no_category');
  958. }
  959. $html = null;
  960. //Showing history title
  961. if ($loadHistory) {
  962. // $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
  963. if (empty($session_categories)) {
  964. $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
  965. }
  966. }
  967. $load_directories_preview = api_get_setting('show_documents_preview') == 'true' ? true : false;
  968. $sessions_with_no_category = $html;
  969. if (isset($session_categories) && !empty($session_categories)) {
  970. foreach ($session_categories as $session_category) {
  971. $session_category_id = $session_category['session_category']['id'];
  972. // Sessions does not belong to a session category
  973. if ($session_category_id == 0) {
  974. // Independent sessions
  975. if (isset($session_category['sessions'])) {
  976. foreach ($session_category['sessions'] as $session) {
  977. $session_id = $session['session_id'];
  978. // Don't show empty sessions.
  979. if (count($session['courses']) < 1) {
  980. continue;
  981. }
  982. $html_courses_session = '';
  983. $count_courses_session = 0;
  984. foreach ($session['courses'] as $course) {
  985. //Read only and accessible
  986. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  987. $html_courses_session .= CourseManager::get_logged_user_course_html($course, $session_id, $load_directories_preview);
  988. }
  989. $count_courses_session++;
  990. }
  991. if ($count_courses_session > 0) {
  992. $params = array();
  993. $params['icon'] = Display::return_icon('window_list.png', $session['session_name'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
  994. $params['is_session'] = true;
  995. //Default session name
  996. $session_link = $session['session_name'];
  997. $params['link'] = null;
  998. if (api_get_setting('session_page_enabled') == 'true' && !api_is_drh()) {
  999. //session name with link
  1000. $session_link = Display::tag('a', $session['session_name'], array('href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
  1001. $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
  1002. }
  1003. $params['title'] = $session_link;
  1004. $moved_status = SessionManager::get_session_change_user_reason($session['moved_status']);
  1005. $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
  1006. $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
  1007. $params['dates'] = $session['date_message'];
  1008. $params['right_actions'] = '';
  1009. if (api_is_platform_admin()) {
  1010. $params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">';
  1011. $params['right_actions'] .= Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
  1012. }
  1013. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1014. // $params['extra'] .= $html_courses_session;
  1015. }
  1016. $sessions_with_no_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_courses_session);
  1017. }
  1018. }
  1019. }
  1020. }
  1021. }
  1022. $adapter = new FixedAdapter($nbResults, array());
  1023. $pagerfanta = new Pagerfanta($adapter);
  1024. $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
  1025. $pagerfanta->setCurrentPage($page); // 1 by default
  1026. $view = new TwitterBootstrapView();
  1027. $app = $this->app;
  1028. $routeGenerator = function($page) use ($app, $filter) {
  1029. return $app['url_generator']->generate('userportal', array(
  1030. 'filter' => $filter,
  1031. 'type' => 'sessions',
  1032. 'page' => $page)
  1033. );
  1034. };
  1035. $pagination = $view->render($pagerfanta, $routeGenerator, array(
  1036. 'proximity' => 3,
  1037. ));
  1038. $sessions_with_no_category .= $pagination;
  1039. }
  1040. return $sessions_with_no_category;
  1041. }
  1042. /**
  1043. * Shows a welcome message when the user doesn't have any content in
  1044. * the course list
  1045. * @param object A Template object used to declare variables usable in the given template
  1046. * @return void
  1047. * @assert () === false
  1048. */
  1049. public function return_welcome_to_course_block($tpl) {
  1050. if (empty($tpl)) {
  1051. return false;
  1052. }
  1053. $count_courses = CourseManager::count_courses();
  1054. $course_catalog_url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
  1055. $course_list_url = api_get_path(WEB_PATH).'user_portal.php';
  1056. $tpl->assign('course_catalog_url', $course_catalog_url);
  1057. $tpl->assign('course_list_url', $course_list_url);
  1058. $tpl->assign('course_catalog_link', Display::url(get_lang('here'), $course_catalog_url));
  1059. $tpl->assign('course_list_link', Display::url(get_lang('here'), $course_list_url));
  1060. $tpl->assign('count_courses', $count_courses);
  1061. $tpl->assign('welcome_to_course_block', 1);
  1062. }
  1063. }