Skip to content

Commit

Permalink
MDL-48930 navigation: Using user headers in user pages.
Browse files Browse the repository at this point in the history
Pages that are percieved to be in a user context are now
using a user context for the header.

Part of MDL-45774
  • Loading branch information
abgreeve committed Apr 10, 2015
1 parent e4522f8 commit 880c507
Show file tree
Hide file tree
Showing 26 changed files with 102 additions and 92 deletions.
2 changes: 1 addition & 1 deletion admin/roles/permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

if ($context->contextlevel == CONTEXT_USER and $USER->id != $context->instanceid) {
$PAGE->navigation->extend_for_user($user);
$PAGE->set_context(context_course::instance($course->id));
$PAGE->set_context(context_user::instance($user->id));
} else {
$PAGE->set_context($context);
}
Expand Down
3 changes: 2 additions & 1 deletion badges/mybackpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

$title = get_string('mybackpack', 'badges');
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->set_heading(fullname($USER));
$PAGE->set_pagelayout('mydashboard');

$backpack = $DB->get_record('badge_backpack', array('userid' => $USER->id));
Expand Down Expand Up @@ -131,5 +131,6 @@
}

echo $OUTPUT->header();
echo $OUTPUT->heading($title);
$form->display();
echo $OUTPUT->footer();
2 changes: 1 addition & 1 deletion badges/mybadges.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

$title = get_string('mybadges', 'badges');
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->set_heading(fullname($USER));
$PAGE->set_pagelayout('mydashboard');

// Include JS files for backpack support.
Expand Down
4 changes: 2 additions & 2 deletions badges/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$url = new moodle_url('/badges/preferences.php');

require_login();
$PAGE->set_context(context_system::instance());
$PAGE->set_context(context_user::instance($USER->id));
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');

Expand All @@ -55,7 +55,7 @@

$title = "$strbadges: $strpreferences";
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->set_heading(fullname($USER));

echo $OUTPUT->header();
echo $OUTPUT->heading("$strbadges: $strpreferences", 2);
Expand Down
8 changes: 4 additions & 4 deletions blog/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
$id = null;
}

// Blogs are always in system context.
$sitecontext = context_system::instance();
$PAGE->set_context($sitecontext);
$usercontext = context_user::instance($USER->id);
$PAGE->set_context($usercontext);

require_login($courseid);

Expand Down Expand Up @@ -142,10 +142,10 @@
}
} else if ($action == 'add') {
$PAGE->set_title("$SITE->shortname: $strblogs: " . get_string('addnewentry', 'blog'));
$PAGE->set_heading($SITE->shortname);
$PAGE->set_heading(fullname($USER));
} else if ($action == 'edit') {
$PAGE->set_title("$SITE->shortname: $strblogs: " . get_string('editentry', 'blog'));
$PAGE->set_heading($SITE->shortname);
$PAGE->set_heading(fullname($USER));
}

if (!empty($entry->id)) {
Expand Down
4 changes: 2 additions & 2 deletions blog/external_blog_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
$url->param('id', $id);
}
$PAGE->set_url($url);
$PAGE->set_context($context);
$PAGE->set_context(context_user::instance($USER->id));
$PAGE->set_pagelayout('admin');

$returnurl = new moodle_url('/blog/external_blogs.php');
Expand Down Expand Up @@ -125,7 +125,7 @@
redirect($returnurl);
}

$PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname);
$PAGE->set_heading(fullname($USER));
$PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");

echo $OUTPUT->header();
Expand Down
4 changes: 2 additions & 2 deletions blog/external_blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

require_login();
$context = context_system::instance();
$PAGE->set_context($context);
$PAGE->set_context(context_user::instance($USER->id));
$PAGE->set_url(new moodle_url('/blog/external_blogs.php'));
require_capability('moodle/blog:manageexternal', $context);

Expand Down Expand Up @@ -61,7 +61,7 @@

$blogs = $DB->get_records('blog_external', array('userid' => $USER->id));

$PAGE->set_heading("$SITE->shortname: $strblogs: $strexternalblogs", $SITE->fullname);
$PAGE->set_heading(fullname($USER));
$PAGE->set_title("$SITE->shortname: $strblogs: $strexternalblogs");
$PAGE->set_pagelayout('standard');

Expand Down
13 changes: 10 additions & 3 deletions blog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@
}
}

if (isset($userid)) {
$context = context_user::instance($userid);
} else {
$context = context_system::instance();
}
$PAGE->set_context($context);

$sitecontext = context_system::instance();
// Blogs are always in system context.
$PAGE->set_context($sitecontext);

// Check basic permissions.
if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) {
Expand Down Expand Up @@ -225,9 +230,11 @@
blog_rss_add_http_header($rsscontext, $rsstitle, $filtertype, $thingid, $tagid);
}
}
if (isset($userid)) {
$PAGE->set_heading(fullname($user));
}

echo $OUTPUT->header();

echo $OUTPUT->heading($blogheaders['heading'], 2);

$bloglisting = new blog_listing($blogheaders['filters']);
Expand Down
5 changes: 3 additions & 2 deletions blog/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
$PAGE->set_pagelayout('admin');

$sitecontext = context_system::instance();
$PAGE->set_context($sitecontext);
$usercontext = context_user::instance($USER->id);
$PAGE->set_context($usercontext);
require_login($courseid);

if (empty($CFG->enableblogs)) {
Expand Down Expand Up @@ -90,7 +91,7 @@

$title = "$site->shortname: $strblogs : $strpreferences";
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->set_heading(fullname($USER));

echo $OUTPUT->header();

Expand Down
11 changes: 8 additions & 3 deletions grade/report/overview/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
$context = context_course::instance($course->id);
$systemcontext = context_system::instance();
$personalcontext = null;
$PAGE->set_context($context);

// If we are accessing the page from a site context then ignore this check.
if ($courseid != SITEID) {
Expand All @@ -57,6 +56,12 @@
$personalcontext = context_user::instance($userid);
}

if (isset($personalcontext)) {
$PAGE->set_context($personalcontext);
} else {
$PAGE->set_context($context);
}

$access = false;
if (has_capability('moodle/grade:viewall', $systemcontext)) {
// Ok - can view all course grades.
Expand Down Expand Up @@ -154,9 +159,9 @@
// Display a standard page.
if ($courseid == SITEID) {
$PAGE->set_pagelayout('standard');
$header = get_string('mygrades', 'grades'). ' - '.fullname($report->user);
$header = get_string('mygrades', 'grades') . ' - ' . fullname($report->user);
$PAGE->set_title($header);
$PAGE->set_heading($header);
$PAGE->set_heading(fullname($report->user));

if ($USER->id != $report->user->id) {
$PAGE->navigation->extend_for_user($report->user);
Expand Down
4 changes: 2 additions & 2 deletions login/change_password.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
$fullname = fullname($USER, true);

$PAGE->set_title($strpasswordchanged);
$PAGE->set_heading($COURSE->fullname);
$PAGE->set_heading(fullname($USER));
echo $OUTPUT->header();

notice($strpasswordchanged, new moodle_url($PAGE->url, array('return'=>1)));
Expand All @@ -151,7 +151,7 @@
$fullname = fullname($USER, true);

$PAGE->set_title($strchangepassword);
$PAGE->set_heading($COURSE->fullname);
$PAGE->set_heading($fullname);
echo $OUTPUT->header();

if (get_user_preferences('auth_forcepasswordchange')) {
Expand Down
2 changes: 1 addition & 1 deletion message/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
/// Display page header
$strmessaging = get_string('messaging', 'message');
$PAGE->set_title($strmessaging);
$PAGE->set_heading($strmessaging);
$PAGE->set_heading(fullname($USER));

// Grab the renderer
$renderer = $PAGE->get_renderer('core', 'message');
Expand Down
6 changes: 3 additions & 3 deletions message/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@
$PAGE->set_pagelayout('incourse');
} else {
$PAGE->set_pagelayout('standard');
$PAGE->set_context(context_user::instance($user1->id));
}
// Page context should always be set to user.
$PAGE->set_context(context_user::instance($user1->id));
if (!empty($user1->id) && $user1->id != $USER->id) {
$PAGE->navigation->extend_for_user($user1);
}
Expand Down Expand Up @@ -194,11 +195,10 @@
$user2fullname = fullname($user2);

$PAGE->set_title("$strmessages: $user2fullname");
$PAGE->set_heading("$strmessages: $user2fullname");
} else {
$PAGE->set_title("{$SITE->shortname}: $strmessages");
$PAGE->set_heading("{$SITE->shortname}: $strmessages");
}
$PAGE->set_heading(fullname($USER));

//now the page contents
echo $OUTPUT->header();
Expand Down
3 changes: 2 additions & 1 deletion mod/forum/classes/event/user_report_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ protected function validate_data() {
{
case CONTEXT_COURSE:
case CONTEXT_SYSTEM:
case CONTEXT_USER:
// OK, expected context level.
break;
default:
// Unexpected contextlevel.
throw new \coding_exception('Context level must be either CONTEXT_SYSTEM or CONTEXT_COURSE.');
throw new \coding_exception('Context level must be either CONTEXT_SYSTEM, CONTEXT_COURSE or CONTEXT_USER.');
}
}

Expand Down
3 changes: 2 additions & 1 deletion mod/forum/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,8 @@ public function test_user_report_viewed_contextlevel_validation() {
'relateduserid' => $user->id,
);

$this->setExpectedException('coding_exception', 'Context level must be either CONTEXT_SYSTEM or CONTEXT_COURSE.');
$this->setExpectedException('coding_exception',
'Context level must be either CONTEXT_SYSTEM, CONTEXT_COURSE or CONTEXT_USER.');
\mod_forum\event\user_report_viewed::create($params);
}

Expand Down
12 changes: 8 additions & 4 deletions mod/forum/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,13 @@
// We are going to search for all of the users posts in all courses!
// a general require login here as we arn't actually within any course.
require_login();
$PAGE->set_context(context_system::instance());
$PAGE->set_context(context_user::instance($user->id));

// Now we need to get all of the courses to search.
// All courses where the user has posted within a forum will be returned.
$courses = forum_get_courses_user_posted_in($user, $discussionsonly);
}


$params = array(
'context' => $PAGE->context,
'relateduserid' => $user->id,
Expand Down Expand Up @@ -202,7 +201,11 @@

// Display a page letting the user know that there's nothing to display;
$PAGE->set_title($pagetitle);
$PAGE->set_heading($pageheading);
if ($isspecificcourse) {
$PAGE->set_heading($pageheading);
} else {
$PAGE->set_heading(fullname($user));
}
echo $OUTPUT->header();
echo $OUTPUT->heading($pagetitle);
echo $OUTPUT->notification($notification);
Expand Down Expand Up @@ -323,7 +326,8 @@
}

$PAGE->set_title($pagetitle);
$PAGE->set_heading($pagetitle);
$PAGE->set_heading($pageheading);

$PAGE->navigation->extend_for_user($user);
$PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.

Expand Down
34 changes: 11 additions & 23 deletions my/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,14 @@
$userid = $USER->id; // Owner of the page
$context = context_user::instance($USER->id);
$PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
$header = "$SITE->shortname: $strmymoodle";
$header = fullname($USER);
}

// Get the My Moodle page info. Should always return something unless the database is broken.
if (!$currentpage = my_get_page($userid, MY_PAGE_PRIVATE)) {
print_error('mymoodlesetup');
}

if (!$currentpage->userid) {
$context = context_system::instance(); // So we even see non-sticky blocks
}

// Start setting up the page
$params = array();
$PAGE->set_context($context);
Expand Down Expand Up @@ -109,25 +105,23 @@
}
} else if ($edit !== null) { // Editing state was specified
$USER->editing = $edit; // Change editing state
if (!$currentpage->userid && $edit) {
// If we are viewing a system page as ordinary user, and the user turns
// editing on, copy the system pages as new user pages, and get the
// new page record
if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PRIVATE)) {
print_error('mymoodlesetup');
}
$context = context_user::instance($USER->id);
$PAGE->set_context($context);
$PAGE->set_subpage($currentpage->id);
}
} else { // Editing state is in session
if ($currentpage->userid) { // It's a page we can edit, so load from session
if (!empty($USER->editing)) {
$edit = 1;
} else {
$edit = 0;
}
} else { // It's a system page and they are not allowed to edit system pages
} else {
// For the page to display properly with the user context header the page blocks need to
// be copied over to the user context.
if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PRIVATE)) {
print_error('mymoodlesetup');
}
$context = context_user::instance($USER->id);
$PAGE->set_context($context);
$PAGE->set_subpage($currentpage->id);
// It's a system page and they are not allowed to edit system pages
$USER->editing = $edit = 0; // Disable editing completely, just to be safe
}
}
Expand Down Expand Up @@ -158,12 +152,6 @@
$USER->editing = $edit = 0;
}

// HACK WARNING! This loads up all this page's blocks in the system context
if ($currentpage->userid == 0) {
$CFG->blockmanagerclass = 'my_syspage_block_manager';
}


echo $OUTPUT->header();

echo $OUTPUT->custom_block_region('content');
Expand Down
2 changes: 1 addition & 1 deletion notes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

$PAGE->set_pagelayout('incourse');
$PAGE->set_title($course->shortname . ': ' . $strnotes);
$PAGE->set_heading($course->fullname);
$PAGE->set_heading(fullname($USER));

echo $OUTPUT->header();
if ($userid) {
Expand Down
Loading

0 comments on commit 880c507

Please sign in to comment.