Skip to content

Commit

Permalink
MDL-32975 navigation: Added option to select how my courses are sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Mar 4, 2013
1 parent cce0d9a commit f87ce4e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 39 deletions.
7 changes: 7 additions & 0 deletions admin/settings/appearance.php
Expand Up @@ -114,6 +114,13 @@
$temp->add(new admin_setting_configcheckbox('navshowcategories', new lang_string('navshowcategories', 'admin'), new lang_string('confignavshowcategories', 'admin'), 1));
$temp->add(new admin_setting_configcheckbox('navshowmycoursecategories', new lang_string('navshowmycoursecategories', 'admin'), new lang_string('navshowmycoursecategories_help', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('navshowallcourses', new lang_string('navshowallcourses', 'admin'), new lang_string('confignavshowallcourses', 'admin'), 0));
$sortoptions = array(
'sortorder' => new lang_string('sort_sortorder', 'admin'),
'fullname' => new lang_string('sort_fullname', 'admin'),
'shortname' => new lang_string('sort_shortname', 'admin'),
'idnumber' => new lang_string('sort_idnumber', 'admin'),
);
$temp->add(new admin_setting_configselect('navsortmycoursessort', new lang_string('navsortmycoursessort', 'admin'), new lang_string('navsortmycoursessort_help', 'admin'), 'sortorder', $sortoptions));
$temp->add(new admin_setting_configtext('navcourselimit',new lang_string('navcourselimit','admin'),new lang_string('confignavcourselimit', 'admin'),20,PARAM_INT));
$temp->add(new admin_setting_configcheckbox('usesitenameforsitepages', new lang_string('usesitenameforsitepages', 'admin'), new lang_string('configusesitenameforsitepages', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('linkadmincategories', new lang_string('linkadmincategories', 'admin'), new lang_string('linkadmincategories_help', 'admin'), 0));
Expand Down
6 changes: 6 additions & 0 deletions lang/en/admin.php
Expand Up @@ -747,6 +747,8 @@
$string['navshowcategories'] = 'Show course categories';
$string['navshowmycoursecategories'] = 'Show my course categories';
$string['navshowmycoursecategories_help'] = 'If enabled courses in the users my courses branch will be shown in categories.';
$string['navsortmycoursessort'] = 'Sort my courses';
$string['navsortmycoursessort_help'] = 'Determines how the courses displayed within the My courses branch on the navigation will be sorted. By default sortorder it used.';
$string['neverdeleteruns'] = 'Never delete runs';
$string['nobookmarksforuser'] = 'You do not have any bookmarks.';
$string['nodatabase'] = 'No database';
Expand Down Expand Up @@ -971,6 +973,10 @@
$string['slasharguments'] = 'Use slash arguments';
$string['smartpix'] = 'Smart pix search';
$string['soaprecommended'] = 'Installing the optional soap extension is useful for web services and some contrib modules.';
$string['sort_fullname'] = 'Fullname';
$string['sort_idnumber'] = 'ID Number';
$string['sort_shortname'] = 'Shortname';
$string['sort_sortorder'] = 'Sort order';
$string['spellengine'] = 'Spell engine';
$string['spelllanguagelist'] = 'Spell language list';
$string['splrequired'] = 'The SPL PHP extension is now required by Moodle.';
Expand Down
85 changes: 46 additions & 39 deletions lib/navigationlib.php
Expand Up @@ -1062,7 +1062,7 @@ public function initialise() {
$this->rootnodes['site'] = $this->add_course($SITE);
$this->rootnodes['myprofile'] = $this->add(get_string('myprofile'), null, self::TYPE_USER, null, 'myprofile');
$this->rootnodes['currentcourse'] = $this->add(get_string('currentcourse'), null, self::TYPE_ROOTNODE, null, 'currentcourse');
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my'), self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my/'), self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['courses'] = $this->add(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_ROOTNODE, null, 'courses');
$this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');

Expand All @@ -1089,6 +1089,10 @@ public function initialise() {
$this->rootnodes['courses']->isexpandable = true;
}

if ($this->rootnodes['mycourses']->isactive) {
$this->load_courses_enrolled();
}

$canviewcourseprofile = true;

// Next load context specific content into the navigation
Expand Down Expand Up @@ -2556,6 +2560,47 @@ public function find($key, $type) {
}
return parent::find($key, $type);
}

/**
* They've expanded the 'my courses' branch.
*/
protected function load_courses_enrolled() {
global $CFG, $DB;
$sortorder = 'visible DESC';
// Append the chosen sortorder.
$sortorder = $sortorder . ',' . $CFG->navsortmycoursessort . ' ASC';
$courses = enrol_get_my_courses(null, $sortorder);
if ($this->show_my_categories(true)) {
// OK Actually we are loading categories. We only want to load categories that have a parent of 0.
// In order to make sure we load everything required we must first find the categories that are not
// base categories and work out the bottom category in thier path.
$categoryids = array();
foreach ($courses as $course) {
$categoryids[] = $course->category;
}
$categoryids = array_unique($categoryids);
list($sql, $params) = $DB->get_in_or_equal($categoryids);
$categories = $DB->get_recordset_select('course_categories', 'id '.$sql.' AND parent <> 0', $params, 'sortorder, id', 'id, path');
foreach ($categories as $category) {
$bits = explode('/', trim($category->path,'/'));
$categoryids[] = array_shift($bits);
}
$categoryids = array_unique($categoryids);
$categories->close();

// Now we load the base categories.
list($sql, $params) = $DB->get_in_or_equal($categoryids);
$categories = $DB->get_recordset_select('course_categories', 'id '.$sql.' AND parent = 0', $params, 'sortorder, id');
foreach ($categories as $category) {
$this->add_category($category, $this->rootnodes['mycourses']);
}
$categories->close();
} else {
foreach ($courses as $course) {
$this->add_course($course, false, self::COURSE_MY);
}
}
}
}

/**
Expand Down Expand Up @@ -2682,44 +2727,6 @@ public function initialise() {
return $this->expandable;
}

/**
* They've expanded the 'my courses' branch.
*/
protected function load_courses_enrolled() {
global $DB;
$courses = enrol_get_my_courses();
if ($this->show_my_categories(true)) {
// OK Actually we are loading categories. We only want to load categories that have a parent of 0.
// In order to make sure we load everything required we must first find the categories that are not
// base categories and work out the bottom category in thier path.
$categoryids = array();
foreach ($courses as $course) {
$categoryids[] = $course->category;
}
$categoryids = array_unique($categoryids);
list($sql, $params) = $DB->get_in_or_equal($categoryids);
$categories = $DB->get_recordset_select('course_categories', 'id '.$sql.' AND parent <> 0', $params, 'sortorder, id', 'id, path');
foreach ($categories as $category) {
$bits = explode('/', trim($category->path,'/'));
$categoryids[] = array_shift($bits);
}
$categoryids = array_unique($categoryids);
$categories->close();

// Now we load the base categories.
list($sql, $params) = $DB->get_in_or_equal($categoryids);
$categories = $DB->get_recordset_select('course_categories', 'id '.$sql.' AND parent = 0', $params, 'sortorder, id');
foreach ($categories as $category) {
$this->add_category($category, $this->rootnodes['mycourses'], self::TYPE_MY_CATEGORY);
}
$categories->close();
} else {
foreach ($courses as $course) {
$this->add_course($course, false, self::COURSE_MY);
}
}
}

/**
* They've expanded the general 'courses' branch.
*/
Expand Down

0 comments on commit f87ce4e

Please sign in to comment.