From db07d1f0f686b1c9987e3453e27358d84d65ec25 Mon Sep 17 00:00:00 2001 From: baelmyhu Date: Thu, 2 Apr 2015 11:39:03 +0200 Subject: [PATCH] View by session for My courses tab - version 1.9.10.2 --- main/css/base.css | 106 +++++++ main/inc/lib/course.lib.php | 174 ++++++++++- main/inc/lib/sessionmanager.lib.php | 392 +++++++++++++++++++++++- main/inc/lib/template.lib.php | 6 +- main/inc/lib/userportal.lib.php | 286 +++++++++++++++++ main/install/configuration.dist.php | 3 +- main/template/default/layout/footer.tpl | 19 ++ user_portal.php | 52 +++- 8 files changed, 1025 insertions(+), 13 deletions(-) diff --git a/main/css/base.css b/main/css/base.css index c18c900e1c..921bf8c974 100755 --- a/main/css/base.css +++ b/main/css/base.css @@ -5315,3 +5315,109 @@ i.size-32.icon-new-work{ #settings .span6:nth-child(2n+1) { clear:left } + +/* CSS for the view by session My Course tab */ +.session-view-block { + font-size : 14px; + font-weight : normal; +} + +.session-view-row { + padding: 8px 0; +} + +.session-view-lvl-2 { + margin-left : 66px; +} + +.session-view-lvl-3 { + padding-left : 92px; +} + +.session-view-lvl-4 { + padding-left : 102px; +} + +.session-view-lvl-5 { + padding-left : 128px; + font-weight : normal; +} + +.session-view-lvl-6 { + padding-left : 20px; +} + +.session-view-lvl-7 { + padding-left : 48px; +} + +img.sessionView { + padding-right: 10px; +} + +a.sessionView { + font-weight : bold; +} + +.session-view-user-category { + font-weight : bold; + padding-bottom : 10px; +} + +.session-view-session-category { + font-weight : bold; + padding-bottom : 10px; +} + +.session-view-session { + font-weight : bold; +} + +/* Like the well class */ +.session-view-well { + min-height: 20px; + padding: 19px; + margin-bottom: 20px; + background-color: #F5F5F5; + border: 1px solid rgba(0, 0, 0, 0.05); + border-radius: 4px; + box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.05) inset; +} + +.session-view-button { + border : none; + min-width : 28px; +} + +.view-by-session-link { + text-align: right; +} + +p.view-by-session-link a { + padding-right : 10px; + padding-left : 10px; +} + +.view-by-session-active { + text-decoration : underline; +} + +.view-by-session-teachers { + display : none; /* change this if you want to display teachers name in this view */ + font-size : 10px; + overflow-x : auto; + overflow-y: auto; + max-height:50px; +} + +.view-by-session-right-actions { + float : right; +} + +.view-by-session-right-actions img { + width : 12px; +} + +.session-view-session-go-to-course-in-session { + font-size : 12px; +} diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index ea2de9f004..cadb2f799f 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3906,17 +3906,151 @@ class CourseManager return $html; } + + /** + * return html code for diaplaying a course title in the standart view (not the Session view) + * @param $courseId + * @param bool $loadDirs + * @return string + */ + public static function displayCourseHtml($courseId, $loadDirs = false) + { + $params = self::getCourseParamsForDisplay($courseId, $loadDirs); + $html = self::course_item_html($params, false); + return $html; + } + + + /** + * Return tab of params to display a course title in the My Courses tab + * Check visibility, right, and notification icones, and load_dirs option + * @param $courseId + * @param bool $loadDirs + * @return array + */ + public static function getCourseParamsForDisplay($courseId, $loadDirs = false) + { + $user_id = api_get_user_id(); + // Table definitions + $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE); + $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $TABLE_ACCESS_URL_REL_COURSE = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $current_url_id = api_get_current_access_url_id(); + + // Get course list auto-register + $special_course_list = self::get_special_course_list(); + + $without_special_courses = ''; + if (!empty($special_course_list)) { + $without_special_courses = ' AND course.code NOT IN ("'.implode('","',$special_course_list).'")'; + } + + //AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." + $sql = "SELECT course.id, course.title, course.code, course.subscribe subscr, course.unsubscribe unsubscr, course_rel_user.status status, + course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat + FROM $TABLECOURS course, + $TABLECOURSUSER course_rel_user, ".$TABLE_ACCESS_URL_REL_COURSE." url + WHERE course.id=".intval($courseId)." + AND course.code = course_rel_user.course_code + AND url.course_code = course.code + AND course_rel_user.user_id = ".intval($user_id)." + $without_special_courses "; + + // If multiple URL access mode is enabled, only fetch courses + // corresponding to the current URL. + if (api_get_multiple_access_url() && $current_url_id != -1) { + $sql .= " AND url.course_code=course.code AND access_url_id=".intval($current_url_id); + } + // Use user's classification for courses (if any). + $sql .= " ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC"; + + $result = Database::query($sql); + + // Browse through all courses. We can only have one course because of the course.id=".intval($courseId) in sql query + $course = Database::fetch_array($result); + $course_info = api_get_course_info($course['code']); + //$course['id_session'] = null; + $course_info['id_session'] = null; + $course_info['status'] = $course['status']; + + // For each course, get if there is any notification icon to show + // (something that would have changed since the user's last visit). + $show_notification = Display :: show_notification($course_info); + + // New code displaying the user's status in respect to this course. + $status_icon = Display::return_icon('blackboard.png', $course_info['title'], array(), ICON_SIZE_LARGE); + + $params = array(); + $params['right_actions'] = ''; + + if (api_is_platform_admin()) { + if ($loadDirs) { + $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + $params['right_actions'] .= ''.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course_info['real_id'].'_0', 'class'=>'document_preview_container')); + } else { + $params['right_actions'].= ''.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + } + + if ($course_info['status'] == COURSEMANAGER) { + //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style'=>'width: 11px; height: 11px;')); + } + } else { + if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) { + if ($loadDirs) { + $params['right_actions'] .= ''.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + $params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course_info['real_id'].'_0', 'class'=>'document_preview_container')); + } else { + if ($course_info['status'] == COURSEMANAGER) { + $params['right_actions'].= ''.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).''; + } + } + } + } + + $course_title_url = ''; + if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED || $course['status'] == COURSEMANAGER) { + $course_title_url = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/?id_session=0'; + $course_title = Display::url($course_info['title'], $course_title_url); + } else { + $course_title = $course_info['title']." ".Display::tag('span',get_lang('CourseClosed'), array('class'=>'item_closed')); + } + + // Start displaying the course block itself + if (api_get_setting('display_coursecode_in_courselist') == 'true') { + $course_title .= ' ('.$course_info['visual_code'].') '; + } + $teachers = ''; + if (api_get_setting('display_teacher_in_courselist') == 'true') { + $teachers = CourseManager::get_teacher_list_from_course_code_to_string($course['code'], self::USER_SEPARATOR, true); + } + $params['link'] = $course_title_url; + $params['icon'] = $status_icon; + $params['title'] = $course_title; + $params['teachers'] = $teachers; + if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) { + $params['notifications'] = $show_notification; + } + + return $params; + } + + /** * Retrieves the user defined course categories - * @author Patrick Cool , Ghent University + * @param string $userId * @return array containing all the titles of the user defined courses with the id as key of the array */ - public static function get_user_course_categories() + public static function get_user_course_categories($userId = "") { - global $_user; + if ($userId == "") { + $realUserId = api_get_user_id(); + } else { + $realUserId = $userId; + } $output = array(); $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); - $sql = "SELECT * FROM ".$table_category." WHERE user_id='".intval($_user['user_id'])."'"; + $sql = "SELECT * FROM ".$table_category." WHERE user_id='".intval($realUserId)."'"; $result = Database::query($sql); while ($row = Database::fetch_array($result)) { $output[$row['id']] = $row['title']; @@ -3924,6 +4058,38 @@ class CourseManager return $output; } + /** + * Return an array the user_category id and title for the course $courseId for user $userId + * @param $userId + * @param $courseId + * @return array + */ + public static function getUserCourseCategoryForCourse($userId, $courseId) + { + $result = array(); + $tblCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER); + $tblUserCategory = Database::get_main_table(TABLE_USER_COURSE_CATEGORY); + $courseInfo = api_get_course_info_by_id($courseId); + $courseCode = $courseInfo['code']; + + $sql = 'SELECT user_course_cat, title + FROM '.$tblCourseRelUser.' cru + LEFT JOIN '.$tblUserCategory.' ucc + ON cru.user_course_cat = ucc.id + WHERE cru.user_id='.intval($userId).' + AND course_code="'.$courseCode.'";'; + + $res = Database::query($sql); + if (Database::num_rows($res) > 0) { + $data = Database::fetch_assoc($res); + $result[] = $data['user_course_cat']; + $result[] = $data['title']; + } + return $result; + } + + + /** * Get the course id based on the original id and field name in the extra fields. * Returns 0 if course was not found diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 77f460337c..6e493e93a3 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -3006,11 +3006,9 @@ class SessionManager $session_id = intval($session_id); $sqlSelect = "SELECT *"; - if ($getCount) { $sqlSelect = "SELECT COUNT(1)"; } - // select the courses $sql = "$sqlSelect FROM $tbl_course c INNER JOIN $tbl_session_rel_course src @@ -3040,10 +3038,8 @@ class SessionManager if ($num_rows > 0) { if ($getCount) { $count = Database::fetch_array($result); - return intval($count[0]); } - while ($row = Database::fetch_array($result,'ASSOC')) { $courses[$row['id']] = $row; } @@ -5533,7 +5529,6 @@ class SessionManager . "GROUP BY u.user_id"; $result = Database::query($sql); - $list = array(); while ($data = Database::fetch_assoc($result)) { @@ -5543,4 +5538,391 @@ class SessionManager return $list; } + /** + * Return an associative array 'id_course' => [id_session1, id_session2...] + * where course id_course is in sessions id_session1, id_session2 * for course where user is coach + * i.e. coach for the course or + * main coach for a session the course is in + * for a session category (or woth no session category if empty) + * + * @param $userId + */ + public static function getSessionCourseForUser($userId) + { + // list of COURSES where user is COURSE session coach + $listCourseCourseCoachSession = self::getCoursesForCourseSessionCoach($userId); + // list of courses where user is MAIN session coach + $listCourseMainCoachSession = self::getCoursesForMainSessionCoach($userId); + + // merge these 2 array + $listResCourseSession = $listCourseCourseCoachSession; + foreach ($listCourseMainCoachSession as $courseId2 => $listSessionId2) { + if (isset($listResCourseSession[$courseId2])) { + // if sessionId array exists for this course + // same courseId, merge the list of session + foreach ($listCourseMainCoachSession[$courseId2] as $i => $sessionId2) { + if (!in_array($sessionId2, $listResCourseSession[$courseId2])) { + $listResCourseSession[$courseId2][] = $sessionId2; + } + } + } else { + $listResCourseSession[$courseId2] = $listSessionId2; + } + } + return $listResCourseSession; + } + + + /** + * Return an array of courses in session for user + * and for each courses the list of session that use this course for user + * + * [0] => array + * userCatId + * userCatTitle + * courseInUserCatList + * [0] => array + * courseId + * title + * courseCode + * sessionCatList + * [0] => array + * catSessionId + * catSessionName + * sessionList + * [0] => array + * sessionId + * sessionName + * + * @param $userId + * @return array + * + */ + public static function getNamedSessionCourseForCoach($userId) + { + $listResults = array(); + $listCourseSession = self::getSessionCourseForUser($userId); + foreach ($listCourseSession as $courseId => $listSessionId) { + + // course info + $courseInfo = CourseManager::get_course_information_by_id($courseId); + $listOneCourse = array(); + $listOneCourse['courseId'] = $courseId; + $listOneCourse['title'] = $courseInfo['title']; + $listOneCourse['courseCode'] = $courseInfo['code']; + $listOneCourse['sessionCatList'] = array(); + $listCat = array(); + foreach ($listSessionId as $i => $sessionId) { + // here we got all session for this course + // lets check there session categories + $sessionInfo = SessionManager::fetch($sessionId); + $catId = $sessionInfo['session_category_id']; + if (!isset($listCat[$catId])) { + $listCatInfo = self::get_session_category($catId); + $listCat[$catId] = array(); + $listCat[$catId]['catSessionId'] = $catId; + $listCat[$catId]['catSessionName'] = $listCatInfo['name']; + $listCat[$catId]['sessionList'] = array(); + } + $listSessionInfo = SessionManager::fetch($sessionId); + $listSessionIdName = array("sessionId" => $sessionId, "sessionName" => $listSessionInfo['name']); + $listCat[$catId]['sessionList'][] = $listSessionIdName; + } + // sort $listCat by catSessionName + usort($listCat, 'self::compareBySessionName'); + // in each catSession sort sessionList by sessionName + foreach($listCat as $i => $listCatSessionInfo) { + $listSessionList = $listCatSessionInfo['sessionList']; + usort($listSessionList, 'self::compareCatSessionInfo'); + $listCat[$i]['sessionList'] = $listSessionList; + } + + $listOneCourse['sessionCatList'] = $listCat; + + // user course category + list($userCatId, $userCatTitle) = CourseManager::getUserCourseCategoryForCourse($userId, $courseId); + $userCatId = intval($userCatId); + $listResults[$userCatId]['courseInUserCategoryId'] = $userCatId; + $listResults[$userCatId]['courseInUserCategoryTitle'] = $userCatTitle; + $listResults[$userCatId]['courseInUserCatList'][] = $listOneCourse; + } + + // sort by user course cat + uasort($listResults, 'self::compareByUserCourseCat'); + + // sort by course title + foreach ($listResults as $userCourseCatId => $tabCoursesInCat) { + $courseInUserCatList = $tabCoursesInCat['courseInUserCatList']; + uasort($courseInUserCatList, 'self::compareByCourse'); + $listResults[$userCourseCatId]['courseInUserCatList'] = $courseInUserCatList; + } + + return $listResults; + } + + + /** + * @param array $listA + * @param array $listB + * @return int + */ + private static function compareCatSessionInfo($listA, $listB) + { + if ($listA['sessionName'] == $listB['sessionName']) { + return 0; + } else if($listA['sessionName'] > $listB['sessionName']) { + return 1; + } else { + return -1; + } + } + + + /** + * @param array $listA + * @param array $listB + * @return int + */ + private static function compareBySessionName($listA, $listB) + { + if ($listB['catSessionName'] == '') { + return -1; + } else if ($listA['catSessionName'] == '') { + return 1; + } else if ($listA['catSessionName'] == $listB['catSessionName']) { + return 0; + } else if($listA['catSessionName'] > $listB['catSessionName']) { + return 1; + } else { + return -1; + } + } + + + /** + * @param array $listA + * @param array $listB + * @return int + */ + private static function compareByUserCourseCat($listA, $listB) + { + if ($listA['courseInUserCategoryTitle'] == $listB['courseInUserCategoryTitle']) { + return 0; + } else if($listA['courseInUserCategoryTitle'] > $listB['courseInUserCategoryTitle']) { + return 1; + } else { + return -1; + } + } + + + /** + * @param array $listA + * @param array $listB + * @return int + */ + private static function compareByCourse($listA, $listB) + { + if ($listA['title'] == $listB['title']) { + return 0; + } else if($listA['title'] > $listB['title']) { + return 1; + } else { + return -1; + } + } + + + + /** + * Return HTML code for displaying session_course_for_coach + * @param $userId + * @return string + */ + public static function getHtmlNamedSessionCourseForCoach($userId) + { + $htmlRes = ''; + + $listInfo = self::getNamedSessionCourseForCoach($userId); + foreach($listInfo as $i => $listCoursesInfo) { + $courseCode = $listCoursesInfo['courseCode']; + $courseTitle = $listCoursesInfo['title']; + $listParamsCourse = array(); + $listParamsCourse['icon'] = '
'.Display::return_icon('blackboard.png', $listCoursesInfo['title'], array(), ICON_SIZE_LARGE); +// $listParamsCourse['link'] = api_get_path(WEB_PATH).'courses/'.$listCoursesInfo['courseCode']; + $listParamsCourse['link'] = ''; + $listParamsCourse['title'] = Display::tag('a', $listCoursesInfo['title'], array('href'=>$listParamsCourse['link'])); + $htmlCourse = '
'.CourseManager::course_item_html($listParamsCourse, true); +// $params['subtitle'] + // for each category of session + $htmlCatSessions = ''; + foreach ($listCoursesInfo['sessionCatList'] as $j => $listCatSessionsInfo) { + // we got an array of session categories + $catSessionId = $listCoursesInfo['sessionCatList'][$j]['catSessionId']; + $catSessionName = $listCoursesInfo['sessionCatList'][$j]['catSessionName']; + + $listParamsCatSession['icon'] = Display::return_icon('folder_blue.png', $catSessionName, array(), ICON_SIZE_LARGE); + $listParamsCatSession['link'] = ''; + $listParamsCatSession['title'] = $catSessionName; + + $marginShift = 20; + if ($catSessionName != '') { + $htmlCatSessions .= '
' . CourseManager::course_item_html($listParamsCatSession, true) . '
'; + $marginShift = 40; + } + + // for each sessions + $listCatSessionSessionList = $listCoursesInfo['sessionCatList'][$j]['sessionList']; + $htmlSession = ''; + foreach ($listCatSessionSessionList as $k => $listSessionInfo) { + // we got an array of session info + $sessionId = $listSessionInfo['sessionId']; + $sessionName = $listSessionInfo['sessionName']; + + $listParamsSession['icon'] = Display::return_icon('blackboard_blue.png', $sessionName, array(), ICON_SIZE_LARGE); + $listParamsSession['link'] = ''; + $linkToCourseSession = api_get_path(WEB_PATH).'courses/'.$courseCode.'/?id_session='.$sessionId; + $listParamsSession['title'] = $sessionName.'
Aller au cours dans la session
'; + $htmlSession .= '
'.CourseManager::course_item_html($listParamsSession, true).'
'; + } + $htmlCatSessions .= $htmlSession; + } + $htmlRes .= $htmlCourse.'
'; + } + + return $htmlRes; + } + + /** + * Return an associative array 'id_course' => [id_session1, id_session2...] + * where course id_course is in sessions id_session1, id_session2 + * @param $userId + * @return array + */ + public static function getCoursesForCourseSessionCoach($userId) + { + $listResCourseSession = array(); + $tblCourse = Database::get_main_table(TABLE_MAIN_COURSE); + $tblSessionRelCourseRelUser = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); + $tblSession = Database::get_main_table(TABLE_MAIN_SESSION); + + $sql = "SELECT id_session, course_code, c.id + FROM $tblSessionRelCourseRelUser srcru + + LEFT JOIN $tblCourse c + ON c.code = srcru.course_code + + WHERE + srcru.id_user=".intval($userId)." + AND srcru.status = 2"; + + $res = Database::query($sql); + + while ($data = Database::fetch_assoc($res)) { + if (self::isSessionDateOkForCoach($data['id_session'])) { + if (!isset($listResCourseSession[$data['id']])) { + $listResCourseSession[$data['id']] = array(); + } + $listResCourseSession[$data['id']][] = $data['id_session']; + } + } + return $listResCourseSession; + } + + + /** + * Return true if coach is allowed to access this session + * @param $inSessionId + * @param $inCoachId + * @return bool + */ + public static function isSessionDateOkForCoach($sessionId) + { + $listSessionInfo = api_get_session_info($sessionId); + $dateStart = $listSessionInfo['date_start']; + $dateEnd = $listSessionInfo['date_end']; + $nbDaysAccessBeforeBeginning = $listSessionInfo['nb_days_access_before_beginning']; + $nbDaysAccessAfterEnd = $listSessionInfo['nb_days_access_after_end']; + + // no start date + if ($dateStart == '0000-00-00') { + return true; + } + + $now = time(); + + $dateStartForCoach = api_strtotime($dateStart.' 00:00:00') - ($nbDaysAccessBeforeBeginning * 86400); + $dateEndForCoach = api_strtotime($dateEnd.' 00:00:00') + ($nbDaysAccessAfterEnd * 86400); + + if ($dateEnd == '0000-00-00') { + // start date but no end date + if ($dateStartForCoach <= $now) { + return true; + } + } else { + // start date and end date + if ($dateStartForCoach <= $now && $now <= $dateEndForCoach) { + return true; + } + } + + return false; + } + + /** + * Return an associative array 'id_course' => [id_session1, id_session2...] + * where course id_course is in sessions id_session1, id_session2 + * @param $userId + * @return array + */ + public static function getCoursesForMainSessionCoach($userId) + { + $listResCourseSession = array(); + $tblSession = Database::get_main_table(TABLE_MAIN_SESSION); + + // list of SESSION where user is session coach + $sql = "SELECT id FROM $tblSession + WHERE id_coach = ".intval($userId); + $res = Database::query($sql); + + while ($data = Database::fetch_assoc($res)) { + $sessionId = $data['id']; + $listCoursesInSession = self::getCoursesInSession($sessionId); + foreach ($listCoursesInSession as $i => $courseId) { + if (self::isSessionDateOkForCoach($sessionId)) { + if (!isset($listResCourseSession[$courseId])) { + $listResCourseSession[$courseId] = array(); + } + $listResCourseSession[$courseId][] = $sessionId; + } + } + } + return $listResCourseSession; + } + + + /** + * Return an array of course_id used in session $sessionId + * @param $sessionId + * @return array + */ + public static function getCoursesInSession($sessionId) + { + $listResultsCourseId = array(); + $tblSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); + $tblCourse = Database::get_main_table(TABLE_MAIN_COURSE); + + // list of course in this session + $sql = "SELECT id_session, c.id + from $tblSessionRelCourse src + LEFT JOIN $tblCourse c + ON c.code=src.course_code + WHERE id_session=".intval($sessionId); + $res = Database::query($sql); + while ($data = Database::fetch_assoc($res)) { + $listResultsCourseId[] = $data['id']; + } + return $listResultsCourseId; + } + } diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 8ab7e14191..7b6d2baeeb 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -552,6 +552,7 @@ class Template { global $disable_js_and_css_files, $htmlHeadXtra; + //JS files //JS files $js_files = array( 'modernizr.js', @@ -562,13 +563,16 @@ class Template 'mediaelement/mediaelement-and-player.min.js' ); - if (api_is_global_chat_enabled()) { + // add chat.js for View by Session, we need the $.cookie library included in it + // @todo : replace $_configuration with setting parameter + if (api_is_global_chat_enabled() || (isset($_configuration['my_courses_view_by_session']) && $_configuration['my_courses_view_by_session'])) { //Do not include the global chat in LP if ($this->show_learnpath == false && $this->show_footer == true && $this->hide_global_chat == false) { $js_files[] = 'chat/js/chat.js'; } } + if (api_get_setting('accessibility_font_resize') == 'true') { $js_files[] = 'fontresize.js'; } diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 83614497c6..f076625f55 100755 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -14,6 +14,9 @@ class IndexManager public $home = ''; public $default_home = 'home/'; + const VIEW_BY_DEFAULT = 0; + const VIEW_BY_SESSION = 1; + /** * Construct * @param string $title @@ -1361,4 +1364,287 @@ class IndexManager { return CourseManager::return_hot_courses(); } + + /** + * UserPortal view for session, return the HTLK of the course list + * @param $user_id + * @return string + */ + public function returnCoursesAndSessionsViewBySession($user_id) { + $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false; + + if ($load_history) { + //Load sessions in category in *history* + $session_categories = UserManager::get_sessions_by_category($user_id, true); + } else { + //Load sessions in category + $session_categories = UserManager::get_sessions_by_category($user_id, false); + } + + $html = ''; + + //Showing history title + if ($load_history) { + $html .= Display::page_subheader(get_lang('HistoryTrainingSession')); + if (empty($session_categories)) { + $html .= get_lang('YouDoNotHaveAnySessionInItsHistory'); + } + } + + $special_courses = ''; + + $loadDirs = $this->load_directories_preview; + + // If we're not in the history view... + $listCoursesInfo = array(); + if (!isset($_GET['history'])) { + // Display special courses + $special_courses = CourseManager::display_special_courses($user_id, $loadDirs); + // Display courses + $listCourses = CourseManager::get_courses_list_by_user_id($user_id, false); // [code=>xxx, real_id=>000] + foreach ($listCourses as $i => $listCourseCodeId) { + list($userCategoryId, $userCatTitle) = CourseManager::getUserCourseCategoryForCourse($user_id, $listCourseCodeId['real_id']); + $listCourse = CourseManager::get_course_information_by_id($listCourseCodeId['real_id']); + $listCoursesInfo[] = array( + 'code' => $listCourseCodeId['code'], + 'id' => $listCourseCodeId['real_id'], + 'title' => $listCourse['title'], + 'userCatId' => $userCategoryId, + 'userCatTitle' => $userCatTitle); + } + usort($listCoursesInfo, 'self::compareByCourse'); + } + + if (is_array($session_categories)) { + $listCoursesInSession = SessionManager::getNamedSessionCourseForCoach($user_id); // all courses that are in a session + } + + // we got all courses + // for each user category, sorted alphabetically, display courses + $listUserCategories = CourseManager::get_user_course_categories($user_id); + $listCoursesAlreadyDisplayed = array(); + uasort($listUserCategories, "self::compareListUserCategory"); + $listUserCategories[0] = ''; + + $html = '
'; + + foreach ($listUserCategories as $userCategoryId => $userCatTitle) { + // add user category + $userCategoryHtml = ''; + if ($userCategoryId != 0) { + $userCategoryHtml = '
'; + } + $userCategoryHtml .= self::getHtmlForUserCategory($userCategoryId, $userCatTitle); + // look for course in this userCat in session courses : $listCoursesInSession + $htmlCategory = ''; + if (isset($listCoursesInSession[$userCategoryId])) { + // list of courses in this user cat + foreach ($listCoursesInSession[$userCategoryId]['courseInUserCatList'] as $i => $listCourse) { + // add course + $listCoursesAlreadyDisplayed[$listCourse['courseId']] = 1; + if ($userCategoryId == 0) { + $htmlCategory .= '
'; + } else { + $htmlCategory .= '
'; + } + $htmlCategory .= self::getHtmlForCourse($listCourse['courseId'], $listCourse['title'], $listCourse['courseCode'], $userCategoryId, 1, $loadDirs); + // list of session category + $htmlSessionCategory = ''; // end session cat block + $htmlCategory .= $htmlSessionCategory .'
' ; + $htmlCategory .= ''; // end course block + } + $userCategoryHtml .= $htmlCategory; + } + + // look for courses in this userCat in not in session courses : $listCoursesInfo + // if course not already added + $htmlCategory = ''; + foreach ($listCoursesInfo as $i => $listCourse) { + if ($listCourse['userCatId'] == $userCategoryId && !isset($listCoursesAlreadyDisplayed[$listCourse['id']])) { + if ($userCategoryId != 0) { + $htmlCategory .= '
'; + } else { + $htmlCategory .= '
'; + } + $htmlCategory .= self::getHtmlForCourse($listCourse['id'], $listCourse['title'], $listCourse['code'], $userCategoryId, 0, $loadDirs); + $htmlCategory .= '
'; + } + } + $htmlCategory .= ''; + $userCategoryHtml .= $htmlCategory; // end user cat block + if ($userCategoryId != 0) { + $userCategoryHtml .= '
'; + } + $html .= $userCategoryHtml; // + } + $html .= '
'; + + return $html.$special_courses; + } + + /** + * Return HTML code for personnal user course category + * @param $id + * @param $title + * @return string + */ + private static function getHtmlForUserCategory($id, $title) + { + if ($id == 0) { + return ''; + } + $icon = Display::return_icon('folder_yellow.png', $title, array('class' => 'sessionView', 'width' => 24), ICON_SIZE_LARGE); + return "
$icon$title
"; + } + + /** + * return HTML code for course display in session view + * @param $id + * @param $title + * @param $code + * @param $userCategoryId + * @param bool $displayButton + * @param $loadDirs + * @return string + */ + private static function getHtmlForCourse($id, $title, $code, $userCategoryId, $displayButton = false, $loadDirs) + { + //   + // + $class = 'session-view-lvl-6'; + if ($userCategoryId != 0 && !$displayButton) { + $class = 'session-view-lvl-7'; + } + + $class2 = 'session-view-lvl-6'; + if ($displayButton || $userCategoryId != 0) { + $class2 = 'session-view-lvl-7'; + } + + $button = ''; + if ($displayButton) { + $button = ''; + } + + $icon = Display::return_icon('blackboard.png', $title, array('class' => 'sessionView', 'width' => 24), ICON_SIZE_LARGE); + $courseLink = api_get_path(WEB_COURSE_PATH).$code.'/?id_session=0'; + + // get html course params + $tabParams = CourseManager::getCourseParamsForDisplay($id, $loadDirs); // ['right_actions'] ['teachers'] ['notifications'] + // teacher list + if (!empty($tabParams['teachers'])) { + $teachers = '

'.$tabParams['teachers'].'

'; + } + // notification + if (!empty($tabParams['right_actions'])) { + $rightActions = '
'.$tabParams['right_actions'].'
'; + } + return "
$button$icon$title".$tabParams['notifications']."$rightActions
$teachers"; + } + + /** + * return HTML code for session category + * @param $id + * @param $title + * @return string + */ + private static function getHtmlSessionCatagory($id, $title) + { + if ($id == 0) { + return ''; + } + $icon = Display::return_icon('folder_blue.png', $title, array('class' => 'sessionView', 'width' => 24), ICON_SIZE_LARGE); + return "
$icon$title
"; + } + + /** + * return HTML code for session + * @param $id + * @param $title + * @param $categotySessionId + * @param $courseCode + * @return string + */ + private static function getHtmlForSession($id, $title, $categotySessionId, $courseCode) + { + $html = ''; + + if ($categotySessionId == 0) { + $class1 = 'session-view-lvl-2'; // session + $class2 = 'session-view-lvl-4'; // got to course in session link + } else { + $class1 = 'session-view-lvl-3'; // session + $class2 = 'session-view-lvl-5'; // got to course in session link + } + + $icon = Display::return_icon('blackboard_blue.png', $title, array('class' => 'sessionView', 'width' => 24), ICON_SIZE_LARGE); + $courseLink = api_get_path(WEB_COURSE_PATH).$courseCode.'/?id_session='.$id; + + $html .= "$icon$title"; + $html .= ''; + return '
'.$html.'
'; + } + + /** + * @param $listA + * @param $listB + * @return int + */ + private static function compareByCourse($listA, $listB) + { + if ($listA['userCatTitle'] == $listB['userCatTitle']) { + if ($listA['title'] == $listB['title']) { + return 0; + } else if($listA['title'] > $listB['title']) { + return 1; + } else { + return -1; + } + } else if ($listA['userCatTitle'] > $listB['userCatTitle']) { + return 1; + } else { + return -1; + } + } + + /** + * @param $listA + * @param $listB + * @return int + */ + public static function compareListUserCategory($listA, $listB) + { + if ($listA['title'] == $listB['title']) { + return 0; + } else if($listA['title'] > $listB['title']) { + return 1; + } else { + return -1; + } + } + + /** + * @param $view + * @param $userId + */ + public static function setDefaultMyCourseView($view, $userId) + { + setcookie('defaultMyCourseView'.$userId, $view); + } + } diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 000a7bd157..34dc4e1119 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -301,4 +301,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE; //$_configuration['limit_session_admin_role'] = false; // Show session description //$_configuration['show_session_description'] = false; - +// Show Default view and Session view link in My Courses tab +//$_configuration['my_courses_view_by_session'] = false; \ No newline at end of file diff --git a/main/template/default/layout/footer.tpl b/main/template/default/layout/footer.tpl index d3fdb29c11..cc965846ea 100755 --- a/main/template/default/layout/footer.tpl +++ b/main/template/default/layout/footer.tpl @@ -143,6 +143,25 @@ }); {% endraw %} + /** + * Generic function to replace the depreceted jQuery toggle function + * @param inId : id of block to hide / unhide + * @param inIdTxt : id of the button + * @param inTxtHide : text one of the button + * @param inTxtUnhide : text two of the button + * @todo : allow to detect if text is from a button or from a + */ + function hideUnhide(inId, inIdTxt, inTxtHide, inTxtUnhide) + { + if ($('#'+inId).css("display") == "none") { + $('#'+inId).show(400); + $('#'+inIdTxt).attr("value", inTxtUnhide); + } else { + $('#'+inId).hide(400); + $('#'+inIdTxt).attr("value", inTxtHide); + } + } + {{ execution_stats }} diff --git a/user_portal.php b/user_portal.php index eb17ec6a5c..5dffb7b4f7 100755 --- a/user_portal.php +++ b/user_portal.php @@ -123,6 +123,36 @@ if ($load_dirs) { '; } +// @todo : replace $_configuration with setting parameter +$displayMyCourseViewbySessionLink = (isset($_configuration['my_courses_view_by_session']) && $_configuration['my_courses_view_by_session']); + +if ($displayMyCourseViewbySessionLink) { + $htmlHeadXtra[] = ' + +'; +} + /* Sniffing system */ //store posts to sessions @@ -145,9 +175,27 @@ if (isset($_SESSION['sniff_navigator']) && $_SESSION['sniff_navigator']!="checke $controller = new IndexManager(get_lang('MyCourses')); - // Main courses and session list -$courses_and_sessions = $controller->return_courses_and_sessions($user_id); +if (isset($_COOKIE['defaultMyCourseView'.$user_id]) && $_COOKIE['defaultMyCourseView'.$user_id] == IndexManager::VIEW_BY_SESSION && $displayMyCourseViewbySessionLink) { + $courses_and_sessions = $controller->returnCoursesAndSessionsViewBySession($user_id); + IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_SESSION, $user_id); +} else { + $courses_and_sessions = $controller->return_courses_and_sessions($user_id); + IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_DEFAULT, $user_id); +} + +// if teacher, session coach or admin, display the button to change te course view +// @todo : replace $_configuration with setting parameter +if ($displayMyCourseViewbySessionLink && (api_is_drh() || api_is_course_coach() || api_is_platform_admin() || api_is_session_admin() || api_is_teacher())) { + $courses_and_sessions = "".$courses_and_sessions; +} + //Show the chamilo mascot if (empty($courses_and_sessions) && !isset($_GET['history'])) {