Mark popular courses manually

pull/3095/head
Nosolored 6 years ago
parent ad44ee376a
commit fa6a144297
  1. 6
      index.php
  2. 71
      main/inc/lib/course.lib.php
  3. 8
      main/inc/lib/userportal.lib.php
  4. 7
      main/install/configuration.dist.php

@ -140,7 +140,11 @@ if ($useCookieValidation === 'true') {
// When loading a chamilo page do not include the hot courses and news
if (!isset($_REQUEST['include'])) {
if (api_get_setting('show_hot_courses') == 'true') {
$hotCourses = $controller->return_hot_courses();
if (api_get_configuration_value('popular_courses')) {
$hotCourses = $controller->return_popular_courses();
} else {
$hotCourses = $controller->return_hot_courses();
}
}
$announcements_block = $controller->return_announcements();
}

@ -4896,6 +4896,77 @@ class CourseManager
return $courses;
}
/**
* Returns an array with the popular courses.
*
* @return array
*/
public static function return_popular_courses()
{
if (api_is_invitee()) {
return [];
}
$limit = (int) $limit;
$userId = api_get_user_id();
// Getting my courses
$my_course_list = self::get_courses_list_by_user_id($userId);
$codeList = [];
foreach ($my_course_list as $course) {
$codeList[$course['real_id']] = $course['real_id'];
}
if (api_is_drh()) {
$courses = self::get_courses_followed_by_drh($userId);
foreach ($courses as $course) {
$codeList[$course['real_id']] = $course['real_id'];
}
}
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_course_field = Database::get_main_table(TABLE_EXTRA_FIELD);
$tbl_course_field_value = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
//we filter the courses from the URL
$join_access_url = $where_access_url = '';
if (api_get_multiple_access_url()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$tbl_url_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$join_access_url = "LEFT JOIN $tbl_url_course url_rel_course
ON url_rel_course.c_id = tcfv.item_id ";
$where_access_url = " AND access_url_id = $access_url_id ";
}
}
$extraFieldType = EntityExtraField::COURSE_FIELD_TYPE;
// get course list auto-register
$sql = "SELECT DISTINCT(c.id) AS c_id
FROM $tbl_course_field_value tcfv
INNER JOIN $tbl_course_field tcf
ON tcfv.field_id = tcf.id $join_access_url
INNER JOIN $courseTable c
ON (c.id = tcfv.item_id)
WHERE
tcf.extra_field_type = $extraFieldType AND
tcf.variable = 'popular_courses' AND
tcfv.value = 1 AND
visibility <> ".COURSE_VISIBILITY_CLOSED." AND
visibility <> ".COURSE_VISIBILITY_HIDDEN." $where_access_url";
$result = Database::query($sql);
$courses = [];
if (Database::num_rows($result)) {
$courses = Database::store_result($result, 'ASSOC');
$courses = self::processHotCourseItem($courses, $codeList);
}
return $courses;
}
/**
* @param array $courses
* @param array $codeList

@ -1898,6 +1898,14 @@ class IndexManager
return CourseManager::return_hot_courses(30, 6);
}
/**
* @return array
*/
public function return_popular_courses()
{
return CourseManager::return_popular_courses();
}
/**
* UserPortal view for session, return the HTML of the course list.
*

@ -1388,6 +1388,13 @@ ALTER TABLE notification_event ADD COLUMN event_id INT NULL;
// In Scorm comunication use the username instead of the user_id
//$_configuration['scorm_api_username_as_student_id'] = false;
// Popular courses on the home page
// Create a extra field in course called "popular_courses" (type CHECKBOX) OR
// INSERT extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, create_at)
// VALUES (2, 13, 'popular_courses', 'Popular Courses', 1, 1, 'YYYY-mm-dd HH:mm:ss')
// Change datetime in SQL
// $_configuration['popular_courses'] = true;
// KEEP THIS AT THE END
// -------- Custom DB changes

Loading…
Cancel
Save