original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Perform some moodle validation.
  
  @param array $data
  @param array $files
  @return array
docstring_tokens: Perform some moodle validation .