From: skodak Date: Fri, 26 Jan 2007 13:49:32 +0000 (+0000) Subject: MDL-8096 - some more fixes and minor refactoring in custom profile fields X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a5d3b072241920fe64a3ec23b24d3250a7c491f8;p=moodle.git MDL-8096 - some more fixes and minor refactoring in custom profile fields --- diff --git a/user/profile/definelib.php b/user/profile/definelib.php index 1e1a46a9a3..5c1ae827c0 100644 --- a/user/profile/definelib.php +++ b/user/profile/definelib.php @@ -33,7 +33,6 @@ class profile_define_base { $form->addElement('htmleditor', 'description', get_string('profiledescription', 'admin')); $form->setHelpButton('description', array('text', get_string('helptext'))); - $form->setType('description', PARAM_MULTILANG); $form->addElement('selectyesno', 'required', get_string('profilerequired', 'admin')); @@ -280,7 +279,7 @@ function profile_delete_field($id) { * @param string direction of move * @return boolean success of operation */ -function profile_move_field ($id, $move) { +function profile_move_field($id, $move) { /// Get the field object if (!$field = get_record('user_info_field', 'id', $id, '', '', '', '', 'id, sortorder, categoryid')) { return false; @@ -318,7 +317,7 @@ function profile_move_field ($id, $move) { * @param string direction of move * @return boolean success of operation */ -function profile_move_category ($id, $move) { +function profile_move_category($id, $move) { /// Get the category object if (!($category = get_record('user_info_category', 'id', $id, '', '', '', '', 'id, sortorder'))) { return false; diff --git a/user/profile/field/menu/field.class.php b/user/profile/field/menu/field.class.php index c3b7a014e5..9faa510d81 100644 --- a/user/profile/field/menu/field.class.php +++ b/user/profile/field/menu/field.class.php @@ -16,15 +16,15 @@ class profile_field_menu extends profile_field_base { } - function display_field_add(&$form) { + function display_field_add(&$mform) { /// Create the form field - $form->addElement('select', $this->inputname, format_string($this->field->name), $this->options); + $mform->addElement('select', $this->inputname, format_string($this->field->name), $this->options); } /// Override base class method - function display_field_default(&$form) { + function display_field_default(&$mform) { $defaultkey = (int)array_search($field->defaultdata, $this->options); - $form->setDefault($this->inputname, $defaultkey); + $mform->setDefault($this->inputname, $defaultkey); } } diff --git a/user/profile/field/text/define.class.php b/user/profile/field/text/define.class.php index f0b6a2d6c8..7de9ec9ff7 100644 --- a/user/profile/field/text/define.class.php +++ b/user/profile/field/text/define.class.php @@ -9,12 +9,12 @@ class profile_define_text extends profile_define_base { /// Param 1 for text type is the size of the field $form->addElement('text', 'param1', get_string('profilefieldsize', 'admin'), 'size="6"'); - $form->setDefault('param1', 50); + $form->setDefault('param1', 30); $form->setType('param1', PARAM_INT); /// Param 2 for text type is the maxlength of the field $form->addElement('text', 'param2', get_string('profilefieldmaxlength', 'admin'), 'size="6"'); - $form->setDefault('param2', 100); + $form->setDefault('param2', 2048); $form->setType('param2', PARAM_INT); } diff --git a/user/profile/field/text/field.class.php b/user/profile/field/text/field.class.php index 3a89efb340..598bd5cb52 100644 --- a/user/profile/field/text/field.class.php +++ b/user/profile/field/text/field.class.php @@ -2,16 +2,13 @@ class profile_field_text extends profile_field_base { - function display_field_add(&$form) { - /// Param 1 for text type is the size of the field - $size = (empty($this->field->param1)) ? '30' : $this->field->param1; - - /// Param 2 for text type is the maxlength of the field - $maxlength = (empty($this->field->param2)) ? '2048' : $this->field->param2; + function display_field_add(&$mform) { + $size = $this->field->param1; + $maxlength = $this->field->param2; /// Create the form field - $form->addElement('text', $this->inputname, format_string($this->field->name), 'maxlength="'.$maxlength.'" size="'.$size.'" '); - $form->setType($this->inputname, PARAM_MULTILANG); + $mform->addElement('text', $this->inputname, format_string($this->field->name), 'maxlength="'.$maxlength.'" size="'.$size.'" '); + $mform->setType($this->inputname, PARAM_MULTILANG); } } diff --git a/user/profile/lib.php b/user/profile/lib.php index 4c13ab4867..bd80876cbb 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -50,15 +50,15 @@ class profile_field_base { * @param object instance of the moodleform class * $return boolean */ - function display_field(&$form) { + function display_field(&$mform) { if ($this->field->visible != PROFILE_VISIBLE_NONE or has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) { - $this->display_field_add($form); - $this->display_field_set_default($form); - $this->display_field_set_required($form); - $this->display_field_set_locked($form); + $this->display_field_add($mform); + $this->display_field_set_default($mform); + $this->display_field_set_required($mform); + $this->display_field_set_locked($mform); } } @@ -97,7 +97,7 @@ class profile_field_base { * Adds the profile field to the moodle form class * @param form instance of the moodleform class */ - function display_field_add(&$form) { + function display_field_add(&$mform) { error('This abstract method must be overriden'); } @@ -121,9 +121,9 @@ class profile_field_base { * Sets the default data for the field in the form object * @param object instance of the moodleform class */ - function display_field_set_default(&$form) { + function display_field_set_default(&$mform) { if (!empty($default)) { - $form->setDefault($this->inputname, $this->field->defaultdata); + $mform->setDefault($this->inputname, $this->field->defaultdata); } } @@ -131,9 +131,9 @@ class profile_field_base { * Sets the required flag for the field in the form object * @param object instance of the moodleform class */ - function display_field_set_required(&$form) { + function display_field_set_required(&$mform) { if ($this->field->required and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) { - $form->addRule($this->inputname, get_string('required'), 'required', null, 'client'); + $mform->addRule($this->inputname, get_string('required'), 'required', null, 'client'); } } @@ -141,9 +141,9 @@ class profile_field_base { * HardFreeze the field if locked. * @param object instance of the moodleform class */ - function display_field_set_locked(&$form) { + function display_field_set_locked(&$mform) { if ($this->field->locked and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) { - $form->hardFreeze($this->inputname); + $mform->hardFreeze($this->inputname); } } @@ -178,18 +178,18 @@ 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(&$form) { +function profile_definition(&$mform) { global $CFG; if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) { foreach ($categories as $category) { if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) { - $form->addElement('header', 'category_'.$category->id, format_string($category->name)); + $mform->addElement('header', 'category_'.$category->id, format_string($category->name)); 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->display_field($form); + $formfield->display_field($mform); } }