Add session view (option my_courses_view_by_session) see #7619

1.10.x
Julio Montoya 10 years ago
parent 70d39cdcc7
commit 92ffaf62c2
  1. 114
      app/Resources/public/css/base.css
  2. 181
      main/inc/lib/course.lib.php
  3. 413
      main/inc/lib/sessionmanager.lib.php
  4. 4
      main/inc/lib/template.lib.php
  5. 367
      main/inc/lib/userportal.lib.php
  6. 2
      main/install/configuration.dist.php
  7. 19
      main/template/default/layout/footer.tpl
  8. 140
      user_portal.php

@ -2,7 +2,8 @@
Theme Name: Chamilo Base
URI Project: http://www.chamilo.org
Description: Styles main base of Chamilo LMS appearance, works with Bootstrap 3.0.x
Author: alex.aragon@beeznest.com
Author:
alex.aragon@beeznest.com
angel.quiroz@beeznest.com
julio.montoya@beeznest.com
yannik.warnier@beeznest.com
@ -6179,6 +6180,117 @@ div#chat-remote-video video {
.filler-report .filler-report-data-init{
width: 60%;
}
/* 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 {
min-height: 38px;
}
.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;
}
#gradebook_list .centered {
text-align:center;
vertical-align:middle;
}
#gradebook_list .centered .badge-group {
width: auto;
}
/* CSS NEW TOP ******************************************************************************/
/* CSS Responsive */
@media (min-width: 1025px) and (max-width: 1200px) {

@ -3333,8 +3333,12 @@ class CourseManager
$course['status'] = STUDENT;
}
$params['icon'] = Display::return_icon('blackboard.png', api_htmlentities($course_info['title']),
array(), ICON_SIZE_LARGE);
$params['icon'] = Display::return_icon(
'blackboard.png',
api_htmlentities($course_info['title']),
array(),
ICON_SIZE_LARGE
);
$params['right_actions'] = '';
if (api_is_platform_admin()) {
@ -3663,15 +3667,20 @@ class CourseManager
/**
* Retrieves the user defined course categories
* @author Patrick Cool <patrick.cool@UGent.be>, 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_main_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'];
@ -3679,6 +3688,37 @@ 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)
{
$tblCourseRelUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tblUserCategory = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
$courseId = intval($courseId);
$userId = intval($userId);
$sql = "SELECT user_course_cat, title
FROM $tblCourseRelUser cru
LEFT JOIN $tblUserCategory ucc
ON cru.user_course_cat = ucc.id
WHERE
cru.user_id = $userId AND c_id= $courseId ";
$res = Database::query($sql);
$result = array();
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
@ -5510,4 +5550,133 @@ class CourseManager
return $form_data;
}
/**
* return html code for displaying a course title in the standard 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 icons, 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.id = course_rel_user.c_id
AND url.c_id = course.id
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'] .= '<a id="document_preview_'.$course_info['real_id'].'_0" class="document_preview" href="javascript:void(0);">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).'</a>';
$params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cidReq='.$course['code'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).'</a>';
$params['right_actions'] .= Display::div('', array('id' => 'document_result_'.$course_info['real_id'].'_0', 'class'=>'document_preview_container'));
} else {
$params['right_actions'].= '<a href="'.api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cidReq='.$course['code'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).'</a>';
}
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'] .= '<a id="document_preview_'.$course_info['real_id'].'_0" class="document_preview" href="javascript:void(0);">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).'</a>';
$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'].= '<a href="'.api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cidReq='.$course['code'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),ICON_SIZE_SMALL).'</a>';
}
}
}
}
$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;
}
}

@ -262,9 +262,10 @@ class SessionManager
/**
* @param string $where_condition
*
* @return mixed
*/
public static function get_count_admin($where_condition = null)
public static function get_count_admin($where_condition = '')
{
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
@ -275,7 +276,7 @@ class SessionManager
$where = 'WHERE 1=1 ';
$user_id = api_get_user_id();
$extraJoin = null;
$extraJoin = '';
if (api_is_session_admin() &&
api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false'
@ -379,8 +380,8 @@ class SessionManager
/**
* Gets the admin session list callback of the session/session_list.php page
* @param array order and limit keys
* @param boolean Whether to get all the results or only the count
* @param array $options order and limit keys
* @param boolean $get_count Whether to get all the results or only the count
* @return mixed Integer for number of rows, or array of results
* @assert (array(),true) !== false
*/
@ -7124,4 +7125,408 @@ class SessionManager
return false;
}
/**
* 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
*
* @return array
*/
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 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);
$sql = "SELECT session_id, c_id, c.id
FROM $tblSessionRelCourseRelUser srcru
LEFT JOIN $tblCourse c
ON c.id = srcru.c_id
WHERE
srcru.user_id =".intval($userId)." AND
srcru.status = 2";
$res = Database::query($sql);
while ($data = Database::fetch_assoc($res)) {
if (self::isSessionDateOkForCoach($data['session_id'])) {
if (!isset($listResCourseSession[$data['id']])) {
$listResCourseSession[$data['id']] = array();
}
$listResCourseSession[$data['id']][] = $data['session_id'];
}
}
return $listResCourseSession;
}
/**
* Return true if coach is allowed to access this session
* @param int $sessionId
* @return bool
*/
public static function isSessionDateOkForCoach($sessionId)
{
return api_get_session_visibility($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 session_id, c.id
FROM $tblSessionRelCourse src
LEFT JOIN $tblCourse c
ON c.id = src.c_id
WHERE session_id = ".intval($sessionId);
$res = Database::query($sql);
while ($data = Database::fetch_assoc($res)) {
$listResultsCourseId[] = $data['id'];
}
return $listResultsCourseId;
}
/**
* 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 = api_get_course_info_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'] = '<div style="float:left">
<input style="border:none;" type="button" onclick="$(\'#course-'.$courseCode.'\').toggle(\'fast\')" value="+" /></div>'.
Display::return_icon('blackboard.png', $listCoursesInfo['title'], array(), ICON_SIZE_LARGE);
$listParamsCourse['link'] = '';
$listParamsCourse['title'] = Display::tag(
'a',
$listCoursesInfo['title'],
array('href' => $listParamsCourse['link'])
);
$htmlCourse = '<div class="well" style="border-color:#27587D">'.
CourseManager::course_item_html($listParamsCourse, true);
// 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 .= '<div style="margin-left:'.$marginShift.'px;">' .
CourseManager::course_item_html($listParamsCatSession, true) . '</div>';
$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.'<div style="font-weight:normal; font-style:italic">
<a href="'.$linkToCourseSession.'">
'.get_lang('GoToCourseInsideSession').'</a></div>';
$htmlSession .= '<div style="margin-left:'.$marginShift.'px;">'.
CourseManager::course_item_html($listParamsSession, true).'</div>';
}
$htmlCatSessions .= $htmlSession;
}
$htmlRes .= $htmlCourse.'<div style="display:none" id="course-'.$courseCode.'">'.$htmlCatSessions.'</div></div>';
}
return $htmlRes;
}
}

@ -610,7 +610,9 @@ class Template
'chosen/chosen.jquery.min.js',
);
if (api_is_global_chat_enabled()) {
$viewBySession = api_get_configuration_value('my_courses_view_by_session');
if (api_is_global_chat_enabled() || $viewBySession) {
// Do not include the global chat in LP
if ($this->show_learnpath == false &&
$this->show_footer == true &&

@ -6,6 +6,9 @@
*/
class IndexManager
{
const VIEW_BY_DEFAULT = 0;
const VIEW_BY_SESSION = 1;
// An instance of the template engine
public $tpl = false;
public $name = '';
@ -1330,4 +1333,368 @@ class IndexManager
return CourseManager::return_hot_courses(30, 6);
}
/**
* UserPortal view for session, return the HTLK of the course list
* @param $user_id
* @return string
*/
public function returnCoursesAndSessionsViewBySession($user_id)
{
$sessionCount = 0;
$courseCount = 0;
$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
$specialCoursesResult = CourseManager::display_special_courses(
$user_id,
$loadDirs
);
$specialCourses = $specialCoursesResult['html'];
// Display courses
// [code=>xxx, real_id=>000]
$listCourses = CourseManager::get_courses_list_by_user_id($user_id, false);
foreach ($listCourses as $i => $listCourseCodeId) {
list($userCategoryId, $userCatTitle) = CourseManager::getUserCourseCategoryForCourse(
$user_id,
$listCourseCodeId['real_id']
);
$listCourse = api_get_course_info_by_id($listCourseCodeId['real_id']);
$listCoursesInfo[] = array(
'code' => $listCourseCodeId['code'],
'id' => $listCourseCodeId['real_id'],
'title' => $listCourse['title'],
'userCatId' => $userCategoryId,
'userCatTitle' => $userCatTitle
);
$courseCount++;
}
usort($listCoursesInfo, 'self::compareByCourse');
}
if (is_array($session_categories)) {
// all courses that are in a session
$listCoursesInSession = SessionManager::getNamedSessionCourseForCoach($user_id);
}
// 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 = '<div class="session-view-block">';
foreach ($listUserCategories as $userCategoryId => $userCatTitle) {
// add user category
$userCategoryHtml = '';
if ($userCategoryId != 0) {
$userCategoryHtml = '<div class="session-view-well ">';
}
$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 .= '<div class="session-view-well session-view-row well" >';
} else {
$htmlCategory .= '<div class="session-view-row" >';
}
$htmlCategory .= self::getHtmlForCourse(
$listCourse['courseId'],
$listCourse['title'],
$listCourse['courseCode'],
$userCategoryId,
1,
$loadDirs
);
// list of session category
$htmlSessionCategory = '<div class="session-view-row" style="display:none;" id="courseblock-'.$listCourse['courseId'].'">';
foreach ($listCourse['sessionCatList'] as $j => $listCategorySession) {
// add session category
$htmlSessionCategory .= self::getHtmlSessionCategory(
$listCategorySession['catSessionId'],
$listCategorySession['catSessionName']
);
// list of session
$htmlSession = ''; // start
foreach ($listCategorySession['sessionList'] as $k => $listSession) {
// add session
$htmlSession .= '<div class="session-view-row">';
$htmlSession .= self::getHtmlForSession(
$listSession['sessionId'],
$listSession['sessionName'],
$listCategorySession['catSessionId'],
$listCourse['courseCode']
);
$htmlSession .= '</div>';
$sessionCount++;
}
$htmlSession .= ''; // end session block
$htmlSessionCategory .= $htmlSession;
}
$htmlSessionCategory .= '</div>'; // end session cat block
$htmlCategory .= $htmlSessionCategory .'</div>' ;
$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 .= '<div class="session-view-row" >';
} else {
$htmlCategory .= '<div class="session-view-well well">';
}
$htmlCategory .= self::getHtmlForCourse(
$listCourse['id'],
$listCourse['title'],
$listCourse['code'],
$userCategoryId,
0,
$loadDirs
);
$htmlCategory .= '</div>';
}
}
$htmlCategory .= '';
$userCategoryHtml .= $htmlCategory; // end user cat block
if ($userCategoryId != 0) {
$userCategoryHtml .= '</div>';
}
$html .= $userCategoryHtml; //
}
$html .= '</div>';
return [
'html' => $html.$specialCourses,
'session_count' => $sessionCount,
'course_count' => $courseCount
];
}
/**
* 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 "<div class='session-view-user-category'>$icon<span>$title</span></div>";
}
/**
* 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 = '<input id="session-view-button-'.intval($id).'" class="session-view-button btn btn-default" type="button" onclick="hideUnhide(\'courseblock-'.intval($id).'\', \'session-view-button-'.intval($id).'\', \'+\', \'-\')" value="+" />';
}
$icon = Display::return_icon(
'blackboard.png',
$title,
array('class' => 'sessionView', 'width' => 24),
ICON_SIZE_LARGE
);
$courseLink = api_get_path(WEB_COURSE_PATH).$code.'/index.php?id_session=0';
// get html course params
// ['right_actions'] ['teachers'] ['notifications']
$tabParams = CourseManager::getCourseParamsForDisplay($id, $loadDirs);
// teacher list
if (!empty($tabParams['teachers'])) {
$teachers = '<p class="'.$class2.' view-by-session-teachers">'.$tabParams['teachers'].'</p>';
}
// notification
if (!empty($tabParams['right_actions'])) {
$rightActions = '<div class="view-by-session-right-actions">'.$tabParams['right_actions'].'</div>';
}
return "<div>
$button
<span class='$class'>$icon
<a class='sessionView' href='$courseLink'>$title</a>
</span>".$tabParams['notifications']."$rightActions
</div>
$teachers";
}
/**
* return HTML code for session category
* @param $id
* @param $title
* @return string
*/
private static function getHtmlSessionCategory($id, $title)
{
if ($id == 0) {
return '';
}
$icon = Display::return_icon(
'folder_blue.png',
$title,
array('class' => 'sessionView', 'width' => 24),
ICON_SIZE_LARGE
);
return "<div class='session-view-session-category'>
<span class='session-view-lvl-2'>
$icon
<span>$title</span>
</span>
</div>";
}
/**
* 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.'/index.php?id_session='.intval($id);
$html .= "<span class='$class1 session-view-session'>$icon$title</span>";
$html .= '<div class="'.$class2.' session-view-session-go-to-course-in-session">
<a class="" href="'.$courseLink.'">'.get_lang('GoToCourseInsideSession').'</a></div>';
return '<div>'.$html.'</div>';
}
/**
* @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);
}
}

@ -228,3 +228,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE;
//$_configuration['user_reset_password'] = false;
// password token expired
//$_configuration['user_reset_password_token_limit'] = 3600;
// Show Default view and Session view link in My Courses tab
//$_configuration['my_courses_view_by_session'] = false;

@ -206,6 +206,25 @@
});
});
};
/**
* Generic function to replace the deprecated 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 <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);
}
}
</script>
{{ execution_stats }}

@ -35,11 +35,110 @@ $userId = api_get_user_id();
/* Constants and CONFIGURATION parameters */
$load_dirs = api_get_setting('show_documents_preview');
$displayMyCourseViewBySessionLink = api_get_configuration_value('my_courses_view_by_session');
$nameTools = get_lang('MyCourses');
/*
Header
Include the HTTP, HTML headers plus the top banner.
*/
if ($load_dirs) {
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
$folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
$close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
$(".document_preview_container").hide();
$(".document_preview").click(function() {
var my_id = this.id;
var course_id = my_id.split("_")[2];
var session_id = my_id.split("_")[3];
//showing div
$(".document_preview_container").hide();
$("#document_result_" +course_id+"_" + session_id).show();
//Loading
var image = $("img", this);
image.attr("src", "'.$close_icon.'");
$.ajax({
url: "'.$url.'",
data: "course_id="+course_id+"&session_id="+session_id,
success: function(return_value) {
image.attr("src", "'.$folder_icon.'");
$("#document_result_" +course_id+"_" + session_id).html(return_value);
}
});
});
});
</script>';
}
if ($displayMyCourseViewBySessionLink) {
$htmlHeadXtra[] = '
<script type="text/javascript">
userId = ' . $userId . '
$(document).ready(function() {
changeMyCoursesView($.cookie("defaultMyCourseView"+userId));
});
/**
* Keep in cookie the last teacher view for the My Courses Tab. default view, or view by session
* @param inView
*/
function changeMyCoursesView(inView)
{
$.cookie("defaultMyCourseView"+userId, inView, { expires: 365 });
if (inView == ' . IndexManager::VIEW_BY_SESSION . ') {
$("#viewBySession").addClass("btn-primary");
$("#viewByDefault").removeClass("btn-primary");
} else {
$("#viewByDefault").addClass("btn-primary");
$("#viewBySession").removeClass("btn-primary");
}
}
</script>
';
}
$controller = new IndexManager(get_lang('MyCourses'));
// Main courses and session list
//$courseAndSessions = $controller->returnCoursesAndSessions($userId);
// Main courses and session list
if (isset($_COOKIE['defaultMyCourseView'.$userId]) &&
$_COOKIE['defaultMyCourseView'.$userId] == IndexManager::VIEW_BY_SESSION && $displayMyCourseViewBySessionLink
) {
$courseAndSessions = $controller->returnCoursesAndSessionsViewBySession($userId);
IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_SESSION, $userId);
} else {
$courseAndSessions = $controller->returnCoursesAndSessions($userId);
IndexManager::setDefaultMyCourseView(IndexManager::VIEW_BY_DEFAULT, $userId);
}
// if teacher, session coach or admin, display the button to change te course view
if ($displayMyCourseViewBySessionLink &&
(api_is_drh() || api_is_course_coach() || api_is_platform_admin() || api_is_session_admin() || api_is_teacher())
) {
$courseAndSessions['html'] = "<div class='view-by-session-link'>
<div class='btn-group pull-right'>
<a class='btn btn-default' id='viewByDefault' href='user_portal.php' onclick='changeMyCoursesView(\"".IndexManager::VIEW_BY_DEFAULT."\")'>
".get_lang('MyCoursesDefaultView')."
</a>
<a class='btn btn-default' id='viewBySession' href='user_portal.php' onclick='changeMyCoursesView(\"".IndexManager::VIEW_BY_SESSION."\")'>
".get_lang('MyCoursesSessionView')."
</a>
</div>
</div><br /><br />
".$courseAndSessions['html'];
}
// Check if a user is enrolled only in one course for going directly to the course after the login.
if (api_get_setting('go_to_course_after_login') == 'true') {
@ -87,47 +186,6 @@ if (api_get_setting('go_to_course_after_login') == 'true') {
}
}
$nameTools = get_lang('MyCourses');
/*
Header
Include the HTTP, HTML headers plus the top banner.
*/
if ($load_dirs) {
$url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=document_preview';
$folder_icon = api_get_path(WEB_IMG_PATH).'icons/22/folder.png';
$close_icon = api_get_path(WEB_IMG_PATH).'loading1.gif';
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
$(".document_preview_container").hide();
$(".document_preview").click(function() {
var my_id = this.id;
var course_id = my_id.split("_")[2];
var session_id = my_id.split("_")[3];
//showing div
$(".document_preview_container").hide();
$("#document_result_" +course_id+"_" + session_id).show();
//Loading
var image = $("img", this);
image.attr("src", "'.$close_icon.'");
$.ajax({
url: "'.$url.'",
data: "course_id="+course_id+"&session_id="+session_id,
success: function(return_value) {
image.attr("src", "'.$folder_icon.'");
$("#document_result_" +course_id+"_" + session_id).html(return_value);
}
});
});
});
</script>';
}
//Show the chamilo mascot
if (empty($courseAndSessions['html']) && !isset($_GET['history'])) {

Loading…
Cancel
Save