diff options
Diffstat (limited to 'app/Validator')
-rw-r--r-- | app/Validator/AuthValidator.php | 2 | ||||
-rw-r--r-- | app/Validator/ColumnValidator.php | 35 | ||||
-rw-r--r-- | app/Validator/ExternalLinkValidator.php | 76 | ||||
-rw-r--r-- | app/Validator/TaskValidator.php | 4 | ||||
-rw-r--r-- | app/Validator/UserValidator.php | 4 |
5 files changed, 107 insertions, 14 deletions
diff --git a/app/Validator/AuthValidator.php b/app/Validator/AuthValidator.php index 36ccdff0..cd6e04d5 100644 --- a/app/Validator/AuthValidator.php +++ b/app/Validator/AuthValidator.php @@ -114,6 +114,6 @@ class AuthValidator extends Base } } - return array($result, $errors);; + return array($result, $errors); } } diff --git a/app/Validator/ColumnValidator.php b/app/Validator/ColumnValidator.php index 4c644e8a..f0f1659b 100644 --- a/app/Validator/ColumnValidator.php +++ b/app/Validator/ColumnValidator.php @@ -22,11 +22,12 @@ class ColumnValidator extends Base */ public function validateModification(array $values) { - $v = new Validator($values, array( - new Validators\Integer('task_limit', t('This value must be an integer')), - new Validators\Required('title', t('The title is required')), - new Validators\MaxLength('title', t('The maximum length is %d characters', 50), 50), - )); + $rules = array( + new Validators\Required('id', t('This value is required')), + new Validators\Integer('id', t('This value must be an integer')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), @@ -43,16 +44,32 @@ class ColumnValidator extends Base */ public function validateCreation(array $values) { - $v = new Validator($values, array( + $rules = array( new Validators\Required('project_id', t('The project id is required')), new Validators\Integer('project_id', t('This value must be an integer')), - new Validators\Required('title', t('The title is required')), - new Validators\MaxLength('title', t('The maximum length is %d characters', 50), 50), - )); + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), $v->getErrors() ); } + + /** + * Common validation rules + * + * @access private + * @return array + */ + private function commonValidationRules() + { + return array( + new Validators\Integer('task_limit', t('This value must be an integer')), + new Validators\GreaterThan('task_limit', t('This value must be greater than %d', -1), -1), + new Validators\Required('title', t('The title is required')), + new Validators\MaxLength('title', t('The maximum length is %d characters', 50), 50), + ); + } } diff --git a/app/Validator/ExternalLinkValidator.php b/app/Validator/ExternalLinkValidator.php new file mode 100644 index 00000000..fff4133b --- /dev/null +++ b/app/Validator/ExternalLinkValidator.php @@ -0,0 +1,76 @@ +<?php + +namespace Kanboard\Validator; + +use SimpleValidator\Validator; +use SimpleValidator\Validators; + +/** + * External Link Validator + * + * @package validator + * @author Frederic Guillot + */ +class ExternalLinkValidator extends Base +{ + /** + * Validate 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) + { + $v = new Validator($values, $this->commonValidationRules()); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + /** + * Validate modification + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateModification(array $values) + { + $rules = array( + new Validators\Required('id', t('The id is required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + /** + * Common validation rules + * + * @access private + * @return array + */ + private function commonValidationRules() + { + return array( + new Validators\Required('url', t('Field required')), + new Validators\MaxLength('url', t('The maximum length is %d characters', 255), 255), + new Validators\Required('title', t('Field required')), + new Validators\MaxLength('title', t('The maximum length is %d characters', 255), 255), + new Validators\Required('link_type', t('Field required')), + new Validators\MaxLength('link_type', t('The maximum length is %d characters', 100), 100), + new Validators\Required('dependency', t('Field required')), + new Validators\MaxLength('dependency', t('The maximum length is %d characters', 100), 100), + new Validators\Integer('id', t('This value must be an integer')), + new Validators\Required('task_id', t('Field required')), + new Validators\Integer('task_id', t('This value must be an integer')), + ); + } +} diff --git a/app/Validator/TaskValidator.php b/app/Validator/TaskValidator.php index 7b73aeba..1a77dd32 100644 --- a/app/Validator/TaskValidator.php +++ b/app/Validator/TaskValidator.php @@ -40,8 +40,8 @@ class TaskValidator extends Base new Validators\Integer('priority', t('This value must be an integer')), new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200), new Validators\MaxLength('reference', t('The maximum length is %d characters', 50), 50), - new Validators\Date('date_due', t('Invalid date'), $this->dateParser->getDateFormats()), - new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getAllFormats()), + new Validators\Date('date_due', t('Invalid date'), $this->dateParser->getDateFormats(true)), + new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getDateTimeFormats(true)), new Validators\Numeric('time_spent', t('This value must be numeric')), new Validators\Numeric('time_estimated', t('This value must be numeric')), ); diff --git a/app/Validator/UserValidator.php b/app/Validator/UserValidator.php index d85d335f..e5953f30 100644 --- a/app/Validator/UserValidator.php +++ b/app/Validator/UserValidator.php @@ -17,10 +17,10 @@ class UserValidator extends Base /** * Common validation rules * - * @access private + * @access protected * @return array */ - private function commonValidationRules() + protected function commonValidationRules() { return array( new Validators\MaxLength('role', t('The maximum length is %d characters', 25), 25), |