diff options
Diffstat (limited to 'app/Model/Task.php')
-rw-r--r-- | app/Model/Task.php | 81 |
1 files changed, 46 insertions, 35 deletions
diff --git a/app/Model/Task.php b/app/Model/Task.php index 7245417a..6f62c3d2 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -675,25 +675,41 @@ class Task extends Base } /** - * Validate task creation + * Common validation rules * - * @access public - * @param array $values Form values - * @return array $valid, $errors [0] = Success or not, [1] = List of errors + * @access private + * @return array */ - public function validateCreation(array $values) + private function commonValidationRules() { - $v = new Validator($values, array( - new Validators\Required('project_id', t('The project is required')), + return array( + new Validators\Integer('id', t('This value must be an integer')), new Validators\Integer('project_id', t('This value must be an integer')), new Validators\Integer('column_id', t('This value must be an integer')), new Validators\Integer('owner_id', t('This value must be an integer')), new Validators\Integer('creator_id', t('This value must be an integer')), new Validators\Integer('score', t('This value must be an integer')), - new Validators\Required('title', t('The title is required')), + new Validators\Integer('category_id', t('This value must be an integer')), new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200), new Validators\Date('date_due', t('Invalid date'), $this->getDateFormats()), - )); + ); + } + + /** + * Validate task creation + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateCreation(array $values) + { + $rules = array( + new Validators\Required('project_id', t('The project is required')), + new Validators\Required('title', t('The title is required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), @@ -710,11 +726,12 @@ class Task extends Base */ public function validateDescriptionCreation(array $values) { - $v = new Validator($values, array( + $rules = array( new Validators\Required('id', t('The id is required')), - new Validators\Integer('id', t('This value must be an integer')), new Validators\Required('description', t('The description is required')), - )); + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), @@ -731,16 +748,11 @@ class Task extends Base */ public function validateModification(array $values) { - $v = new Validator($values, array( + $rules = array( new Validators\Required('id', t('The id is required')), - new Validators\Integer('id', t('This value must be an integer')), - new Validators\Integer('project_id', t('This value must be an integer')), - new Validators\Integer('column_id', t('This value must be an integer')), - new Validators\Integer('owner_id', t('This value must be an integer')), - new Validators\Integer('score', t('This value must be an integer')), - new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200), - new Validators\Date('date_due', t('Invalid date'), $this->getDateFormats()), - )); + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), @@ -757,14 +769,13 @@ class Task extends Base */ public function validateAssigneeModification(array $values) { - $v = new Validator($values, array( + $rules = array( new Validators\Required('id', t('The id is required')), - new Validators\Integer('id', t('This value must be an integer')), new Validators\Required('project_id', t('The project is required')), - new Validators\Integer('project_id', t('This value must be an integer')), new Validators\Required('owner_id', t('This value is required')), - new Validators\Integer('owner_id', t('This value must be an integer')), - )); + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), @@ -781,14 +792,14 @@ class Task extends Base */ public function validateCategoryModification(array $values) { - $v = new Validator($values, array( + $rules = array( new Validators\Required('id', t('The id is required')), - new Validators\Integer('id', t('This value must be an integer')), new Validators\Required('project_id', t('The project is required')), - new Validators\Integer('project_id', t('This value must be an integer')), new Validators\Required('category_id', t('This value is required')), - new Validators\Integer('category_id', t('This value must be an integer')), - )); + + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), @@ -805,12 +816,12 @@ class Task extends Base */ public function validateProjectModification(array $values) { - $v = new Validator($values, array( + $rules = array( new Validators\Required('id', t('The id is required')), - new Validators\Integer('id', t('This value must be an integer')), new Validators\Required('project_id', t('The project is required')), - new Validators\Integer('project_id', t('This value must be an integer')), - )); + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), |