diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Controller/Tasklink.php | 4 | ||||
-rw-r--r-- | app/Core/Base.php | 4 | ||||
-rw-r--r-- | app/Model/TaskLink.php | 57 | ||||
-rw-r--r-- | app/Model/User.php | 3 | ||||
-rw-r--r-- | app/ServiceProvider/ClassProvider.php | 1 | ||||
-rw-r--r-- | app/Validator/TaskLinkValidator.php | 71 |
6 files changed, 77 insertions, 63 deletions
diff --git a/app/Controller/Tasklink.php b/app/Controller/Tasklink.php index 068bf16d..a81d3ee5 100644 --- a/app/Controller/Tasklink.php +++ b/app/Controller/Tasklink.php @@ -69,7 +69,7 @@ class Tasklink extends Base $values = $this->request->getValues(); $ajax = $this->request->isAjax() || $this->request->getIntegerParam('ajax'); - list($valid, $errors) = $this->taskLink->validateCreation($values); + list($valid, $errors) = $this->taskLinkValidator->validateCreation($values); if ($valid) { if ($this->taskLink->create($values['task_id'], $values['opposite_task_id'], $values['link_id'])) { @@ -125,7 +125,7 @@ class Tasklink extends Base $task = $this->getTask(); $values = $this->request->getValues(); - list($valid, $errors) = $this->taskLink->validateModification($values); + list($valid, $errors) = $this->taskLinkValidator->validateModification($values); if ($valid) { if ($this->taskLink->update($values['id'], $values['task_id'], $values['opposite_task_id'], $values['link_id'])) { diff --git a/app/Core/Base.php b/app/Core/Base.php index f32c1442..5a726ffa 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -100,7 +100,6 @@ use Pimple\Container; * @property \Kanboard\Model\TaskPermission $taskPermission * @property \Kanboard\Model\TaskPosition $taskPosition * @property \Kanboard\Model\TaskStatus $taskStatus - * @property \Kanboard\Model\TaskValidator $taskValidator * @property \Kanboard\Model\TaskMetadata $taskMetadata * @property \Kanboard\Model\Transition $transition * @property \Kanboard\Model\User $user @@ -114,6 +113,9 @@ use Pimple\Container; * @property \Kanboard\Model\UserMetadata $userMetadata * @property \Kanboard\Model\Webhook $webhook * @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator + * @property \Kanboard\Validator\TaskLinkValidator $taskLinkValidator + * @property \Kanboard\Validator\TaskValidator $taskValidator + * @property \Kanboard\Validator\UserValidator $userValidator * @property \Psr\Log\LoggerInterface $logger * @property \PicoDb\Database $db * @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher diff --git a/app/Model/TaskLink.php b/app/Model/TaskLink.php index 1ac59203..87aae55e 100644 --- a/app/Model/TaskLink.php +++ b/app/Model/TaskLink.php @@ -2,8 +2,6 @@ namespace Kanboard\Model; -use SimpleValidator\Validator; -use SimpleValidator\Validators; use Kanboard\Event\TaskLinkEvent; /** @@ -261,59 +259,4 @@ class TaskLink extends Base return true; } - - /** - * Common validation rules - * - * @access private - * @return array - */ - private function commonValidationRules() - { - return array( - new Validators\Required('task_id', t('Field required')), - new Validators\Required('opposite_task_id', t('Field required')), - new Validators\Required('link_id', t('Field required')), - new Validators\NotEquals('opposite_task_id', 'task_id', t('A task cannot be linked to itself')), - new Validators\Exists('opposite_task_id', t('This linked task id doesn\'t exists'), $this->db->getConnection(), Task::TABLE, 'id') - ); - } - - /** - * 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('Field required')), - ); - - $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); - - return array( - $v->execute(), - $v->getErrors() - ); - } } diff --git a/app/Model/User.php b/app/Model/User.php index 84785ce5..ac0e7491 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -3,9 +3,6 @@ namespace Kanboard\Model; use PicoDb\Database; -use SimpleValidator\Validator; -use SimpleValidator\Validators; -use Kanboard\Core\Session\SessionManager; use Kanboard\Core\Security\Token; use Kanboard\Core\Security\Role; diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 44dba45b..80017bb0 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -87,6 +87,7 @@ class ClassProvider implements ServiceProviderInterface 'Validator' => array( 'PasswordResetValidator', 'TaskValidator', + 'TaskLinkValidator', 'UserValidator', ), 'Core' => array( diff --git a/app/Validator/TaskLinkValidator.php b/app/Validator/TaskLinkValidator.php new file mode 100644 index 00000000..021eb0b6 --- /dev/null +++ b/app/Validator/TaskLinkValidator.php @@ -0,0 +1,71 @@ +<?php + +namespace Kanboard\Validator; + +use SimpleValidator\Validator; +use SimpleValidator\Validators; +use Kanboard\Model\Task; + +/** + * TaskLink Validator + * + * @package validator + * @author Frederic Guillot + */ +class TaskLinkValidator extends Base +{ + /** + * Common validation rules + * + * @access private + * @return array + */ + private function commonValidationRules() + { + return array( + new Validators\Required('task_id', t('Field required')), + new Validators\Required('opposite_task_id', t('Field required')), + new Validators\Required('link_id', t('Field required')), + new Validators\NotEquals('opposite_task_id', 'task_id', t('A task cannot be linked to itself')), + new Validators\Exists('opposite_task_id', t('This linked task id doesn\'t exists'), $this->db->getConnection(), Task::TABLE, 'id') + ); + } + + /** + * 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('Field required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); + + return array( + $v->execute(), + $v->getErrors() + ); + } +} |