page.lib.php 56 KB

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