MDL-32405 fix PHP4isms and other E_STRICT issues in custom profile fields
This commit is contained in:
@@ -58,7 +58,7 @@ class profile_define_base {
|
||||
* editing a profile field specific to the current data type
|
||||
* @param object instance of the moodleform class
|
||||
*/
|
||||
function define_form_specific(&$form) {
|
||||
function define_form_specific($form) {
|
||||
/// do nothing - overwrite if necessary
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ class profile_define_base {
|
||||
* Validate the data from the add/edit profile field form
|
||||
* that is specific to the current data type
|
||||
* @param object data from the add/edit profile field form
|
||||
* @param array files
|
||||
* @return array associative array of error messages
|
||||
*/
|
||||
function define_validate_specific($data, $files) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class profile_define_checkbox extends profile_define_base {
|
||||
|
||||
function define_form_specific(&$form) {
|
||||
function define_form_specific($form) {
|
||||
/// select whether or not this should be checked by default
|
||||
$form->addElement('selectyesno', 'defaultdata', get_string('profiledefaultchecked', 'admin'));
|
||||
$form->setDefault('defaultdata', 0); // defaults to 'no'
|
||||
|
||||
@@ -22,9 +22,9 @@ class profile_field_checkbox extends profile_field_base {
|
||||
}
|
||||
}
|
||||
|
||||
function edit_field_add(&$mform) {
|
||||
function edit_field_add($mform) {
|
||||
/// Create the form field
|
||||
$checkbox = &$mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name));
|
||||
$checkbox = $mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name));
|
||||
if ($this->data == '1') {
|
||||
$checkbox->setChecked(true);
|
||||
}
|
||||
|
||||
@@ -47,9 +47,10 @@ class profile_define_datetime extends profile_define_base {
|
||||
* Validate the data from the profile field form
|
||||
*
|
||||
* @param object data from the add/edit profile field form
|
||||
* @param array files
|
||||
* @return array associative array of error messages
|
||||
*/
|
||||
function define_validate_specific($data) {
|
||||
function define_validate_specific($data, $files) {
|
||||
$errors = array();
|
||||
|
||||
// Make sure the start year is not greater than the end year
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class profile_define_menu extends profile_define_base {
|
||||
|
||||
function define_form_specific(&$form) {
|
||||
function define_form_specific($form) {
|
||||
/// Param 1 for menu type contains the options
|
||||
$form->addElement('textarea', 'param1', get_string('profilemenuoptions', 'admin'), array('rows' => 6, 'cols' => 40));
|
||||
$form->setType('param1', PARAM_MULTILANG);
|
||||
|
||||
@@ -34,7 +34,7 @@ class profile_field_menu extends profile_field_base {
|
||||
* Overwrites the base class method
|
||||
* @param object moodleform instance
|
||||
*/
|
||||
function edit_field_add(&$mform) {
|
||||
function edit_field_add($mform) {
|
||||
$mform->addElement('select', $this->inputname, format_string($this->field->name), $this->options);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class profile_field_menu extends profile_field_base {
|
||||
* Set the default value for this field instance
|
||||
* Overwrites the base class method
|
||||
*/
|
||||
function edit_field_set_default(&$mform) {
|
||||
function edit_field_set_default($mform) {
|
||||
if (FALSE !==array_search($this->field->defaultdata, $this->options)){
|
||||
$defaultkey = (int)array_search($this->field->defaultdata, $this->options);
|
||||
} else {
|
||||
@@ -55,10 +55,11 @@ class profile_field_menu extends profile_field_base {
|
||||
* The data from the form returns the key. This should be converted to the
|
||||
* respective option string to be saved in database
|
||||
* Overwrites base class accessor method
|
||||
* @param integer the key returned from the select input in the form
|
||||
* @param mixed $data - the key returned from the select input in the form
|
||||
* @param stdClass $datarecord The object that will be used to save the record
|
||||
*/
|
||||
function edit_save_data_preprocess($key) {
|
||||
return isset($this->options[$key]) ? $this->options[$key] : NULL;
|
||||
function edit_save_data_preprocess($data, $datarecord) {
|
||||
return isset($this->options[$data]) ? $this->options[$data] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +68,7 @@ class profile_field_menu extends profile_field_base {
|
||||
* Overwrites the base class method
|
||||
* @param object user object
|
||||
*/
|
||||
function edit_load_user_data(&$user) {
|
||||
function edit_load_user_data($user) {
|
||||
$user->{$this->inputname} = $this->datakey;
|
||||
}
|
||||
|
||||
@@ -75,7 +76,7 @@ class profile_field_menu extends profile_field_base {
|
||||
* HardFreeze the field if locked.
|
||||
* @param object instance of the moodleform class
|
||||
*/
|
||||
function edit_field_set_locked(&$mform) {
|
||||
function edit_field_set_locked($mform) {
|
||||
if (!$mform->elementExists($this->inputname)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class profile_define_text extends profile_define_base {
|
||||
|
||||
function define_form_specific(&$form) {
|
||||
function define_form_specific($form) {
|
||||
/// Default data
|
||||
$form->addElement('text', 'defaultdata', get_string('profiledefaultdata', 'admin'), 'size="50"');
|
||||
$form->setType('defaultdata', PARAM_MULTILANG);
|
||||
|
||||
@@ -26,7 +26,7 @@ class profile_field_text extends profile_field_base {
|
||||
return $data;
|
||||
}
|
||||
|
||||
function edit_field_add(&$mform) {
|
||||
function edit_field_add($mform) {
|
||||
$size = $this->field->param1;
|
||||
$maxlength = $this->field->param2;
|
||||
$fieldtype = ($this->field->param3 == 1 ? 'password' : 'text');
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class profile_define_textarea extends profile_define_base {
|
||||
|
||||
function define_form_specific(&$form) {
|
||||
function define_form_specific($form) {
|
||||
/// Default data
|
||||
$form->addElement('editor', 'defaultdata', get_string('profiledefaultdata', 'admin'));
|
||||
$form->setType('defaultdata', PARAM_RAW); // we have to trust person with capability to edit this default description
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
class profile_field_textarea extends profile_field_base {
|
||||
|
||||
function edit_field_add(&$mform) {
|
||||
function edit_field_add($mform) {
|
||||
$cols = $this->field->param1;
|
||||
$rows = $this->field->param2;
|
||||
|
||||
@@ -17,7 +17,7 @@ class profile_field_textarea extends profile_field_base {
|
||||
return false;
|
||||
}
|
||||
|
||||
function edit_save_data_preprocess($data, &$datarecord) {
|
||||
function edit_save_data_preprocess($data, $datarecord) {
|
||||
if (is_array($data)) {
|
||||
$datarecord->dataformat = $data['format'];
|
||||
$data = $data['text'];
|
||||
@@ -25,7 +25,7 @@ class profile_field_textarea extends profile_field_base {
|
||||
return $data;
|
||||
}
|
||||
|
||||
function edit_load_user_data(&$user) {
|
||||
function edit_load_user_data($user) {
|
||||
if ($this->data !== NULL) {
|
||||
$this->data = clean_text($this->data, $this->dataformat);
|
||||
$user->{$this->inputname} = array('text'=>$this->data, 'format'=>$this->dataformat);
|
||||
|
||||
+15
-15
@@ -43,7 +43,7 @@ class profile_field_base {
|
||||
* Abstract method: Adds the profile field to the moodle form class
|
||||
* @param form instance of the moodleform class
|
||||
*/
|
||||
function edit_field_add(&$mform) {
|
||||
function edit_field_add($mform) {
|
||||
print_error('mustbeoveride', 'debug', '', 'edit_field_add');
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class profile_field_base {
|
||||
* @param object instance of the moodleform class
|
||||
* $return boolean
|
||||
*/
|
||||
function edit_field(&$mform) {
|
||||
function edit_field($mform) {
|
||||
|
||||
if ($this->field->visible != PROFILE_VISIBLE_NONE
|
||||
or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
@@ -82,7 +82,7 @@ class profile_field_base {
|
||||
* @param object instance of the moodleform class
|
||||
* $return boolean
|
||||
*/
|
||||
function edit_after_data(&$mform) {
|
||||
function edit_after_data($mform) {
|
||||
|
||||
if ($this->field->visible != PROFILE_VISIBLE_NONE
|
||||
or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
@@ -158,7 +158,7 @@ class profile_field_base {
|
||||
* Sets the default data for the field in the form object
|
||||
* @param object instance of the moodleform class
|
||||
*/
|
||||
function edit_field_set_default(&$mform) {
|
||||
function edit_field_set_default($mform) {
|
||||
if (!empty($default)) {
|
||||
$mform->setDefault($this->inputname, $this->field->defaultdata);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class profile_field_base {
|
||||
* Sets the required flag for the field in the form object
|
||||
* @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))) {
|
||||
$mform->addRule($this->inputname, get_string('required'), 'required', null, 'client');
|
||||
}
|
||||
@@ -178,7 +178,7 @@ class profile_field_base {
|
||||
* HardFreeze the field if locked.
|
||||
* @param object instance of the moodleform class
|
||||
*/
|
||||
function edit_field_set_locked(&$mform) {
|
||||
function edit_field_set_locked($mform) {
|
||||
if (!$mform->elementExists($this->inputname)) {
|
||||
return;
|
||||
}
|
||||
@@ -190,11 +190,11 @@ class profile_field_base {
|
||||
|
||||
/**
|
||||
* Hook for child classess to process the data before it gets saved in database
|
||||
* @param mixed
|
||||
* @param stdClass The object that will be used to save the record
|
||||
* @param mixed $data
|
||||
* @param stdClass $datarecord The object that will be used to save the record
|
||||
* @return mixed
|
||||
*/
|
||||
function edit_save_data_preprocess($data, &$datarecord) {
|
||||
function edit_save_data_preprocess($data, $datarecord) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ class profile_field_base {
|
||||
* form
|
||||
* @param object a user object
|
||||
*/
|
||||
function edit_load_user_data(&$user) {
|
||||
function edit_load_user_data($user) {
|
||||
if ($this->data !== NULL) {
|
||||
$user->{$this->inputname} = $this->data;
|
||||
}
|
||||
@@ -336,7 +336,7 @@ class profile_field_base {
|
||||
|
||||
/***** General purpose functions for customisable user profiles *****/
|
||||
|
||||
function profile_load_data(&$user) {
|
||||
function profile_load_data($user) {
|
||||
global $CFG, $DB;
|
||||
|
||||
if ($fields = $DB->get_records('user_info_field')) {
|
||||
@@ -353,7 +353,7 @@ function profile_load_data(&$user) {
|
||||
* Print out the customisable categories and fields for a users profile
|
||||
* @param object instance of the moodleform class
|
||||
*/
|
||||
function profile_definition(&$mform) {
|
||||
function profile_definition($mform) {
|
||||
global $CFG, $DB;
|
||||
|
||||
// if user is "admin" fields are displayed regardless
|
||||
@@ -386,7 +386,7 @@ function profile_definition(&$mform) {
|
||||
}
|
||||
}
|
||||
|
||||
function profile_definition_after_data(&$mform, $userid) {
|
||||
function profile_definition_after_data($mform, $userid) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$userid = ($userid < 0) ? 0 : (int)$userid;
|
||||
@@ -453,7 +453,7 @@ function profile_display_fields($userid) {
|
||||
* should appear on the signup page
|
||||
* @param object moodle form object
|
||||
*/
|
||||
function profile_signup_fields(&$mform) {
|
||||
function profile_signup_fields($mform) {
|
||||
global $CFG, $DB;
|
||||
|
||||
//only retrieve required custom fields (with category information)
|
||||
@@ -513,7 +513,7 @@ function profile_user_record($userid) {
|
||||
* @param object $user user object
|
||||
* @return void $user object is modified
|
||||
*/
|
||||
function profile_load_custom_fields(&$user) {
|
||||
function profile_load_custom_fields($user) {
|
||||
$user->profile = (array)profile_user_record($user->id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user