diff options
author | emkael <emkael@tlen.pl> | 2020-05-05 14:25:42 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2020-05-05 14:25:42 +0200 |
commit | 62827e6cf470449c117624058fb36ad94804bcc0 (patch) | |
tree | 10cd1e4d36c34b694acfadaa69fc7f6ae2b1eabd /plugins/Timetrackingeditor/Validator/SubtaskTimeTrackingValidator.php | |
parent | 7b66ddf2e4fbdb837e78d8b7dbaa9fc38391bc32 (diff) |
Diffstat (limited to 'plugins/Timetrackingeditor/Validator/SubtaskTimeTrackingValidator.php')
-rw-r--r-- | plugins/Timetrackingeditor/Validator/SubtaskTimeTrackingValidator.php | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/plugins/Timetrackingeditor/Validator/SubtaskTimeTrackingValidator.php b/plugins/Timetrackingeditor/Validator/SubtaskTimeTrackingValidator.php new file mode 100644 index 00000000..6bddc47a --- /dev/null +++ b/plugins/Timetrackingeditor/Validator/SubtaskTimeTrackingValidator.php @@ -0,0 +1,73 @@ +<?php + +namespace Kanboard\Plugin\Timetrackingeditor\Validator; + +use SimpleValidator\Validator; +use SimpleValidator\Validators; +use Kanboard\Validator\BaseValidator; + +/** + * SubtaskTimetracking Validator + * + * @package Kanboard\Plugin\Timetrackingeditor\Validator + * @author Thomas Stinner + */ +class SubtaskTimeTrackingValidator 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) + { + $rules = array (); + + + $v = new Validator($values, array_merge($rules, $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 Timetracking id is required')) + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + /** + * Common validation rules, valid for creation and modification + * + * @access private + */ + private function commonValidationRules() + { + $rules = array( + new Validators\Required('task_id', t('The Task id is required')), + new Validators\Required('opposite_subtask_id', t('The subtask is required')), + new Validators\Required('start', t('The Start Date is required')), + new Validators\Required('time_spent', t('The Time spent is required')), + ); + return $rules; + } +} |