summaryrefslogtreecommitdiff
path: root/app/Filter/BaseDateRangeFilter.php
blob: fcff0d4cabb0f2e6a271a8fa9be2f6043b8b29db (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
49
50
51
52
53
54
<?php

namespace Kanboard\Filter;

use Kanboard\Core\DateParser;

/**
 * Base date filter class
 *
 * @package filter
 * @author  Kamil Ściana
 */
abstract class BaseDateRangeFilter extends BaseFilter
{
    /**
     * DateParser object
     *
     * @access protected
     * @var DateParser
     */
    protected $dateParser;

    /**
     * Set DateParser object
     *
     * @access public
     * @param  DateParser $dateParser
     * @return $this
     */
    public function setDateParser(DateParser $dateParser)
    {
        $this->dateParser = $dateParser;
        return $this;
    }

    /**
     * Apply a date filter
     *
     * @access protected
     * @param  string $field
     */
    protected function applyDateFilter($field)
    {
        $dates = explode('..', $this->value);

        if(count($dates)=== 2){
            $timestampFrom = $this->dateParser->getTimestamp($dates[0]." 00:00");
            $timestampTo = $this->dateParser->getTimestamp($dates[1]." 00:00");

            $this->query->gte($field, $timestampFrom);
            $this->query->lte($field, $timestampTo + 86399);
        }
    }
}