/** * Specify our rules here so that we have access to the instance of this model. */ public function validate(Validation $array = null) { if (!$array) { $this->rules = array("album_cover_item_id" => array("callbacks" => array(array($this, "valid_album_cover"))), "description" => array("rules" => array("length[0,65535]")), "mime_type" => array("callbacks" => array(array($this, "valid_field"))), "name" => array("rules" => array("length[0,255]", "required"), "callbacks" => array(array($this, "valid_name"))), "parent_id" => array("callbacks" => array(array($this, "valid_parent"))), "rand_key" => array("rule" => array("decimal")), "slug" => array("rules" => array("length[0,255]", "required"), "callbacks" => array(array($this, "valid_slug"))), "sort_column" => array("callbacks" => array(array($this, "valid_field"))), "sort_order" => array("callbacks" => array(array($this, "valid_field"))), "title" => array("rules" => array("length[0,255]", "required")), "type" => array("callbacks" => array(array($this, "read_only"), array($this, "valid_field")))); // Conditional rules if ($this->id == 1) { // We don't care about the name and slug for the root album. $this->rules["name"] = array(); $this->rules["slug"] = array(); } // Movies and photos must have data files. Verify the data file on new items, or if it has // been replaced. if (($this->is_photo() || $this->is_movie()) && $this->data_file) { $this->rules["name"]["callbacks"][] = array($this, "valid_data_file"); } } parent::validate($array); }
/** * Specify our rules here so that we have access to the instance of this model. */ public function validate($array = null) { if (!$array) { $this->rules = array("album_cover_item_id" => array("callbacks" => array(array($this, "valid_album_cover"))), "description" => array("rules" => array("length[0,65535]")), "mime_type" => array("callbacks" => array(array($this, "valid_field"))), "name" => array("rules" => array("length[0,255]", "required"), "callbacks" => array(array($this, "valid_name"))), "parent_id" => array("callbacks" => array(array($this, "valid_parent"))), "rand_key" => array("rule" => array("decimal")), "slug" => array("rules" => array("length[0,255]", "required"), "callbacks" => array(array($this, "valid_slug"))), "sort_column" => array("callbacks" => array(array($this, "valid_field"))), "sort_order" => array("callbacks" => array(array($this, "valid_field"))), "title" => array("rules" => array("length[0,255]", "required")), "type" => array("callbacks" => array(array($this, "read_only"), array($this, "valid_field")))); // Conditional rules if ($this->id == 1) { // Root album can't have a name or slug so replace the rules $this->rules["name"] = array("rules" => array("length[0]")); $this->rules["slug"] = array("rules" => array("length[0]")); } // Movies and photos must have data files if (($this->is_photo() || $this->is_movie()) && !$this->loaded()) { $this->rules["name"]["callbacks"][] = array($this, "valid_data_file"); } } parent::validate($array); }