Skip to content

Commit

Permalink
navigation MDL-22425 Restructured navigation for the nth time plus pe…
Browse files Browse the repository at this point in the history
…rformance tweaking and course display limit
  • Loading branch information
Sam Hemelryk committed May 13, 2010
1 parent 9da5f50 commit 4766a50
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 68 deletions.
1 change: 1 addition & 0 deletions admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
$temp = new admin_settingpage('navigation', get_string('navigation'));
$temp->add(new admin_setting_configcheckbox('navshowcategories', get_string('navshowcategories', 'admin'), get_string('confignavshowcategories', 'admin'), 1));
$temp->add(new admin_setting_configcheckbox('navshowallcourses', get_string('navshowallcourses', 'admin'), get_string('confignavshowallcourses', 'admin'), 0));
$temp->add(new admin_setting_configtext('navcourselimit',get_string('navcourselimit','admin'),get_string('confignavcourselimit', 'admin'),20,PARAM_INT));
$ADMIN->add('appearance', $temp);

/* TODO: reimplement editor settings and preferences, editors are now full plugins ;-)
Expand Down
8 changes: 8 additions & 0 deletions admin/settings/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@
get_string('extrauserselectorfields', 'admin'), get_string('configextrauserselectorfields', 'admin'), array('email' => '1'),
array('email' => get_string('email'), 'idnumber' => get_string('idnumber'), 'username' => get_string('username'), )));
}

$choices = array(
HOMEPAGE_SITE => get_string('site'),
HOMEPAGE_MY => get_string('mymoodle', 'admin'),
HOMEPAGE_USER => get_string('userpreference', 'admin')
);
$temp->add(new admin_setting_configselect('defaulthomepage', get_string('defaulthomepage', 'admin'), get_string('configdefaulthomepage', 'admin'), HOMEPAGE_SITE, $choices));

$ADMIN->add('roles', $temp);

if (is_siteadmin()) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/navigation/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function navigation_node($items, $attrs=array(), $expansionlimit=null,
}
$content = $item->get_content();
$title = $item->get_title();
$isbranch = (empty($expansionlimit) || $item->type != $expansionlimit) && ($item->children->count() > 0 || ($item->nodetype == navigation_node::NODETYPE_BRANCH && $item->children->count()==0 && isloggedin()));
$isbranch = ($item->type != $expansionlimit && ($item->children->count() > 0 || ($item->nodetype == navigation_node::NODETYPE_BRANCH && $item->children->count()==0 && (isloggedin() || $item->type <= navigation_node::TYPE_CATEGORY))));
$hasicon = (!$isbranch && $item->icon instanceof renderable);

if ($hasicon) {
Expand Down
18 changes: 11 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
user_accesstime_log();
}

$PAGE->set_url('/');
$PAGE->set_course($SITE);

/// If the site is currently under maintenance, then print a message
if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
print_maintenance_message();
Expand All @@ -51,13 +54,17 @@
if (moodle_needs_upgrading()) {
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
}
} else if (!empty($CFG->mymoodleredirect)) { // Redirect logged-in users to My Moodle overview if required
if (isloggedin() && !isguestuser()) {
redirect($CFG->wwwroot .'/my/index.php');
} else if (get_home_page() != HOMEPAGE_SITE) {
// Redirect logged-in users to My Moodle overview if required
if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
} else if ($CFG->defaulthomepage == HOMEPAGE_MY && optional_param('redirect', true, PARAM_BOOL)) {
redirect($CFG->wwwroot .'/my/');
} else if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) {
$PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
}
}


if (get_moodle_cookie() == '') {
set_moodle_cookie('nobody'); // To help search for cookies on login page
}
Expand All @@ -67,10 +74,7 @@
}

$PAGE->set_pagetype('site-index');
$PAGE->set_course($SITE);

$PAGE->set_other_editing_capability('moodle/course:manageactivities');
$PAGE->set_url('/');
$PAGE->set_docs_path('');
$PAGE->set_pagelayout('frontpage');
$editing = $PAGE->user_is_editing();
Expand Down
5 changes: 5 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
$string['configdebugvalidators'] = 'Enable if you want to have links to external validator servers in page footer. You may need to create new user with username <em>w3cvalidator</em>, and enable guest access. These changes may allow unauthorized access to server, do not enable on production sites!';
$string['configdefaultallowedmodules'] = 'For the courses which fall into the above category, which modules do you want to allow by default <b>when the course is created</b>?';
$string['configdefaultcourseroleid'] = 'Users who enrol in a course will be automatically assigned this role.';
$string['configdefaulthomepage'] = 'This determines the home page for logged in users';
$string['configdefaultrequestcategory'] = 'Courses requested by users will be automatically placed in this category.';
$string['configdefaultrequestedcategory'] = 'Default category to put courses that were requested into, if they\'re approved.';
$string['configdefaultuserroleid'] = 'All logged in users will be given the capabilities of the role you specify here, at the site level, in ADDITION to any other roles they may have been given. The default is the Authenticated user role (or Guest role in older versions). Note that this will not conflict with other roles they have, it just ensures that all users have capabilities that are not assignable at the course level (eg post blog entries, manage own calendar, etc).';
Expand Down Expand Up @@ -265,6 +266,7 @@
$string['configmycoursesperpage'] = 'Maximum number of courses to display in any list of a user\'s own courses';
$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['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.';
Expand Down Expand Up @@ -420,6 +422,7 @@
$string['debugvalidators'] = 'Show validator links';
$string['defaultallowedmodules'] = 'Default allowed modules';
$string['defaultcourseroleid'] = 'Default role for users in a course';
$string['defaulthomepage'] = 'Default home page for users';
$string['defaulthtmleditor'] = 'Default HTML editor';
$string['defaultrequestcategory'] = 'Default category for course requests';
$string['defaultsettinginfo'] = 'Default: {$a}';
Expand Down Expand Up @@ -691,6 +694,7 @@
$string['mysql416bypassed'] = 'However, if your site is using iso-8859-1 (latin) languages ONLY, you may continue using your currently installed MySQL 4.1.12 (or higher).';
$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['navshowcategories'] = 'Show course categories';
$string['nobookmarksforuser'] = 'You do not have any bookmarks.';
Expand Down Expand Up @@ -974,6 +978,7 @@
$string['userbulk'] = 'Bulk user actions';
$string['userdeleted'] = 'User deleted';
$string['userlist'] = 'Browse list of users';
$string['userpreference'] = 'User preference';
$string['userpolicies'] = 'User policies';
$string['userrenamed'] = 'User renamed';
$string['users'] = 'Users';
Expand Down
3 changes: 3 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@
$string['mailteachers'] = 'Inform teachers';
$string['makeafolder'] = 'Make a folder';
$string['makeeditable'] = 'If you make \'{$a}\' editable by the web server process (eg apache) then you could edit this file directly from this page';
$string['makethismyhome'] = 'Make this my default home page';
$string['manageblocks'] = 'Blocks';
$string['managecourses'] = 'Manage courses';
$string['managedatabase'] = 'Database';
Expand Down Expand Up @@ -1578,8 +1579,10 @@
$string['siteerrors'] = 'Site errors';
$string['sitefiles'] = 'Site files';
$string['sitefilesused'] = 'Site files used in this course';
$string['sitehome'] = 'Site home';
$string['sitelogs'] = 'Site logs';
$string['sitenews'] = 'Site news';
$string['sitepages'] = 'Site pages';
$string['sitepartlist'] = 'You do not have the required permissions to view the participants list';
$string['sitepartlist0'] = 'You must be a site teacher to be allowed to see the site participants list';
$string['sitepartlist1'] = 'You must be a teacher to be allowed to see the site participants list';
Expand Down
12 changes: 9 additions & 3 deletions lib/ajax/getnavbranch.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
// This identifies the block instance requesting AJAX extension
$instanceid = optional_param('instance', null, PARAM_INT);

$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));

// Create a global nav object
$navigation = new global_navigation_for_ajax($PAGE);

Expand Down Expand Up @@ -68,8 +70,12 @@
// Create a navigation object to use, we can't guarantee PAGE will be complete

$expandable = $navigation->initialise($branchtype, $branchid);
if (isset($block) && !empty($block->config->expansionlimit)) {
$navigation->set_expansion_limit($block->config->expansionlimit);
if (!isloggedin() || isguestuser()) {
$navigation->set_expansion_limit(navigation_node::TYPE_COURSE);
} else {
if (isset($block) && !empty($block->config->expansionlimit)) {
$navigation->set_expansion_limit($block->config->expansionlimit);
}
}
if (isset($block)) {
$block->trim($navigation, $trimmode, $trimlength, ceil($trimlength/2));
Expand All @@ -78,7 +84,7 @@

// Find the actuall branch we are looking for
$branch = $navigation->find($branchid, $branchtype);

// Stop buffering errors at this point
$html = ob_get_contents();
ob_end_clean();
Expand Down
30 changes: 30 additions & 0 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@
*/
define('EXTERNAL_TOKEN_EMBEDDED', 1);

/**
* The home page should be the site home
*/
define('HOMEPAGE_SITE', 0);
/**
* The home page should be the users my page
*/
define('HOMEPAGE_MY', 1);
/**
* The home page can be chosen by the user
*/
define('HOMEPAGE_USER', 2);

/// PARAMETER HANDLING ////////////////////////////////////////////////////

Expand Down Expand Up @@ -9638,3 +9650,21 @@ function mnet_get_idp_jump_url($user) {
}
return $mnetjumps[$user->mnethostid];
}

/**
* Gets the homepage to use for the current user
*
* @return int One of HOMEPAGE_*
*/
function get_home_page() {
global $CFG;

if (isloggedin() && !isguestuser() && !empty($CFG->defaulthomepage)) {
if ($CFG->defaulthomepage == HOMEPAGE_MY) {
return HOMEPAGE_MY;
} else {
return (int)get_user_preferences('user_home_page_preference', HOMEPAGE_MY);
}
}
return HOMEPAGE_SITE;
}
Loading

0 comments on commit 4766a50

Please sign in to comment.