public function validate(Validation $array, $save = FALSE) { $array->pre_filter('trim'); $array->add_rules('title', 'required'); $array->add_rules('website_id', 'required'); $this->unvalidatedFields = array('description', 'deleted', 'parent_id', 'owner_id', 'auto_accept', 'auto_accept_max_difficulty'); return parent::validate($array, $save); }
public function validate(Validation $array, $save = FALSE) { $array->pre_filter('trim'); $array->add_rules('title', 'required'); // Explicitly add those fields for which we don't do validation $this->unvalidatedFields = array('description', 'website_id', 'parent_id', 'deleted'); return parent::validate($array, $save); }
/** * Validates and optionally saves a new geometry record from an array * * @param array $array Values to check * @param bool $save Saves the record when validation succeeds * @return bool */ public function validate(array &$array, $save = FALSE) { // Set up validation $array = Validation::factory($array)->pre_filter('trim'); // Add callbacks for the layer url and layer file $array->add_callbacks('kml_file', array($this, 'file_check')); // Pass validation to parent and return return parent::validate($array, $save); }
public function validate(Validation $array, $save = false) { // uses PHP trim() to remove whitespace from beginning and end of all fields before validation $array->pre_filter('trim'); $array->add_rules('subject_type_id', 'required', 'digit'); $array->add_rules('website_id', 'required', 'digit'); // Explicitly add those fields for which we don't do validation $this->unvalidatedFields = array('parent_id', 'description', 'deleted'); return parent::validate($array, $save); }
public function validate(Validation $array, $save = FALSE) { $orig_values = $array->as_array(); // uses PHP trim() to remove whitespace from beginning and end of all fields before validation $array->pre_filter('trim'); $array->add_rules('name', 'required'); $this->add_sref_rules($array, 'centroid_sref', 'centroid_sref_system'); // Explicitly add those fields for which we don't do validation $this->unvalidatedFields = array('code', 'parent_id', 'deleted', 'centroid_geom', 'boundary_geom', 'location_type_id', 'comment', 'public', 'external_key'); return parent::validate($array, $save); }
/** * Validates and optionally saves a category record from an array * * @param array $array Values to check * @param bool $save Saves the record when validation succeeds * @return bool */ public function validate(array &$array, $save = FALSE) { // Set up validation $array = Validation::factory($array)->pre_filter('trim', TRUE)->add_rules('parent_id', 'required', 'numeric')->add_rules('category_title', 'required', 'length[3,80]')->add_rules('category_description', 'required')->add_rules('category_color', 'required', 'length[6,6]'); // Validation checks where parent_id > 0 if ($array->parent_id > 0) { if (!empty($this->id) and $this->id == $array->parent_id) { // Error Kohana::log('error', 'The parent id and category id are the same!'); $array->add_error('parent_id', 'same'); } else { // Ensure parent_id exists in the DB $array->add_callbacks('parent_id', 'Category_Model::is_valid_category'); } } // Pass on validation to parent and return return parent::validate($array, $save); }
/** * Validates and optionally saves a category record from an array * * @param array $array Values to check * @param bool $save Saves the record when validation succeeds * @return bool */ public function validate(array &$array, $save = FALSE) { // Set up validation $array = Validation::factory($array)->pre_filter('trim', TRUE)->add_rules('parent_id', 'required', 'numeric')->add_rules('category_title', 'required', 'length[3,80]')->add_rules('category_description', 'required')->add_rules('category_color', 'required', 'length[6,6]'); // When creating a new category if (empty($this->id)) { // Set locale to current language $this->locale = Kohana::config('locale.language.0'); } // Validation checks where parent_id > 0 if ($array->parent_id > 0) { $this_parent = self::factory('category')->find($array->parent_id); // If parent category is trusted/special if ($this_parent->category_trusted == 1) { Kohana::log('error', 'The parent id is a trusted category!'); $array->add_error('parent_id', 'parent_trusted'); } // When editing a category if (!empty($this->id)) { $this_cat = self::factory('category')->find($this->id); // If this category is trusted/special, don't subcategorize if ($this_cat->category_trusted) { Kohana::log('error', 'This is a special category'); $array->add_error('parent_id', 'special'); } // If parent category is trusted/special if ($this_parent->category_trusted == 1) { Kohana::log('error', 'The parent id is a trusted category!'); $array->add_error('parent_id', 'parent_trusted'); } // If subcategories exist $children = self::factory('category')->where('parent_id', $this->id)->count_all(); if ($children > 0) { Kohana::log('error', 'This category has subcategories'); $array->add_error('parent_id', 'already_parent'); } // If parent and category id are the same if ($this->id == $array->parent_id) { // Error Kohana::log('error', 'The parent id and category id are the same!'); $array->add_error('parent_id', 'same'); } } else { // Ensure parent_id exists in the DB $array->add_callbacks('parent_id', 'Category_Model::is_valid_category'); } } // Pass on validation to parent and return return parent::validate($array, $save); }
/** * Validate and save the data. * * @todo add a validation rule for valid date types. * @todo validate at least a location_name or sref required */ public function validate(Validation $array, $save = FALSE) { $orig_values = $array->as_array(); // uses PHP trim() to remove whitespace from beginning and end of all fields before validation $array->pre_filter('trim'); if ($this->id && preg_match('/[RDV]/', $this->record_status) && empty($this->submission['fields']['record_status']) && $this->wantToUpdateMetadata) { // If we update a processed occurrence but don't set the verification state, revert it to completed/awaiting verification. $array->verified_by_id = null; $array->verified_on = null; $array->record_status = 'C'; $this->requeuedForVerification = true; } // Any fields that don't have a validation rule need to be copied into the model manually $this->unvalidatedFields = array('date_end', 'location_name', 'survey_id', 'deleted', 'recorder_names', 'parent_id', 'comment', 'sample_method_id', 'input_form', 'external_key', 'group_id', 'privacy_precision', 'record_status', 'verified_by_id', 'verified_on'); $array->add_rules('survey_id', 'required'); // when deleting a sample, only need the id and the deleted flag, don't need the date or location details, but copy over if they are there. if (array_key_exists('deleted', $orig_values) && $orig_values['deleted'] == 't') { $this->unvalidatedFields = array_merge($this->unvalidatedFields, array('date_type', 'date_start', 'date_end', 'location_id', 'entered_sref', 'entered_sref_system', 'geom')); } else { $array->add_rules('date_type', 'required', 'length[1,2]'); $array->add_rules('date_start', 'date_in_past'); // We need either at least one of the location_id and sref/geom : in some cases may have both if (empty($orig_values['location_id'])) { // if a location is provided, we don't need an sref. // without a location_id, default to requires an sref. // no need to copy over location_id, as not present. $array->add_rules('entered_sref', "required"); $array->add_rules('entered_sref_system', 'required'); $array->add_rules('geom', 'required'); // even though our location_id is empty, still mark it as unvalidated so it gets copied over $this->unvalidatedFields[] = 'location_id'; if (array_key_exists('entered_sref_system', $orig_values) && $orig_values['entered_sref_system'] !== '') { $system = $orig_values['entered_sref_system']; $array->add_rules('entered_sref', "sref[{$system}]"); $array->add_rules('entered_sref_system', 'sref_system'); } } else { // got a location_id so may as well require it to make sure it gets copied across $array->add_rules('location_id', 'required'); // if any of the sref fields are also supplied, need all 3 fields if (!empty($orig_values['entered_sref']) || !empty($orig_values['entered_sref_system']) || !empty($orig_values['geom'])) { $this->add_sref_rules($array, 'entered_sref', 'entered_sref_system'); } else { // we are not requiring the fields so they must go in unvalidated fields, allowing them to get blanked out on edit $this->unvalidatedFields[] = 'entered_sref'; $this->unvalidatedFields[] = 'entered_sref_system'; } $this->unvalidatedFields[] = 'geom'; } } return parent::validate($array, $save); }