From c990e4bfcb706a42c43db53eb54b7c321f232aae Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 15 Apr 2012 17:15:50 +0200 Subject: [PATCH] MDL-32405 fix PHP4isms and other E_STRICT issues in custom profile fields --- user/profile/definelib.php | 3 +- user/profile/field/checkbox/define.class.php | 2 +- user/profile/field/checkbox/field.class.php | 4 +-- user/profile/field/datetime/define.class.php | 3 +- user/profile/field/menu/define.class.php | 2 +- user/profile/field/menu/field.class.php | 15 +++++----- user/profile/field/text/define.class.php | 2 +- user/profile/field/text/field.class.php | 2 +- user/profile/field/textarea/define.class.php | 2 +- user/profile/field/textarea/field.class.php | 6 ++-- user/profile/lib.php | 30 ++++++++++---------- 11 files changed, 37 insertions(+), 34 deletions(-) diff --git a/user/profile/definelib.php b/user/profile/definelib.php index de8f6bae6ad..262fd3e57ed 100644 --- a/user/profile/definelib.php +++ b/user/profile/definelib.php @@ -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) { diff --git a/user/profile/field/checkbox/define.class.php b/user/profile/field/checkbox/define.class.php index 7785c28f354..a2d71bfe998 100644 --- a/user/profile/field/checkbox/define.class.php +++ b/user/profile/field/checkbox/define.class.php @@ -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' diff --git a/user/profile/field/checkbox/field.class.php b/user/profile/field/checkbox/field.class.php index 29aaf3dd9b4..6602556d029 100644 --- a/user/profile/field/checkbox/field.class.php +++ b/user/profile/field/checkbox/field.class.php @@ -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); } diff --git a/user/profile/field/datetime/define.class.php b/user/profile/field/datetime/define.class.php index a499ca004a3..5e454925b60 100644 --- a/user/profile/field/datetime/define.class.php +++ b/user/profile/field/datetime/define.class.php @@ -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 diff --git a/user/profile/field/menu/define.class.php b/user/profile/field/menu/define.class.php index 330472c1431..e26d0f771b2 100644 --- a/user/profile/field/menu/define.class.php +++ b/user/profile/field/menu/define.class.php @@ -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); diff --git a/user/profile/field/menu/field.class.php b/user/profile/field/menu/field.class.php index d1aa2ae6785..36b711acc8f 100644 --- a/user/profile/field/menu/field.class.php +++ b/user/profile/field/menu/field.class.php @@ -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; } diff --git a/user/profile/field/text/define.class.php b/user/profile/field/text/define.class.php index 0245212421f..fe7731c034c 100644 --- a/user/profile/field/text/define.class.php +++ b/user/profile/field/text/define.class.php @@ -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); diff --git a/user/profile/field/text/field.class.php b/user/profile/field/text/field.class.php index 06676531b8c..de726ae5030 100644 --- a/user/profile/field/text/field.class.php +++ b/user/profile/field/text/field.class.php @@ -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'); diff --git a/user/profile/field/textarea/define.class.php b/user/profile/field/textarea/define.class.php index c74b2e48d84..ff516fd0a49 100644 --- a/user/profile/field/textarea/define.class.php +++ b/user/profile/field/textarea/define.class.php @@ -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 diff --git a/user/profile/field/textarea/field.class.php b/user/profile/field/textarea/field.class.php index eeffebca4d4..2658a56437c 100644 --- a/user/profile/field/textarea/field.class.php +++ b/user/profile/field/textarea/field.class.php @@ -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); diff --git a/user/profile/lib.php b/user/profile/lib.php index 906f8ca1a91..54649d7029b 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -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); }