public function unique_key($id = NULL) { if (!empty($id) && is_string($id) && !ctype_digit($id)) { return 'url_identifier'; } return parent::unique_key($id); }
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); }
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); }
/** * 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); }
/** * 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); }
/** * Extend the default ORM delete to remove related records */ public function delete() { $table_prefix = Kohana::config('database.default.table_prefix'); // Delete category_lang entries ORM::factory('category_lang')->where('category_id', $this->id)->delete_all(); // Update subcategories tied to this category and make them top level $this->db->query('UPDATE `' . $table_prefix . 'category` SET parent_id = 0 WHERE parent_id = :category_id', array(':category_id' => $this->id)); // Unapprove all reports tied to this category only (not to multiple categories) $this->db->query('UPDATE `' . $table_prefix . 'incident` SET incident_active = 0 WHERE id IN (SELECT incident_id FROM `' . $table_prefix . 'incident_category` WHERE category_id = :category_id) AND id NOT IN (SELECT DISTINCT incident_id FROM `' . $table_prefix . 'incident_category` WHERE category_id != :category_id) ', array(':category_id' => $this->id)); // Delete all incident_category entries $result = ORM::factory('incident_category')->where('category_id', $this->id)->delete_all(); // @todo Delete the category image parent::delete(); }
/** * Gets the list of custom attributes for this model. * @param boolean $required Optional. Set to true to only return required attributes (requires * the website and survey identifier to be set). * @param int @typeFilter Specify a location type meaning id or a sample method meaning id to * filter the returned attributes to those which apply to the given type or method. * @param boolean @hasSurveyRestriction true if this objects attributes can be restricted to * survey scope. */ protected function getAttributes($required = false, $typeFilter = null, $hasSurveyRestriction = true) { return parent::getAttributes($required, $typeFilter, false); }
/** * Handle the case where a new record is created with a centroid_sref but without the geom being pre-calculated. * E.g. when importing from a shape file, or when JS is disabled on the client. */ protected function preSubmit() { // Allow a location to be submitted with a spatial ref and system but no centroid_geom. If so we // can work out the Geom if (!empty($this->submission['fields']['centroid_sref']['value']) && !empty($this->submission['fields']['centroid_sref_system']['value']) && empty($this->submission['fields']['centroid_geom']['value'])) { try { $this->submission['fields']['centroid_geom']['value'] = spatial_ref::sref_to_internal_wkt($this->submission['fields']['centroid_sref']['value'], $this->submission['fields']['centroid_sref_system']['value']); } catch (Exception $e) { $this->errors['centroid_sref'] = $e->getMessage(); } } elseif (empty($this->submission['fields']['centroid_sref']['value']) && empty($this->submission['fields']['centroid_geom']['value']) && !empty($this->submission['fields']['boundary_geom']['value'])) { kohana::log('debug', 'working out centroid from boundary'); // if the geom is supplied for the boundary, but not the centroid sref, then calculate it. // First, convert the boundary geom to a centroid using any provided system, else use LatLong (EPSG:4326) $boundary = $this->submission['fields']['boundary_geom']['value']; if (!empty($this->submission['fields']['centroid_sref_system']['value'])) { $centroid = $this->calcCentroid($boundary, $this->submission['fields']['centroid_sref_system']['value']); } else { $centroid = $this->calcCentroid($boundary); } $this->submission['fields']['centroid_geom']['value'] = $centroid['wkt']; $this->submission['fields']['centroid_sref']['value'] = $centroid['sref']; $this->submission['fields']['centroid_sref_system']['value'] = $centroid['sref_system']; } // Empty boundary geom is allowed but must be null if (isset($this->submission['fields']['boundary_geom']['value']) && empty($this->submission['fields']['boundary_geom']['value'])) { $this->submission['fields']['boundary_geom']['value'] = null; } return parent::presubmit(); }
public function __construct($id = null) { parent::__construct($id); }
/** * Override get handler to translate PostGIS internal spatial data to WKT. */ public function __get($column) { $value = parent::__get($column); if (substr($column, -4) == 'geom' && $value !== null) { $row = $this->db->query("SELECT ST_asText('{$value}') AS wkt")->current(); $value = $row->wkt; } return $value; }
/** * Extend the default ORM save to also update matching Category_Lang record if it exits */ public function save() { parent::save(); $table_prefix = Kohana::config('database.default.table_prefix'); Database::instance()->query('UPDATE `' . $table_prefix . 'category_lang` SET category_title = ?, category_description = ? WHERE category_id = ? AND locale = ?', $this->category_title, $this->category_description, $this->id, $this->locale); }
/** * Return the submission structure, which includes defining the occurrences table * is a sub-model. * * @return array Submission structure for a subject_observation entry. */ public function get_submission_structure() { $r = parent::get_submission_structure(); $r['joinsTo'] = array('occurrences'); return $r; }
/** * 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) { $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); }