mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'MDL-26680-master' of git://github.com/micaherne/moodle
Conflicts: theme/bootstrapbase/style/moodle.css
This commit is contained in:
commit
ce3b8b0e71
@ -12,3 +12,5 @@ $string['defaultprofilepage'] = 'Default profile page';
|
||||
$string['addpage'] = 'Add page';
|
||||
$string['delpage'] = 'Delete page';
|
||||
$string['managepages'] = 'Manage pages';
|
||||
$string['resetpage'] = 'Reset page to default';
|
||||
$string['reseterror'] = 'There was an error resetting your page';
|
19
my/index.php
19
my/index.php
@ -42,6 +42,7 @@ redirect_if_major_upgrade_required();
|
||||
|
||||
// TODO Add sesskey check to edit
|
||||
$edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off
|
||||
$reset = optional_param('reset', null, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
|
||||
@ -53,7 +54,7 @@ if (isguestuser()) { // Force them to see system default, no editing allowed
|
||||
redirect(new moodle_url('/', array('redirect' => 0)));
|
||||
}
|
||||
|
||||
$userid = NULL;
|
||||
$userid = null;
|
||||
$USER->editing = $edit = 0; // Just in case
|
||||
$context = context_system::instance();
|
||||
$PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); // unlikely :)
|
||||
@ -98,7 +99,14 @@ if (!isguestuser()) { // Skip default home page for guests
|
||||
|
||||
// Toggle the editing state and switches
|
||||
if ($PAGE->user_allowed_editing()) {
|
||||
if ($edit !== null) { // Editing state was specified
|
||||
if ($reset !== null) {
|
||||
if (!is_null($userid)) {
|
||||
if(!$currentpage = my_reset_page($userid, MY_PAGE_PRIVATE)){
|
||||
print_error('reseterror', 'my');
|
||||
}
|
||||
redirect(new moodle_url('/my'));
|
||||
}
|
||||
} 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
|
||||
@ -126,6 +134,10 @@ if ($PAGE->user_allowed_editing()) {
|
||||
// Add button for editing page
|
||||
$params = array('edit' => !$edit);
|
||||
|
||||
$resetbutton = '';
|
||||
$resetstring = get_string('resetpage', 'my');
|
||||
$reseturl = new moodle_url("$CFG->wwwroot/my/index.php", array('edit' => 1, 'reset' => 1));
|
||||
|
||||
if (!$currentpage->userid) {
|
||||
// viewing a system page -- let the user customise it
|
||||
$editstring = get_string('updatemymoodleon');
|
||||
@ -134,11 +146,12 @@ if ($PAGE->user_allowed_editing()) {
|
||||
$editstring = get_string('updatemymoodleon');
|
||||
} else {
|
||||
$editstring = get_string('updatemymoodleoff');
|
||||
$resetbutton = $OUTPUT->single_button($reseturl, $resetstring);
|
||||
}
|
||||
|
||||
$url = new moodle_url("$CFG->wwwroot/my/index.php", $params);
|
||||
$button = $OUTPUT->single_button($url, $editstring);
|
||||
$PAGE->set_button($button);
|
||||
$PAGE->set_button($resetbutton . $button);
|
||||
|
||||
} else {
|
||||
$USER->editing = $edit = 0;
|
||||
|
32
my/lib.php
32
my/lib.php
@ -98,6 +98,38 @@ function my_copy_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') {
|
||||
return $page;
|
||||
}
|
||||
|
||||
/*
|
||||
* For a given user, this deletes their My Moodle page and returns them to the system default.
|
||||
*
|
||||
* @param int $userid the id of the user whose page should be reset
|
||||
* @param int $private either MY_PAGE_PRIVATE or MY_PAGE_PUBLIC
|
||||
* @param string $pagetype either my-index or user-profile
|
||||
* @return mixed system page, or false on error
|
||||
*/
|
||||
function my_reset_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') {
|
||||
global $DB, $CFG;
|
||||
|
||||
$page = my_get_page($userid, $private);
|
||||
if ($page->userid == $userid) {
|
||||
$context = context_user::instance($userid);
|
||||
if ($blocks = $DB->get_records('block_instances', array('parentcontextid' => $context->id,
|
||||
'pagetypepattern' => $pagetype))) {
|
||||
foreach ($blocks as $block) {
|
||||
if (is_null($block->subpagepattern) || $block->subpagepattern == $page->id) {
|
||||
blocks_delete_instance($block);
|
||||
}
|
||||
}
|
||||
}
|
||||
$DB->delete_records('my_pages', array('id' => $page->id));
|
||||
}
|
||||
|
||||
// Get the system default page
|
||||
if (!$systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => $private))) {
|
||||
return false; // error
|
||||
}
|
||||
return $systempage;
|
||||
}
|
||||
|
||||
class my_syspage_block_manager extends block_manager {
|
||||
// HACK WARNING!
|
||||
// TODO: figure out a better way to do this
|
||||
|
27
my/tests/behat/add_blocks.feature
Normal file
27
my/tests/behat/add_blocks.feature
Normal file
@ -0,0 +1,27 @@
|
||||
@core @core_my
|
||||
Feature: Add blocks to my home page
|
||||
In order to add more functionality to my home page
|
||||
As a user
|
||||
I need to add blocks to my home page
|
||||
|
||||
Background:
|
||||
Given the following "users" exists:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
| student2 | Student | 2 | student2@asd.com |
|
||||
And the following "courses" exists:
|
||||
| fullname | shortname | format |
|
||||
| Course 1 | C1 | topics |
|
||||
And the following "course enrolments" exists:
|
||||
| user | course | role |
|
||||
| student1 | C1 | student |
|
||||
| student2 | C1 | student |
|
||||
And I log in as "student1"
|
||||
And I follow "My home"
|
||||
|
||||
Scenario: Add blocks to page
|
||||
When I press "Customise this page"
|
||||
And I add the "Latest news" block
|
||||
And I add the "My latest badges" block
|
||||
Then I should see "Latest news"
|
||||
And I should see "My latest badges"
|
29
my/tests/behat/reset_page.feature
Normal file
29
my/tests/behat/reset_page.feature
Normal file
@ -0,0 +1,29 @@
|
||||
@core @core_my
|
||||
Feature: Reset my home page to default
|
||||
In order to remove customisations from my home page
|
||||
As a user
|
||||
I need to reset my home page
|
||||
|
||||
Background:
|
||||
Given the following "users" exists:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
| student2 | Student | 2 | student2@asd.com |
|
||||
And the following "courses" exists:
|
||||
| fullname | shortname | format |
|
||||
| Course 1 | C1 | topics |
|
||||
And the following "course enrolments" exists:
|
||||
| user | course | role |
|
||||
| student1 | C1 | student |
|
||||
| student2 | C1 | student |
|
||||
And I log in as "student1"
|
||||
And I follow "My home"
|
||||
|
||||
Scenario: Add blocks to page and reset
|
||||
When I press "Customise this page"
|
||||
And I add the "Latest news" block
|
||||
And I add the "My latest badges" block
|
||||
And I press "Reset page to default"
|
||||
Then I should not see "Latest news"
|
||||
And I should not see "My latest badges"
|
||||
And I should not see "Reset page to default"
|
@ -200,6 +200,7 @@ a.skip:active {position: static;display: block;}
|
||||
.navbutton {text-align:right;}
|
||||
.breadcrumb ul {padding:0;margin:0;text-indent:0;list-style:none;}
|
||||
.navbutton {float: right;}
|
||||
.navbutton .singlebutton {margin-left: 4px}
|
||||
.breadcrumb li,
|
||||
.navbutton div,
|
||||
.navbutton form {display:inline;}
|
||||
@ -759,6 +760,7 @@ body.tag .managelink {padding: 5px;}
|
||||
.dir-rtl .headermenu {float:left;}
|
||||
.dir-rtl .breadcrumb {float:right;}
|
||||
.dir-rtl .navbutton {float: left;}
|
||||
.dir-rtl .navbutton .singlebutton {margin-right: 4px}
|
||||
.dir-rtl .breadcrumb ul li { float: right; margin-left: 5px;}
|
||||
.dir-rtl .mform .fitem .fitemtitle {float:right;}
|
||||
.dir-rtl .loginbox .loginform .form-label {float:right;text-align:left;}
|
||||
|
@ -118,6 +118,11 @@ select {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.breadcrumb-button .singlebutton {
|
||||
float: left;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.dir-rtl {
|
||||
.nav-tabs > li,
|
||||
.nav-pills > li {
|
||||
@ -146,6 +151,11 @@ select {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.dir-rtl .breadcrumb-button .singlebutton {
|
||||
float: right;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.ie .row-fluid .desktop-first-column {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -42,6 +42,7 @@ require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
$userid = optional_param('id', 0, PARAM_INT);
|
||||
$edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off
|
||||
$reset = optional_param('reset', null, PARAM_BOOL);
|
||||
|
||||
$PAGE->set_url('/user/profile.php', array('id'=>$userid));
|
||||
|
||||
@ -149,7 +150,14 @@ if ($node = $PAGE->settingsnav->get('root')) {
|
||||
|
||||
// Toggle the editing state and switches
|
||||
if ($PAGE->user_allowed_editing()) {
|
||||
if ($edit !== null) { // Editing state was specified
|
||||
if ($reset !== null) {
|
||||
if (!is_null($userid)) {
|
||||
if (!$currentpage = my_reset_page($userid, MY_PAGE_PUBLIC, 'user-profile')){
|
||||
print_error('reseterror', 'my');
|
||||
}
|
||||
redirect(new moodle_url('/user/profile.php'));
|
||||
}
|
||||
} 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
|
||||
@ -176,19 +184,25 @@ if ($PAGE->user_allowed_editing()) {
|
||||
// Add button for editing page
|
||||
$params = array('edit' => !$edit);
|
||||
|
||||
$resetbutton = '';
|
||||
$resetstring = get_string('resetpage', 'my');
|
||||
$reseturl = new moodle_url("$CFG->wwwroot/user/profile.php", array('edit' => 1, 'reset' => 1));
|
||||
|
||||
if (!$currentpage->userid) {
|
||||
// viewing a system page -- let the user customise it
|
||||
$editstring = get_string('updatemymoodleon');
|
||||
$params['edit'] = 1;
|
||||
} else if (empty($edit)) {
|
||||
$editstring = get_string('updatemymoodleon');
|
||||
$resetbutton = $OUTPUT->single_button($reseturl, $resetstring);
|
||||
} else {
|
||||
$editstring = get_string('updatemymoodleoff');
|
||||
$resetbutton = $OUTPUT->single_button($reseturl, $resetstring);
|
||||
}
|
||||
|
||||
$url = new moodle_url("$CFG->wwwroot/user/profile.php", $params);
|
||||
$button = $OUTPUT->single_button($url, $editstring);
|
||||
$PAGE->set_button($button);
|
||||
$PAGE->set_button($resetbutton . $button);
|
||||
|
||||
} else {
|
||||
$USER->editing = $edit = 0;
|
||||
|
25
user/tests/behat/add_blocks.feature
Normal file
25
user/tests/behat/add_blocks.feature
Normal file
@ -0,0 +1,25 @@
|
||||
@core @core_user
|
||||
Feature: Add blocks to my profile page
|
||||
In order to add more functionality to my profile page
|
||||
As a user
|
||||
I need to add blocks to my profile page
|
||||
|
||||
Background:
|
||||
Given the following "users" exists:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
| student2 | Student | 2 | student2@asd.com |
|
||||
And the following "courses" exists:
|
||||
| fullname | shortname | format |
|
||||
| Course 1 | C1 | topics |
|
||||
And the following "course enrolments" exists:
|
||||
| user | course | role |
|
||||
| student1 | C1 | student |
|
||||
| student2 | C1 | student |
|
||||
And I log in as "admin"
|
||||
And I follow "View profile"
|
||||
|
||||
Scenario: Add blocks to page
|
||||
When I press "Customise this page"
|
||||
And I add the "Latest news" block
|
||||
Then I should see "Latest news"
|
27
user/tests/behat/reset_page.feature
Normal file
27
user/tests/behat/reset_page.feature
Normal file
@ -0,0 +1,27 @@
|
||||
@core @core_user
|
||||
Feature: Reset my profile page to default
|
||||
In order to remove customisations from my profile page
|
||||
As a user
|
||||
I need to reset my profile page
|
||||
|
||||
Background:
|
||||
Given the following "users" exists:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
| student2 | Student | 2 | student2@asd.com |
|
||||
And the following "courses" exists:
|
||||
| fullname | shortname | format |
|
||||
| Course 1 | C1 | topics |
|
||||
And the following "course enrolments" exists:
|
||||
| user | course | role |
|
||||
| student1 | C1 | student |
|
||||
| student2 | C1 | student |
|
||||
And I log in as "admin"
|
||||
And I follow "View profile"
|
||||
|
||||
Scenario: Add blocks to page and reset
|
||||
When I press "Customise this page"
|
||||
And I add the "Latest news" block
|
||||
And I press "Reset page to default"
|
||||
Then I should not see "Latest news"
|
||||
And I should not see "Reset page to default"
|
Loading…
x
Reference in New Issue
Block a user