Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
New: Course content search attribute and order.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Feb 1, 2019
1 parent b47ce10 commit 38f4dcc
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
==============
Expand Down
59 changes: 58 additions & 1 deletion classes/core_course_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions lang/en/theme_essential.php
Original file line number Diff line number Diff line change
Expand Up @@ -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=""></iframe\'.';

Expand Down
29 changes: 29 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,35 @@
$setting = new admin_setting_configcheckbox($name, $title, $description, $default, true, false);
$essentialsettingsfeature->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');
Expand Down

0 comments on commit 38f4dcc

Please sign in to comment.