mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 08:09:47 +02:00
MDL-32787 user: rule required for custom profile fields applies to all users editing own profile
This commit is contained in:
parent
d71b79a406
commit
fc3aa0fbaf
5 changed files with 39 additions and 26 deletions
|
@ -165,7 +165,8 @@ $user->imagefile = $draftitemid;
|
||||||
//create form
|
//create form
|
||||||
$userform = new user_edit_form(null, array(
|
$userform = new user_edit_form(null, array(
|
||||||
'editoroptions' => $editoroptions,
|
'editoroptions' => $editoroptions,
|
||||||
'filemanageroptions' => $filemanageroptions));
|
'filemanageroptions' => $filemanageroptions,
|
||||||
|
'userid' => $user->id));
|
||||||
if (empty($user->country)) {
|
if (empty($user->country)) {
|
||||||
// MDL-16308 - we must unset the value here so $CFG->country can be used as default one
|
// MDL-16308 - we must unset the value here so $CFG->country can be used as default one
|
||||||
unset($user->country);
|
unset($user->country);
|
||||||
|
|
|
@ -10,18 +10,23 @@ class user_edit_form extends moodleform {
|
||||||
|
|
||||||
// Define the form
|
// Define the form
|
||||||
function definition () {
|
function definition () {
|
||||||
global $CFG, $COURSE;
|
global $CFG, $COURSE, $USER;
|
||||||
|
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
if (is_array($this->_customdata) && array_key_exists('editoroptions', $this->_customdata)) {
|
$editoroptions = null;
|
||||||
$editoroptions = $this->_customdata['editoroptions'];
|
$filemanageroptions = null;
|
||||||
} else {
|
$userid = $USER->id;
|
||||||
$editoroptions = null;
|
|
||||||
}
|
if (is_array($this->_customdata)) {
|
||||||
if (is_array($this->_customdata) && array_key_exists('filemanageroptions', $this->_customdata)) {
|
if (array_key_exists('editoroptions', $this->_customdata)) {
|
||||||
$filemanageroptions = $this->_customdata['filemanageroptions'];
|
$editoroptions = $this->_customdata['editoroptions'];
|
||||||
} else {
|
}
|
||||||
$filemanageroptions = null;
|
if (array_key_exists('filemanageroptions', $this->_customdata)) {
|
||||||
|
$filemanageroptions = $this->_customdata['filemanageroptions'];
|
||||||
|
}
|
||||||
|
if (array_key_exists('userid', $this->_customdata)) {
|
||||||
|
$userid = $this->_customdata['userid'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Accessibility: "Required" is bad legend text.
|
//Accessibility: "Required" is bad legend text.
|
||||||
$strgeneral = get_string('general');
|
$strgeneral = get_string('general');
|
||||||
|
@ -47,7 +52,7 @@ class user_edit_form extends moodleform {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Next the customisable profile fields
|
/// Next the customisable profile fields
|
||||||
profile_definition($mform);
|
profile_definition($mform, $userid);
|
||||||
|
|
||||||
$this->add_action_buttons(false, get_string('updatemyprofile'));
|
$this->add_action_buttons(false, get_string('updatemyprofile'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,8 @@ $user->imagefile = $draftitemid;
|
||||||
//create form
|
//create form
|
||||||
$userform = new user_editadvanced_form(null, array(
|
$userform = new user_editadvanced_form(null, array(
|
||||||
'editoroptions' => $editoroptions,
|
'editoroptions' => $editoroptions,
|
||||||
'filemanageroptions' => $filemanageroptions));
|
'filemanageroptions' => $filemanageroptions,
|
||||||
|
'userid' => $user->id));
|
||||||
$userform->set_data($user);
|
$userform->set_data($user);
|
||||||
|
|
||||||
if ($usernew = $userform->get_data()) {
|
if ($usernew = $userform->get_data()) {
|
||||||
|
|
|
@ -13,16 +13,20 @@ class user_editadvanced_form extends moodleform {
|
||||||
global $USER, $CFG, $COURSE;
|
global $USER, $CFG, $COURSE;
|
||||||
|
|
||||||
$mform =& $this->_form;
|
$mform =& $this->_form;
|
||||||
|
$editoroptions = null;
|
||||||
|
$filemanageroptions = null;
|
||||||
|
$userid = $USER->id;
|
||||||
|
|
||||||
if (is_array($this->_customdata) && array_key_exists('editoroptions', $this->_customdata)) {
|
if (is_array($this->_customdata)) {
|
||||||
$editoroptions = $this->_customdata['editoroptions'];
|
if (array_key_exists('editoroptions', $this->_customdata)) {
|
||||||
} else {
|
$editoroptions = $this->_customdata['editoroptions'];
|
||||||
$editoroptions = null;
|
}
|
||||||
}
|
if (array_key_exists('filemanageroptions', $this->_customdata)) {
|
||||||
if (is_array($this->_customdata) && array_key_exists('filemanageroptions', $this->_customdata)) {
|
$filemanageroptions = $this->_customdata['filemanageroptions'];
|
||||||
$filemanageroptions = $this->_customdata['filemanageroptions'];
|
}
|
||||||
} else {
|
if (array_key_exists('userid', $this->_customdata)) {
|
||||||
$filemanageroptions = null;
|
$userid = $this->_customdata['userid'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Accessibility: "Required" is bad legend text.
|
//Accessibility: "Required" is bad legend text.
|
||||||
|
@ -66,7 +70,7 @@ class user_editadvanced_form extends moodleform {
|
||||||
useredit_shared_definition($mform, $editoroptions, $filemanageroptions);
|
useredit_shared_definition($mform, $editoroptions, $filemanageroptions);
|
||||||
|
|
||||||
/// Next the customisable profile fields
|
/// Next the customisable profile fields
|
||||||
profile_definition($mform);
|
profile_definition($mform, $userid);
|
||||||
|
|
||||||
$this->add_action_buttons(false, get_string('updatemyprofile'));
|
$this->add_action_buttons(false, get_string('updatemyprofile'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,8 @@ class profile_field_base {
|
||||||
* @param object instance of the moodleform class
|
* @param object instance of the moodleform class
|
||||||
*/
|
*/
|
||||||
function edit_field_set_required($mform) {
|
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');
|
$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
|
* Print out the customisable categories and fields for a users profile
|
||||||
* @param object instance of the moodleform class
|
* @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;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// if user is "admin" fields are displayed regardless
|
// if user is "admin" fields are displayed regardless
|
||||||
|
@ -377,7 +379,7 @@ function profile_definition($mform) {
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
|
require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
|
||||||
$newfield = 'profile_field_'.$field->datatype;
|
$newfield = 'profile_field_'.$field->datatype;
|
||||||
$formfield = new $newfield($field->id);
|
$formfield = new $newfield($field->id, $userid);
|
||||||
$formfield->edit_field($mform);
|
$formfield->edit_field($mform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue