]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8096 - fixed use of formslib in custom profile field gui
authorskodak <skodak>
Thu, 25 Jan 2007 19:36:47 +0000 (19:36 +0000)
committerskodak <skodak>
Thu, 25 Jan 2007 19:36:47 +0000 (19:36 +0000)
user/profile/field/menu/field.class.php
user/profile/index.php
user/profile/index_category_form.php
user/profile/index_field_form.php
user/profile/lib.php

index 584e083e6d31995b0d754ebd3a3050dbfad14d21..72612ec726347661b1ecacf9d35a69454701f930 100644 (file)
@@ -4,7 +4,9 @@ class profile_field_menu extends profile_field_base {
 
     function init() {
         /// Param 1 for menu type is the options
-        if (($options = explode("\n", $this->field->param1)) === false) {
+        if (empty($this->field->param1)) {
+            $options = array();
+        } else if (($options = explode("\n", $this->field->param1)) === false) {
             $options = array();
         }
         $this->options = $options;
index ec55cb867294425cb0fa688945cc9e3f3ae4bd2a..76b4eefe3361b9033f1d138c2c5fd7dc0b584784 100644 (file)
@@ -110,7 +110,8 @@ if ( ($action == 'editcategory' )) {
 
    
     require_once('index_category_form.php');
-    $categoryform = new category_form(null, compact('category'));
+    $categoryform = new category_form(null);
+    $categoryform->set_data($category);
     if ($categoryform->is_cancelled()) {
         redirect($redirect);
         exit;
@@ -153,7 +154,8 @@ if ( ($action == 'editcategory' )) {
 } elseif ( $action == 'editfield' ) {
    
     require_once('index_field_form.php');
-    $fieldform = new field_form(null, compact('field'));
+    $fieldform = new field_form(null, $field->datatype);
+    $fieldform->set_data($field);
     if ($fieldform->is_cancelled()) {
         redirect($redirect);
         exit;
index 596db12a93313712282ef6bfc08e285380dbd4c0..d636365efb8f627f720a8462924399412a6cce8d 100644 (file)
@@ -8,41 +8,34 @@ class category_form extends moodleform {
     function definition () {
         global $USER, $CFG;
 
-        $mform      =& $this->_form;
-        $renderer   =& $mform->defaultRenderer();
-        $category   =  $this->_customdata['category'];
+        $mform =& $this->_form;
         
         $strrequired = get_string('required');
 
         /// Add some extra hidden fields
-        $mform->addElement('hidden', 'id', $category->id);
+        $mform->addElement('hidden', 'id');
         $mform->addElement('hidden', 'action', 'editcategory');
-        $mform->addElement('hidden', 'sesskey', $USER->sesskey);
 
         $mform->addElement('text', 'name', get_string('profilecategoryname', 'admin'), 'maxlength="255" size="30"');
         $mform->setType('name', PARAM_MULTILANG);
         $mform->addRule('name', $strrequired, 'required', null, 'client');
-        $mform->setDefault('name', $category->name);
         
         $this->add_action_buttons(true);
 
 
     } /// End of function
 
-    function definition_after_data () {
-        /// nothing yet
-    }
-
-
 /// perform some moodle validation
     function validation ($data) {
         global $CFG;
 
         $data  = (object)$data;
         $err = array();
+        
+        $category = get_record('user_info_category', 'id', $data->id); 
 
         /// Check the name is unique
-        if (($category = get_record('user_info_category', 'name', $data->name)) and ($category->id <> $data->id)) {
+        if ($category and ($category->name !== $data->name) and (record_exists('user_info_category', 'name', $data->name))) {
             $err['name'] = get_string('profilecategorynamenotunique', 'admin');
         }
 
index 979348bb94a3fa1ab410529dfa85df2cf772ead3..4189a0366fabd1f46e441099739ff60bc7f73d91 100644 (file)
@@ -8,29 +8,26 @@ class field_form extends moodleform {
     function definition () {
         global $USER, $CFG;
 
-        $mform      =& $this->_form;
-        $renderer   =& $mform->defaultRenderer();
-        $field       = $this->_customdata['field'];
+        $mform     =& $this->_form;
+        $fieldtype = $this->_customdata;
         
         $strrequired = get_string('required');
 
         /// Add some extra hidden fields
-        $mform->addElement('hidden', 'id', $field->id);
+        $mform->addElement('hidden', 'id');
         $mform->addElement('hidden', 'action', 'editfield');
-        $mform->addElement('hidden', 'type', $field->datatype);
-        $mform->addElement('hidden', 'oldcategory', $field->categoryid);
-        $mform->addElement('hidden', 'datatype', $field->datatype);
-        $mform->addElement('hidden', 'sesskey', $USER->sesskey);
+        $mform->addElement('hidden', 'type', $fieldtype);
+        $mform->addElement('hidden', 'oldcategory');
+        $mform->addElement('hidden', 'datatype');
+        $mform->addElement('hidden', 'sesskey');
         
 
         /// Everything else is dependant on the data type
-        require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
-        $newfield = 'profile_field_'.$field->datatype;
-        $formfield = new $newfield($field->id);
+        require_once($CFG->dirroot.'/user/profile/field/'.$fieldtype.'/field.class.php');
+        $newfield = 'profile_field_'.$fieldtype;
+        $formfield = new $newfield();
         $formfield->edit_field($mform);
         
-        /// override the defaults with the user settings
-        $this->set_data($field);
 
         $this->add_action_buttons(true);
 
@@ -47,12 +44,12 @@ class field_form extends moodleform {
         global $CFG;
 
         $data  = (object)$data;
-        $field = $this->_customdata['field'];
+        $fieldtype = $this->_customdata;
         
         /// Everything else is dependant on the data type
-        require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
-        $newfield = 'profile_field_'.$field->datatype;
-        $formfield = new $newfield($field->id);
+        require_once($CFG->dirroot.'/user/profile/field/'.$fieldtype.'/field.class.php');
+        $newfield = 'profile_field_'.$fieldtype;
+        $formfield = new $newfield();
         $err = $formfield->edit_validate($data);
 
         if (count($err) == 0){
index 552ffea9fc5138942590c565fc52477f036da2a2..ae7895efa3cba7a084c03014727205593e6a6fed 100644 (file)
@@ -212,7 +212,7 @@ class profile_field_base {
         $form->addElement('selectyesno', 'locked', get_string('profilelocked', 'admin'));
         $form->setType('locked', PARAM_BOOL);
 
-        unset($choices);
+        $choices = array();
         $choices[0] = get_string('profilevisiblenone', 'admin');
         $choices[1] = get_string('profilevisibleprivate', 'admin');
         $choices[2] = get_string('profilevisibleall', 'admin');
@@ -221,7 +221,7 @@ class profile_field_base {
         $form->setDefault('visible', 2);
         $form->setHelpButton('visible', array('profilevisible', get_string('profilevisible','admin')));
 
-        unset($choices);
+        $choices = array();
         $choices = profile_list_categories();
         $form->addElement('select', 'categoryid', get_string('profilecategory', 'admin'), $choices);
         $form->setType('categoryid', PARAM_INT);