public function validation($data, $files) {
        global $CFG, $DB;
        $errors = parent::validation($data, $files);

        $data  = (object)$data;

        $duplicate = $DB->get_field('user_info_category', 'id', array('name' => $data->name));

        // Check the name is unique.
        if (!empty($data->id)) { // We are editing an existing record.
            $olddata = $DB->get_record('user_info_category', array('id' => $data->id));
            // Name has changed, new name in use, new name in use by another record.
            $dupfound = (($olddata->name !== $data->name) && $duplicate && ($data->id != $duplicate));
        } else { // New profile category.
            $dupfound = $duplicate;
        }

        if ($dupfound ) {
            $errors['name'] = get_string('profilecategorynamenotunique', 'admin');
        }

        return $errors;
    }
public function validation($data, $files) {
        global $CFG, $DB;
        $errors = parent::validation($data, $files);

        $data  = (object)$data;

        $duplicate = $DB->get_field('user_info_category', 'id', array('name' => $data->name));

        // Check the name is unique.
        if (!empty($data->id)) { // We are editing an existing record.
            $olddata = $DB->get_record('user_info_category', array('id' => $data->id));
            // Name has changed, new name in use, new name in use by another record.
            $dupfound = (($olddata->name !== $data->name) && $duplicate && ($data->id != $duplicate));
        } else { // New profile category.
            $dupfound = $duplicate;
        }

        if ($dupfound ) {
            $errors['name'] = get_string('profilecategorynamenotunique', 'admin');
        }

        return $errors;
    }
public function validation ( $ data , $ files ) { global $ CFG , $ DB ; $ errors = parent :: validation ( $ data , $ files ) ; $ data = ( object ) $ data ; $ duplicate = $ DB -> get_field ( 'user_info_category' , 'id' , array ( 'name' => $ data -> name ) ) ; // Check the name is unique. if ( ! empty ( $ data -> id ) ) { // We are editing an existing record. $ olddata = $ DB -> get_record ( 'user_info_category' , array ( 'id' => $ data -> id ) ) ; // Name has changed, new name in use, new name in use by another record. $ dupfound = ( ( $ olddata -> name !== $ data -> name ) && $ duplicate && ( $ data -> id != $ duplicate ) ) ; } else { // New profile category. $ dupfound = $ duplicate ; } if ( $ dupfound ) { $ errors [ 'name' ] = get_string ( 'profilecategorynamenotunique' , 'admin' ) ; } return $ errors ; }
Perform some moodle validation.

@param array $data
@param array $files
@return array
Perform some moodle validation .