Permalink
Browse files

Merge branch 'wip-mdl-32787-m22' of git://github.com/rajeshtaneja/moo…

…dle into MOODLE_22_STABLE
  • Loading branch information...
2 parents 54bf197 + 4598cc9 commit 56861454c1cf2be10bf5f146b3d78973c53e3cff Sam Hemelryk committed Jul 3, 2012
Showing with 29 additions and 16 deletions.
  1. +1 −1 user/edit.php
  2. +12 −6 user/edit_form.php
  3. +1 −1 user/editadvanced.php
  4. +10 −5 user/editadvanced_form.php
  5. +5 −3 user/profile/lib.php
View
2 user/edit.php
@@ -153,7 +153,7 @@
);
$user = file_prepare_standard_editor($user, 'description', $editoroptions, $personalcontext, 'user', 'profile', 0);
-$userform = new user_edit_form(null, array('editoroptions'=>$editoroptions));
+$userform = new user_edit_form(null, array('editoroptions'=>$editoroptions, 'userid' => $user->id));
if (empty($user->country)) {
// MDL-16308 - we must unset the value here so $CFG->country can be used as default one
unset($user->country);
View
18 user/edit_form.php
@@ -10,13 +10,19 @@ class user_edit_form extends moodleform {
// Define the form
function definition () {
- global $CFG, $COURSE;
+ global $CFG, $COURSE, $USER;
$mform =& $this->_form;
- if (is_array($this->_customdata) && array_key_exists('editoroptions', $this->_customdata)) {
- $editoroptions = $this->_customdata['editoroptions'];
- } else {
- $editoroptions = null;
+ $editoroptions = null;
+ $userid = $USER->id;
+
+ if (is_array($this->_customdata)) {
+ if (array_key_exists('editoroptions', $this->_customdata)) {
+ $editoroptions = $this->_customdata['editoroptions'];
+ }
+ if (array_key_exists('userid', $this->_customdata)) {
+ $userid = $this->_customdata['userid'];
+ }
}
//Accessibility: "Required" is bad legend text.
$strgeneral = get_string('general');
@@ -42,7 +48,7 @@ function definition () {
}
/// Next the customisable profile fields
- profile_definition($mform);
+ profile_definition($mform, $userid);
$this->add_action_buttons(false, get_string('updatemyprofile'));
}
View
2 user/editadvanced.php
@@ -135,7 +135,7 @@
}
//create form
-$userform = new user_editadvanced_form(null, array('editoroptions'=>$editoroptions));
+$userform = new user_editadvanced_form(null, array('editoroptions'=>$editoroptions, 'userid' => $user->id));
$userform->set_data($user);
if ($usernew = $userform->get_data()) {
View
15 user/editadvanced_form.php
@@ -13,11 +13,16 @@ function definition() {
global $USER, $CFG, $COURSE;
$mform =& $this->_form;
+ $editoroptions = null;
+ $userid = $USER->id;
- if (is_array($this->_customdata) && array_key_exists('editoroptions', $this->_customdata)) {
- $editoroptions = $this->_customdata['editoroptions'];
- } else {
- $editoroptions = null;
+ if (is_array($this->_customdata)) {
+ if (array_key_exists('editoroptions', $this->_customdata)) {
+ $editoroptions = $this->_customdata['editoroptions'];
+ }
+ if (array_key_exists('userid', $this->_customdata)) {
+ $userid = $this->_customdata['userid'];
+ }
}
//Accessibility: "Required" is bad legend text.
@@ -61,7 +66,7 @@ function definition() {
useredit_shared_definition($mform, $editoroptions);
/// Next the customisable profile fields
- profile_definition($mform);
+ profile_definition($mform, $userid);
$this->add_action_buttons(false, get_string('updatemyprofile'));
}
View
8 user/profile/lib.php
@@ -169,7 +169,8 @@ function edit_field_set_default(&$mform) {
* @param object instance of the moodleform class
*/
function edit_field_set_required(&$mform) {
- if ($this->is_required() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
+ global $USER;
+ if ($this->is_required() && ($this->userid == $USER->id)) {
$mform->addRule($this->inputname, get_string('required'), 'required', null, 'client');
}
}
@@ -352,8 +353,9 @@ function profile_load_data(&$user) {
/**
* Print out the customisable categories and fields for a users profile
* @param object instance of the moodleform class
+ * @param int $userid id of user whose profile is being edited.
*/
-function profile_definition(&$mform) {
+function profile_definition(&$mform, $userid = 0) {
global $CFG, $DB;
// if user is "admin" fields are displayed regardless
@@ -377,7 +379,7 @@ function profile_definition(&$mform) {
foreach ($fields as $field) {
require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
$newfield = 'profile_field_'.$field->datatype;
- $formfield = new $newfield($field->id);
+ $formfield = new $newfield($field->id, $userid);
$formfield->edit_field($mform);
}
}

0 comments on commit 5686145

Please sign in to comment.