diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-09-12 15:57:05 +0200 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-09-12 15:57:05 +0200 |
commit | c3a0cf43430438bfe7e7b0ccccfadb72a74331d6 (patch) | |
tree | 048ab933b7048c93f1e30bc73ed2c0b90054696e /app/Model/Project.php | |
parent | 15e1ed6148632b7008875207f26345f472a909d1 (diff) |
Remove some code duplication (validation rules)
Diffstat (limited to 'app/Model/Project.php')
-rw-r--r-- | app/Model/Project.php | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/app/Model/Project.php b/app/Model/Project.php index 9aef3c7e..6e75838c 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -624,6 +624,23 @@ class Project extends Base } /** + * Common validation rules + * + * @access private + * @return array + */ + private function commonValidationRules() + { + return array( + new Validators\Integer('id', t('This value must be an integer')), + new Validators\Integer('is_active', t('This value must be an integer')), + new Validators\Required('name', t('The project name is required')), + new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50), + new Validators\Unique('name', t('This project must be unique'), $this->db->getConnection(), self::TABLE), + ); + } + + /** * Validate project creation * * @access public @@ -632,11 +649,7 @@ class Project extends Base */ public function validateCreation(array $values) { - $v = new Validator($values, array( - new Validators\Required('name', t('The project name is required')), - new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50), - new Validators\Unique('name', t('This project must be unique'), $this->db->getConnection(), self::TABLE) - )); + $v = new Validator($values, $this->commonValidationRules()); return array( $v->execute(), @@ -653,14 +666,11 @@ class Project extends Base */ public function validateModification(array $values) { - $v = new Validator($values, array( - new Validators\Required('id', t('The project id is required')), - new Validators\Integer('id', t('This value must be an integer')), - new Validators\Required('name', t('The project name is required')), - new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50), - new Validators\Unique('name', t('This project must be unique'), $this->db->getConnection(), self::TABLE), - new Validators\Integer('is_active', t('This value must be an integer')) - )); + $rules = array( + new Validators\Required('id', t('This value is required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), |