From 3699073371acc66ccacb56a89e87147a9c90d8c4 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 11 Jan 2016 22:07:39 -0500 Subject: Move project validator methods --- app/Validator/ProjectValidator.php | 83 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 app/Validator/ProjectValidator.php (limited to 'app/Validator') diff --git a/app/Validator/ProjectValidator.php b/app/Validator/ProjectValidator.php new file mode 100644 index 00000000..53cb7a37 --- /dev/null +++ b/app/Validator/ProjectValidator.php @@ -0,0 +1,83 @@ +db->getConnection(), Project::TABLE), + ); + } + + /** + * Validate project 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) + { + if (! empty($values['identifier'])) { + $values['identifier'] = strtoupper($values['identifier']); + } + + $v = new Validator($values, $this->commonValidationRules()); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + /** + * Validate project 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) + { + if (! empty($values['identifier'])) { + $values['identifier'] = strtoupper($values['identifier']); + } + + $rules = array( + new Validators\Required('id', t('This value is required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); + + return array( + $v->execute(), + $v->getErrors() + ); + } +} -- cgit v1.2.3