diff --git a/CHANGES.txt b/CHANGES.txt index a5670ec9..c322d324 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,6 +7,7 @@ New in 3.4.1.5 - FIX: 'courselistteachericon' not showing. - NEW: Show / hide the participants menu with the 'participantsmenu' setting in the 'Header' settings. - NEW: Separate 'People' from 'This course' menu and create 'Participants' menu. +- NEW: Course content search attribute and order. New in 3.4.1.4 ============== diff --git a/classes/core_course_renderer.php b/classes/core_course_renderer.php index fedd60b5..0b20a532 100644 --- a/classes/core_course_renderer.php +++ b/classes/core_course_renderer.php @@ -283,7 +283,7 @@ public function inspector_ajax($term) { $data = array(); - $courses = enrol_get_my_courses(); + $courses = enrol_get_my_courses('timecreated'); $site = get_site(); if (array_key_exists($site->id, $courses)) { @@ -324,6 +324,20 @@ public function inspector_ajax($term) { $sesskey = sesskey(); $coursetally = 0; + + // Presort. + $coursecontentsearchsortattribute = \theme_essential\toolbox::get_setting('coursecontentsearchsortattribute'); + $coursecontentsearchsortorder = \theme_essential\toolbox::get_setting('coursecontentsearchsortorder'); + if ((empty($coursecontentsearchsortattribute)) || (empty($coursecontentsearchsortorder))) { + $sortfunc = 'ccscmp_cid_asc'; + } else if ((!empty($remotecourses)) && ($coursecontentsearchsortattribute == 'ccd')) { + // Remote courses do not have a course started date, timecreated, so use the startdate instead. + $sortfunc = 'ccscmp_csd_'.$coursecontentsearchsortorder; + } else { + $sortfunc = 'ccscmp_'.$coursecontentsearchsortattribute.'_'.$coursecontentsearchsortorder; + } + usort($courses, array($this, $sortfunc)); + foreach ($courses as $course) { if (!$courseitemsearchtype) { $label = $course->fullname; @@ -402,4 +416,47 @@ public function inspector_ajax($term) { $data[] = array('label' => $tallystr, 'value' => ''); return $data; } + + public static function ccscmp_csd_asc($courseone, $coursetwo) { + return ($courseone->startdate < $coursetwo->startdate) ? -1 : +1; + } + + public static function ccscmp_csd_desc($courseone, $coursetwo) { + return self::ccscmp_csd_asc($coursetwo, $courseone); + } + + public static function ccscmp_ced_asc($courseone, $coursetwo) { + // If a course has an empty end date then use the start date. + $courseonedate = (empty($courseone->enddate)) ? $courseone->startdate : $courseone->enddate; + $coursetwodate = (empty($coursetwo->enddate)) ? $coursetwo->startdate : $coursetwo->enddate; + return ($courseonedate < $coursetwodate) ? -1 : +1; + } + + public static function ccscmp_ced_desc($courseone, $coursetwo) { + return self::ccscmp_ced_asc($coursetwo, $courseone); + } + + public static function ccscmp_cfn_asc($courseone, $coursetwo) { + return strcmp($courseone->fullname, $coursetwo->fullname); + } + + public static function ccscmp_cfn_desc($courseone, $coursetwo) { + return self::ccscmp_cfn_asc($coursetwo, $courseone); + } + + public static function ccscmp_ccd_asc($courseone, $coursetwo) { + return ($courseone->timecreated < $coursetwo->timecreated) ? -1 : +1; + } + + public static function ccscmp_ccd_desc($courseone, $coursetwo) { + return self::ccscmp_ccd_asc($coursetwo, $courseone); + } + + public static function ccscmp_cid_asc($courseone, $coursetwo) { + return ($courseone->id < $coursetwo->id) ? -1 : +1; + } + + public static function ccscmp_cid_desc($courseone, $coursetwo) { + return self::ccscmp_cid_asc($coursetwo, $courseone); + } } \ No newline at end of file diff --git a/lang/en/theme_essential.php b/lang/en/theme_essential.php index 44d89c1d..f69d35db 100644 --- a/lang/en/theme_essential.php +++ b/lang/en/theme_essential.php @@ -307,6 +307,17 @@ $string['coursecontentsearch'] = 'Course content search'; $string['coursecontentsearchdesc'] = "Enable course content search on the 'Dashboard' page. Only works when Essential is not in '\$CFG->themedir'."; +$string['csd'] = 'Course start date'; +$string['ced'] = 'Course end date'; +$string['cfn'] = 'Course full name'; +$string['ccd'] = 'Course created date'; +$string['cid'] = 'Course ID'; +$string['coursecontentsearchsortattribute'] = 'Course content search sort attribute'; +$string['coursecontentsearchsortattributedesc'] = "Sort the search results by this attribute."; + +$string['coursecontentsearchsortorder'] = 'Course content search sort order'; +$string['coursecontentsearchsortorderdesc'] = "Sort the search results by ascending or descending."; + $string['fitvids'] = 'Use FitVids'; $string['fitvidsdesc'] = 'Enable FitVids (fitvidsjs.com) to make your embedded videos responsive. If FitVids is on and you want a video to be excluded then add \'class="fitvidsignore"\' to the \'iframe\' tag in the HTML mode of the editor. For example: \'iframe class="fitvidsignore" width="420" height="315" src="//www.youtube.com/embed/enmEmym85xc" frameborder="0" allowfullscreen="">add($setting); + // Course content search sort results by. + $ccssrchoices = array( + 'csd' => get_string('csd', 'theme_essential'), + 'ced' => get_string('ced', 'theme_essential'), + 'cfn' => get_string('cfn', 'theme_essential'), + 'ccd' => get_string('ccd', 'theme_essential'), + 'cid' => get_string('cid', 'theme_essential') + ); + + $name = 'theme_essential/coursecontentsearchsortattribute'; + $title = get_string('coursecontentsearchsortattribute', 'theme_essential'); + $description = get_string('coursecontentsearchsortattributedesc', 'theme_essential'); + $default = 'cid'; + $setting = new essential_admin_setting_configselect($name, $title, $description, $default, $ccssrchoices); + $essentialsettingsfeature->add($setting); + + // Course content search sort order. + $name = 'theme_essential/coursecontentsearchsortorder'; + $title = get_string('coursecontentsearchsortorder', 'theme_essential'); + $description = get_string('coursecontentsearchsortorderdesc', 'theme_essential'); + $default = 'asc'; + $setting = new essential_admin_setting_configselect($name, $title, $description, $default, + array( + 'asc' => get_string('sortasc', 'grades'), + 'desc' => get_string('sortdesc', 'grades') + ) + ); + $essentialsettingsfeature->add($setting); + // Custom scrollbars. $name = 'theme_essential/customscrollbars'; $title = get_string('customscrollbars', 'theme_essential');