Display - Rename methods and variables, improve documentation in new handpicked popular courses feature - refs #3095

pull/3354/head
Yannick Warnier 5 years ago
commit ba726d05c6
  1. 8
      index.php
  2. 72
      main/inc/lib/course.lib.php
  3. 8
      main/inc/lib/userportal.lib.php
  4. 7
      main/install/configuration.dist.php

@ -140,7 +140,13 @@ 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_handpicked')) {
// If the option has been set correctly, use the courses manually
// marked as popular rather than the ones marked by users
$hotCourses = $controller->returnPopularCoursesHandPicked();
} else {
$hotCourses = $controller->return_hot_courses();
}
}
$announcements_block = $controller->return_announcements();
}

@ -5135,6 +5135,78 @@ class CourseManager
return $courses;
}
/**
* Returns an array with the "hand picked" popular courses.
* Courses only appear in this list if their extra field 'popular_courses'
* has been selected in the admin page of the course.
*
* @return array
*/
public static function returnPopularCoursesHandPicked()
{
if (api_is_invitee()) {
return [];
}
$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

@ -2286,6 +2286,14 @@ class IndexManager
];
}
/**
* Wrapper to CourseManager::returnPopularCoursesHandPicked()
* @return array
*/
public function returnPopularCoursesHandPicked()
{
return CourseManager::returnPopularCoursesHandPicked();
}
/**
* @param $listA
* @param $listB

@ -1578,6 +1578,13 @@ $_configuration['auth_password_links'] = [
// Allow my student publications page
//$_configuration['allow_my_student_publication_page'] = false;
// Show handpicked "popular" courses on the home page instead of users-chosen
// courses.
// Create an extra field for courses called "popular_courses" (type CHECKBOX) OR
// INSERT extra_field (extra_field_type, field_type, variable, display_text, visible_to_self, changeable, created_at)
// VALUES (2, 13, 'popular_courses', 'Popular course', 1, 1, NOW());
// $_configuration['popular_courses_handpicked'] = false;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

Loading…
Cancel
Save