summaryrefslogtreecommitdiff
path: root/app/Validator
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-06-24 22:10:14 -0400
committerFrederic Guillot <fred@kanboard.net>2016-06-24 22:10:14 -0400
commitce367a24fca09bb1fa05da167f36db54712c8fa1 (patch)
tree204814ef3e71256ef77716d7f233ff194772c5a0 /app/Validator
parentcead21691e449707e17dba4ef0be3f8ce0ee42f5 (diff)
Added tag modification from the user interface
Diffstat (limited to 'app/Validator')
-rw-r--r--app/Validator/TagValidator.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/app/Validator/TagValidator.php b/app/Validator/TagValidator.php
new file mode 100644
index 00000000..32622583
--- /dev/null
+++ b/app/Validator/TagValidator.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace Kanboard\Validator;
+
+use Kanboard\Model\TagModel;
+use SimpleValidator\Validator;
+use SimpleValidator\Validators;
+
+/**
+ * Tag Validator
+ *
+ * @package Kanboard\Validator
+ * @author Frederic Guillot
+ */
+class TagValidator extends BaseValidator
+{
+ /**
+ * 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());
+ $result = $v->execute();
+ $errors = $v->getErrors();
+
+ if ($result && $this->tagModel->exists($values['project_id'], $values['name'])) {
+ $result = false;
+ $errors = array('name' => array(t('The name must be unique')));
+ }
+
+ return array($result, $errors);
+ }
+
+ /**
+ * 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('Field required')),
+ );
+
+ $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
+ $result = $v->execute();
+ $errors = $v->getErrors();
+
+ if ($result && $this->tagModel->exists($values['project_id'], $values['name'], $values['id'])) {
+ $result = false;
+ $errors = array('name' => array(t('The name must be unique')));
+ }
+
+ return array($result, $errors);
+ }
+
+ /**
+ * Common validation rules
+ *
+ * @access protected
+ * @return array
+ */
+ protected function commonValidationRules()
+ {
+ return array(
+ new Validators\Required('project_id', t('Field required')),
+ new Validators\Required('name', t('Field required')),
+ new Validators\MaxLength('name', t('The maximum length is %d characters', 255), 255),
+ );
+ }
+}