]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8096 - some more fixes and minor refactoring in custom profile fields
authorskodak <skodak>
Fri, 26 Jan 2007 13:49:32 +0000 (13:49 +0000)
committerskodak <skodak>
Fri, 26 Jan 2007 13:49:32 +0000 (13:49 +0000)
user/profile/definelib.php
user/profile/field/menu/field.class.php
user/profile/field/text/define.class.php
user/profile/field/text/field.class.php
user/profile/lib.php

index 1e1a46a9a3523d3d423a8d751b5841ad433cf261..5c1ae827c00acb3d38bdb0a6afaa5b1fcbb37dc6 100644 (file)
@@ -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;
index c3b7a014e50fb5912d7efa0e4ee917d1d623c446..9faa510d8155cfbb6447593d7ff5fa4883d97d41 100644 (file)
@@ -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);
     }
 }
 
index f0b6a2d6c8f72c16a8cc27a9523f15775115dc8e..7de9ec9ff7f3ce779dd91d6a5b0022effd8b662c 100644 (file)
@@ -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);
     }
 
index 3a89efb3409da0e02b230819c22e928278c249cf..598bd5cb528b0ef96fd2cc2f42eb0c2c570122c7 100644 (file)
@@ -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);
     }
 
 }
index 4c13ab4867d36a844841c2a9539d8e6e8a1492c2..bd80876cbbbc2be961e563f76b563438b0e94ff5 100644 (file)
@@ -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);
 
                 }
             }