Skip to content

Commit

Permalink
navigation MDL-22425 Fixed courses not being shown to logged in users…
Browse files Browse the repository at this point in the history
… and removed all traces of mymoodleredirect settings
  • Loading branch information
Sam Hemelryk committed May 14, 2010
1 parent 8e5c082 commit ba2789c
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 17 deletions.
4 changes: 2 additions & 2 deletions auth/shibboleth/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
unset($SESSION->wantsurl); /// Just in case
}

/// Go to my-moodle page instead of homepage if mymoodleredirect enabled
if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) and !empty($CFG->mymoodleredirect) and !isguestuser()) {
/// Go to my-moodle page instead of homepage if defaulthomepage enabled
if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) and !empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY and !isguestuser()) {
if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
$urltogo = $CFG->wwwroot.'/my/';
}
Expand Down
7 changes: 6 additions & 1 deletion blocks/navigation/block_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,13 @@ function get_content() {

// Initialise the JS tree object
$module = array('name'=>'block_navigation', 'fullpath'=>'/blocks/navigation/navigation.js', 'requires'=>array('core_dock', 'io', 'node', 'dom', 'event-custom', 'json-parse'));
$arguments = array($this->instance->id, array('expansions'=>$expandable, 'instance'=>$this->instance->id, 'candock'=>$this->instance_can_be_docked()));
$limit = 20;
if (!empty($CFG->navcourselimit)) {
$limit = $CFG->navcourselimit;
}
$arguments = array($this->instance->id, array('expansions'=>$expandable, 'instance'=>$this->instance->id, 'candock'=>$this->instance_can_be_docked(), 'courselimit'=>$limit));
$this->page->requires->js_init_call('M.block_navigation.init_add_tree', $arguments, false, $module);
$this->page->requires->string_for_js('viewallcourses','moodle');

// Grab the items to display
$renderer = $this->page->get_renderer('block_navigation');
Expand Down
21 changes: 19 additions & 2 deletions blocks/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ M.block_navigation = M.block_navigation || {
* @namespace
*/
classes:{},
courselimit : 20,
/**
* This function gets called when the module is first loaded as required by
* the YUI.add statement at the bottom of the page.
Expand All @@ -55,6 +56,9 @@ M.block_navigation = M.block_navigation || {
* Add new instance of navigation tree to tree collection
*/
init_add_tree:function(Y, id, properties) {
if (properties.courselimit) {
this.courselimit = properties.courselimit;
}
M.block_navigation.treecollection[id] = new M.block_navigation.classes.tree(Y, id, properties);
}
};
Expand Down Expand Up @@ -174,6 +178,7 @@ M.block_navigation.classes.tree.prototype.load_ajax = function(tid, outcome, arg
}
} catch (e) {
// If we got here then there was an error parsing the result
alert(e.message);
}
// The branch is empty so class it accordingly
args.target.replaceClass('branch', 'emptybranch');
Expand All @@ -191,7 +196,6 @@ M.block_navigation.classes.tree.prototype.add_branch = function(branchobj, targe

// Make the new branch into an object
var branch = new M.block_navigation.classes.branch(this, branchobj);

var childrenul = false;
if (depth === 1) {
if (!branch.children) {
Expand All @@ -203,10 +207,23 @@ M.block_navigation.classes.tree.prototype.add_branch = function(branchobj, targe
childrenul = branch.inject_into_dom(target);
}
if (childrenul) {
for (i in branch.children) {
var count = 0;
for (var i in branch.children) {
// Add each branch to the tree
if (branch.children[i].type == 20) {
count++;
}
this.add_branch(branch.children[i], childrenul, depth+1);
}
if (branch.type == 10 && count >= M.block_navigation.courselimit) {
var properties = Array();
properties['name'] = M.str.moodle.viewallcourses;
properties['title'] = M.str.moodle.viewallcourses;
properties['link'] = M.cfg.wwwroot+'/course/category.php?id='+branch.key;
properties['haschildren'] = false;
properties['icon'] = {'pix':"i/navigationitem",'component':'moodle'};
this.add_branch(properties, childrenul, depth+1);
}
}
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@
$string['configmymoodleredirect'] = 'This setting forces redirects to /my on login for non-admins and replaces the top level site navigation with /my';
$string['configmypagelocked'] = 'This setting prevents the default page from being edited by any non-admins';
$string['confignavcourselimit'] = 'Limits the number of courses shown to the user when they are either not logged in or are not enrolled in any courses.';
$string['confignavshowallcourses'] = 'Setting this ensures that all courses a user is registered in are shown on the navigation at all times. By default once a user browses to a course only that course is shown on the navigation.';
$string['confignavshowcategories'] = 'Show course categories in the navigation bar and navigation blocks';
$string['confignavshowallcourses'] = 'Setting this ensures that all courses on the site are shown in the navigation at all times.';
$string['confignavshowcategories'] = 'Show course categories in the navigation bar and navigation blocks. This does not occur with courses the user is currently enrolled in, they will still be listed under mycourses without categories.';
$string['confignodefaultuserrolelists'] = 'This setting prevents all users from being returned from the database from deprecated calls of get_course_user, etc., for the site course if the default role provides that access. Check this, if you suffer a performance hit.';
$string['confignonmetacoursesyncroleids'] = 'By default all role assignments from child courses are synchronised to metacourses. Roles that are selected here will not be included in the synchronisation process.';
$string['confignoreplyaddress'] = 'Emails are sometimes sent out on behalf of a user (eg forum posts). The email address you specify here will be used as the "From" address in those cases when the recipients should not be able to reply directly to the user (eg when a user chooses to keep their address private).';
Expand Down Expand Up @@ -695,7 +695,7 @@
$string['mysql416required'] = 'MySQL 4.1.16 is the minimum version required for Moodle 1.6 in order to guarantee that all data can be converted to UTF-8 in the future.';
$string['navigationupgrade'] = 'This upgrade introduces two new navigation blocks that will replace these blocks: Administration, Courses, Activities and Participants. If you had set any special permissions on those blocks you should check to make sure everything is behaving as you want it.';
$string['navcourselimit'] = 'Course limit';
$string['navshowallcourses'] = 'Show all users courses';
$string['navshowallcourses'] = 'Show all courses';
$string['navshowcategories'] = 'Show course categories';
$string['nobookmarksforuser'] = 'You do not have any bookmarks.';
$string['nodatabase'] = 'No database';
Expand Down
2 changes: 2 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,8 @@
$string['valuealreadyused'] = 'This value has already been used.';
$string['version'] = 'Version';
$string['view'] = 'View';
$string['viewallcourses'] = 'View all courses';
$string['viewallcoursescategories'] = 'View all courses and categories';
$string['viewfileinpopup'] = 'View file in a popup window';
$string['viewprofile'] = 'View profile';
$string['views'] = 'Views';
Expand Down
29 changes: 22 additions & 7 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,9 @@ public function initialise() {
}

$this->mycourses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', null, false, $limit);
$showallcourses = (count($this->mycourses) == 0 || !empty($CFG->navshowallcourses));
$showcategories = ($showallcourses && !empty($CFG->navshowcategories));

// Check if any courses were returned.
if (count($this->mycourses) > 0) {
// Add all of the users courses to the navigation
Expand All @@ -875,12 +878,12 @@ public function initialise() {
}
}

$showallcourses = (count($this->mycourses) == 0 || !empty($CFG->navshowallcourses));
$showcategories = ($showallcourses && !empty($CFG->navshowcategories));

if ($showcategories) {
// Load all categories (ensures we get the base categories)
$this->load_all_categories();
} else if ($showallcourses) {
// Load all courses
$this->load_all_courses();
}

// Next load context specific content into the navigation
Expand All @@ -889,10 +892,6 @@ public function initialise() {
case CONTEXT_COURSECAT :
// Load the front page course navigation
$this->load_course($SITE);
if ($showallcourses) {
// Load all courses
$this->load_all_courses();
}
break;
case CONTEXT_BLOCK :
case CONTEXT_COURSE :
Expand Down Expand Up @@ -948,6 +947,22 @@ public function initialise() {
break;
}

$limit = 20;
if (!empty($CFG->navcourselimit)) {
$limit = $CFG->navcourselimit;
}
if ($showcategories) {
$categories = $this->find_all_of_type(self::TYPE_CATEGORY);
foreach ($categories as &$category) {
if ($category->children->count() >= $limit) {
$url = new moodle_url('/course/category.php', array('id'=>$category->key));
$category->add(get_string('viewallcourses'), $url, self::TYPE_SETTING);
}
}
} else if ($this->rootnodes['courses']->children->count() >= $limit) {
$this->rootnodes['courses']->add(get_string('viewallcoursescategories'), new moodle_url('/course/index.php'), self::TYPE_SETTING);
}

// Load for the current user
$this->load_for_user();
// Load each extending user into the navigation.
Expand Down
4 changes: 2 additions & 2 deletions login/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@
unset($SESSION->wantsurl);
}

/// Go to my-moodle page instead of homepage if mymoodleredirect enabled
if (!empty($CFG->mymoodleredirect) and !is_siteadmin() and !isguestuser()) {
/// Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my
if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY && !is_siteadmin() && !isguestuser()) {
if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
$urltogo = $CFG->wwwroot.'/my/';
}
Expand Down

0 comments on commit ba2789c

Please sign in to comment.