Add my_courses_list_as_category configuration setting - refs BT#13101

pull/2487/head
Angel Fernando Quiroz Campos 8 years ago
parent 0cec0d1534
commit 216734f60c
  1. 24
      main/admin/course_category.php
  2. 6
      main/inc/lib/course.lib.php
  3. 29
      main/inc/lib/course_category.lib.php
  4. 108
      main/inc/lib/userportal.lib.php
  5. 4
      main/install/configuration.dist.php
  6. 22
      main/template/default/user_portal/course_categories.tpl
  7. 15
      user_portal.php

@ -22,6 +22,8 @@ if (!empty($categoryId)) {
}
$action = isset($_GET['action']) ? $_GET['action'] : null;
$myCourseListAsCategory = api_get_configuration_value('my_courses_list_as_category');
if (!empty($action)) {
if ($action == 'delete') {
CourseCategory::deleteNode($categoryId);
@ -45,10 +47,16 @@ if (!empty($action)) {
$_POST['auth_course_child'],
$categoryId
);
$categoryInfo = CourseCategory::getCategory($_POST['code']);
$ret = $categoryInfo['id'];
$errorMsg = Display::return_message(get_lang('Updated'));
}
if (!$ret) {
$errorMsg = Display::return_message(get_lang('CatCodeAlreadyUsed'), 'error');
} else {
if ($myCourseListAsCategory && isset($_FILES['image'])) {
CourseCategory::saveImage($ret, $_FILES['image']);
}
}
Display::addFlash($errorMsg);
@ -120,6 +128,22 @@ if ($action == 'add' || $action == 'edit') {
);
$form->addGroup($group, null, get_lang("AllowCoursesInCategory"));
if ($myCourseListAsCategory) {
$form->addFile('image', get_lang('Image'), ['accept' => 'image/*']);
if ($action == 'edit' && !empty($categoryInfo['image'])) {
$form->addHtml('
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">'.Display::img(
api_get_path(WEB_UPLOAD_PATH).$categoryInfo['image'],
get_lang('Image'),
['width' => 256]
).'</div>
</div>
');
}
}
if (!empty($categoryInfo)) {
$class = "save";
$text = get_lang('Save');

@ -2786,7 +2786,7 @@ class CourseManager
// get course list not auto-register. Use Distinct to avoid multiple
// entries when a course is assigned to a HRD (DRH) as watcher
$sql = "SELECT DISTINCT(course.code), course.id as real_id
$sql = "SELECT DISTINCT(course.code), course.id as real_id, course.category_code AS category
FROM $tbl_course course
INNER JOIN $tbl_course_user cru
ON (course.id = cru.c_id)
@ -2814,7 +2814,7 @@ class CourseManager
}
if ($include_sessions === true) {
$sql = "SELECT DISTINCT(c.code), c.id as real_id
$sql = "SELECT DISTINCT(c.code), c.id as real_id, course.category_code AS category
FROM " . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." s,
$tbl_course c
WHERE user_id = $user_id AND s.c_id = c.id";
@ -3603,6 +3603,7 @@ class CourseManager
$params['visibility'] = $course_info['visibility'];
$params['status'] = $course_info['status'];
$params['category'] = $course_info['categoryName'];
$params['category_code'] = $course_info['categoryCode'];
$params['icon'] = Display::return_icon(
'drawing-pin.png',
null,
@ -3840,6 +3841,7 @@ class CourseManager
$params['title'] = $course_info['title'];
$params['title_cut'] = $params['title'];
$params['category'] = $course_info['categoryName'];
$params['category_code'] = $course_info['categoryCode'];
$params['teachers'] = $teachers;
if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) {

@ -1150,4 +1150,33 @@ class CourseCategory
return $nameTools;
}
/**
* Save image for a course category
* @param int $categoryId Course category ID
* @param array $fileData File data from $_FILES
*/
public static function saveImage($categoryId, $fileData)
{
if (!empty($fileData['error'])) {
return;
}
$extension = getextension($fileData['name']);
$dirName = 'course_category/';
$fileDir = api_get_path(SYS_UPLOAD_PATH).$dirName;
$fileName = "cc_$categoryId.{$extension[0]}";
if (!file_exists($fileDir)) {
mkdir($fileDir, api_get_permissions_for_new_directories(), true);
}
$image = new Image($fileData['tmp_name']);
$image->send_image($fileDir.$fileName);
$table = Database::get_main_table(TABLE_MAIN_CATEGORY);
Database::update($table, ['image' => $dirName.$fileName], ['id = ?' => $categoryId]);
}
}

@ -1177,7 +1177,7 @@ class IndexManager
* @param int $user_id
* @return string
*/
public function returnCoursesAndSessions($user_id)
public function returnCoursesAndSessions($user_id, $showSessions = true, $categoryCodeFilter = '')
{
$gameModeIsActive = api_get_setting('gamification_mode');
$listCourse = '';
@ -1387,6 +1387,10 @@ class IndexManager
}
if ($specialCourses) {
if ($categoryCodeFilter) {
$specialCourses = self::filterByCategory($specialCourses, $categoryCodeFilter);
}
$this->tpl->assign('courses', $specialCourses);
$specialCourseList = $this->tpl->fetch(
@ -1395,6 +1399,11 @@ class IndexManager
}
if ($courses['in_category'] || $courses['not_category']) {
if ($categoryCodeFilter) {
$courses['in_category'] = self::filterByCategory($courses['in_category'], $categoryCodeFilter);
$courses['not_category'] = self::filterByCategory($courses['not_category'], $categoryCodeFilter);
}
$this->tpl->assign('courses', $courses['not_category']);
$this->tpl->assign('categories', $courses['in_category']);
@ -1410,6 +1419,9 @@ class IndexManager
}
$sessions_with_category = '';
$sessions_with_no_category = '';
if ($showSessions) {
$coursesListSessionStyle = api_get_configuration_value('courses_list_session_title_link');
$coursesListSessionStyle = $coursesListSessionStyle === false ? 1 : $coursesListSessionStyle;
if (api_is_drh()) {
@ -1426,8 +1438,8 @@ class IndexManager
$session_category_id = $session_category['session_category']['id'];
// Sessions and courses that are not in a session category
if (
empty($session_category_id) &&
isset($session_category['sessions'])
empty($session_category_id)
&& isset($session_category['sessions'])
) {
// Independent sessions
foreach ($session_category['sessions'] as $session) {
@ -1500,7 +1512,8 @@ class IndexManager
);
if (isset($courseUserHtml[1])) {
$course_session = $courseUserHtml[1];
$course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
$course_session['skill'] =
isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
//Course option (show student progress)
//This code will add new variables (Progress, Score, Certificate)
@ -1512,7 +1525,8 @@ class IndexManager
array(),
$session_id
);
$course_session['student_info']['progress'] = ($progress === false) ? null : $progress;
$course_session['student_info']['progress'] =
($progress === false) ? null : $progress;
}
if ($studentInfoScore) {
@ -1537,9 +1551,11 @@ class IndexManager
$course_session['student_info']['certificate'] = null;
if (isset($category[0])) {
if ($category[0]->is_certificate_available($user_id)) {
$course_session['student_info']['certificate'] = Display::label(get_lang('Yes'), 'success');
$course_session['student_info']['certificate'] =
Display::label(get_lang('Yes'), 'success');
} else {
$course_session['student_info']['certificate'] = Display::label(get_lang('No'));
$course_session['student_info']['certificate'] =
Display::label(get_lang('No'));
}
}
}
@ -1563,7 +1579,8 @@ class IndexManager
'id' => $session_id
);
$session_box = Display::get_session_title_box($session_id);
$actions = api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session_id;
$actions =
api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session_id;
$coachId = $session_box['id_coach'];
$extraFieldValue = new ExtraFieldValue('session');
$imageField = $extraFieldValue->get_values_by_handler_and_field_variable(
@ -1574,7 +1591,9 @@ class IndexManager
$params['category_id'] = $session_box['category_id'];
$params['title'] = $session_box['title'];
$params['id_coach'] = $coachId;
$params['coach_url'] = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup&user_id='.$coachId;
$params['coach_url'] =
api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_popup&user_id='
.$coachId;
$params['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
$params['coach_avatar'] = UserManager::getUserPicture(
$coachId,
@ -1582,9 +1601,11 @@ class IndexManager
);
$params['date'] = $session_box['dates'];
$params['image'] = isset($imageField['value']) ? $imageField['value'] : null;
$params['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
$params['duration'] =
isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
$params['edit_actions'] = $actions;
$params['show_description'] = $session_box['show_description'] == 1 && $portalShowDescription;
$params['show_description'] =
$session_box['show_description'] == 1 && $portalShowDescription;
$params['description'] = $session_box['description'];
$params['visibility'] = $session_box['visibility'];
$params['show_simple_session_info'] = $showSimpleSessionInfo;
@ -1605,10 +1626,12 @@ class IndexManager
}
if ($gameModeIsActive) {
$params['stars'] = GamificationUtils::getSessionStars($params['id'], $this->user_id);
$params['stars'] =
GamificationUtils::getSessionStars($params['id'], $this->user_id);
$params['progress'] = GamificationUtils::getSessionProgress($params['id'],
$this->user_id);
$params['points'] = GamificationUtils::getSessionPoints($params['id'], $this->user_id);
$params['points'] =
GamificationUtils::getSessionPoints($params['id'], $this->user_id);
}
$listSession[] = $params;
$sessionCount++;
@ -1692,14 +1715,18 @@ class IndexManager
$session_box = Display::get_session_title_box($session_id);
$sessionParams[0]['id'] = $session_id;
$sessionParams[0]['date'] = $session_box['dates'];
$sessionParams[0]['duration'] = isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
$sessionParams[0]['duration'] =
isset($session_box['duration']) ? ' '.$session_box['duration'] : null;
$sessionParams[0]['course_list_session_style'] = $coursesListSessionStyle;
$sessionParams[0]['title'] = $session_box['title'];
$sessionParams[0]['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'].' | ' : '').$session_box['dates'];
$sessionParams[0]['subtitle'] =
(!empty($session_box['coach']) ? $session_box['coach'].' | ' : '')
.$session_box['dates'];
$sessionParams[0]['show_actions'] = api_is_platform_admin();
$sessionParams[0]['courses'] = $html_courses_session;
$sessionParams[0]['show_simple_session_info'] = $showSimpleSessionInfo;
$sessionParams[0]['coach_name'] = !empty($session_box['coach']) ? $session_box['coach'] : null;
$sessionParams[0]['coach_name'] =
!empty($session_box['coach']) ? $session_box['coach'] : null;
if ($showSimpleSessionInfo) {
$sessionParams[0]['subtitle'] = self::getSimpleSessionDetails(
@ -1739,8 +1766,8 @@ class IndexManager
}
if (
!empty($session_category_start_date) &&
!empty($session_category_end_date)
!empty($session_category_start_date)
&& !empty($session_category_end_date)
) {
$categoryParams['subtitle'] = sprintf(
get_lang('FromDateXToDateY'),
@ -1791,6 +1818,7 @@ class IndexManager
);
}
}
}
return [
'html' => trim($specialCourseList.$sessions_with_category.$sessions_with_no_category.$listCourse),
@ -2242,4 +2270,48 @@ class IndexManager
return implode(' | ', $strDetails);
}
/**
* @param $userId
* @return array
*/
public static function returnCourseCategoryListFromUser($userId)
{
$sessionCount = 0;
$courseList = CourseManager::get_courses_list_by_user_id($userId);
$categoryCodes = CourseManager::getCourseCategoriesFromCourseList($courseList);
$categories = [];
foreach ($categoryCodes as $categoryCode) {
$categories[] = CourseCategory::getCategory($categoryCode);
}
$template = new Template('', false, false, false, true, false, false);
$layout = $template->get_template('user_portal/course_categories.tpl');
$template->assign('course_categories', $categories);
return [
'html' => $template->fetch($layout),
'course_count' => count($courseList),
'session_count' => $sessionCount
];
}
/**
* Filter the course list by category code
* @param array $courseList course list
* @param string $categoryCode
* @return array
*/
private static function filterByCategory($courseList, $categoryCode)
{
return array_filter($courseList, function ($courseInfo) use ($categoryCode) {
if ($courseInfo['category_code'] === $categoryCode) {
return true;
}
return false;
});
}
}

@ -570,4 +570,8 @@ $_configuration['score_grade_model'] = [
// $_configuration['hide_course_notification'] = true;
// Show less session information in course list
//$_configuration['show_simple_session_info'] = true;
// Show course category list on My Courses page before the courses. Requires a DB change
//ALTER TABLE course_category ADD image varchar(255) NULL;
//$_configuration['my_courses_list_as_category'] = false;
// ------
//

@ -0,0 +1,22 @@
<p class="lead">{{ 'MyCoursePageCategoryIntroduction'|get_lang }}</p>
<ul class="media-list">
{% for category in course_categories %}
{% if category %}
<li class="media">
<div class="media-left">
<a href="{{ _p.web_self ~ '?' ~ {'category':category.code}|url_encode }}">
<img src="{{ category.image ? _p.web_upload ~ category.image : 'session_default.png'|icon(128) }}"
alt="{{ category.name }}" width="200" class="media-object">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">{{ category.name }}</h4>
<p>{{ category.code }}</p>
<a href="{{ _p.web_self ~ '?' ~ {'category':category.code}|url_encode }}" class="btn btn-default">
{{ 'View'|get_lang }} <span class="fa fa-arrow-right" aria-hidden="true"></span>
</a>
</div>
</li>
{% endif %}
{% endfor %}
</ul>

@ -125,8 +125,11 @@ if ($displayMyCourseViewBySessionLink) {
</script>';
}
$myCourseListAsCategory = api_get_configuration_value('my_courses_list_as_category');
$controller = new IndexManager(get_lang('MyCourses'));
if (!$myCourseListAsCategory) {
// Main courses and session list
if (isset($_COOKIE['defaultMyCourseView'.$userId])
&& $_COOKIE['defaultMyCourseView'.$userId] == IndexManager::VIEW_BY_SESSION
@ -161,6 +164,15 @@ if ($displayMyCourseViewBySessionLink
<br /><br />
".$courseAndSessions['html'];
}
} else {
$categoryCode = isset($_GET['category']) ? $_GET['category'] : '';
if (!$categoryCode) {
$courseAndSessions = $controller->returnCourseCategoryListFromUser($userId);
} else {
$courseAndSessions = $controller->returnCoursesAndSessions($userId, false, $categoryCode);
}
}
// 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') {
@ -260,6 +272,9 @@ if (!empty($_GET['history'])) {
$historyClass = 'courses-history';
}
$controller->tpl->assign('course_history_page', $historyClass);
if ($myCourseListAsCategory) {
$controller->tpl->assign('header', get_lang('MyCourses'));
}
$controller->tpl->display_two_col_template();
// Deleting the session_id.

Loading…
Cancel
Save