summaryrefslogtreecommitdiff
path: root/plugins/TimeMachine/Validator/SubTaskTimeTrackingValidator.php
blob: 28421b6629a7663eda608ad8c652bda7606032eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

namespace Kanboard\Plugin\TimeMachine\Validator;

use Kanboard\Validator\BaseValidator;
use SimpleValidator\Validator;
use SimpleValidator\Validators;

/**
 * SubTask Time Tracking Validator
 *
 * @package  Kanboard\Validator
 * @author   Frederic Guillot
 */
class SubTaskTimeTrackingValidator extends BaseValidator
{

    /**
     * Validate SubTackTimeTracking from form
     *
     * @param  array   $values           Form values
     *
     * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
     */
    public function validates(array $values)
    {
        $valids = [];
        $errors = [];

        foreach ($values as $key => $value) {
            $rules = array(
                new Validators\Required('id', t('The task time tracking id is required')),
                new Validators\Date('start', t('Invalid date'), $this->dateParser->getParserFormats()),
                new Validators\Date('end', t('Invalid date'), $this->dateParser->getParserFormats()),
            );

            $v = new Validator($value, $rules);

            $valids[$key] = $v->execute();
            $errors[$key] = $v->getErrors();
        }

        return array(
            $valids,
            $errors
        );
    }
}