summaryrefslogtreecommitdiff
path: root/app/Model/TaskFilter.php
blob: b5a901548ee7ffad769cc08cc97cb7ddcfcbfd7f (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php

namespace Model;

/**
 * Task Filter
 *
 * @package  model
 * @author   Frederic Guillot
 */
class TaskFilter extends Base
{
    private $query;

    public function create()
    {
        $this->query = $this->db->table(Task::TABLE);
        return $this;
    }

    public function filterByProject($project_id)
    {
        if ($project_id > 0) {
            $this->query->eq('project_id', $project_id);
        }

        return $this;
    }

    public function filterByCategory($category_id)
    {
        if ($category_id >= 0) {
            $this->query->eq('category_id', $category_id);
        }

        return $this;
    }

    public function filterByOwner($owner_id)
    {
        if ($owner_id >= 0) {
            $this->query->eq('owner_id', $owner_id);
        }

        return $this;
    }

    public function filterByColor($color_id)
    {
        if ($color_id !== '') {
            $this->query->eq('color_id', $color_id);
        }

        return $this;
    }

    public function filterByColumn($column_id)
    {
        if ($column_id >= 0) {
            $this->query->eq('column_id', $column_id);
        }

        return $this;
    }

    public function filterBySwimlane($swimlane_id)
    {
        if ($swimlane_id >= 0) {
            $this->query->eq('swimlane_id', $swimlane_id);
        }

        return $this;
    }

    public function filterByStatus($is_active)
    {
        if ($is_active >= 0) {
            $this->query->eq('is_active', $is_active);
        }

        return $this;
    }

    public function filterByDueDateRange($start, $end)
    {
        $this->query->gte('date_due', $this->dateParser->getTimestampFromIsoFormat($start));
        $this->query->lte('date_due', $this->dateParser->getTimestampFromIsoFormat($end));

        return $this;
    }

    public function findAll()
    {
        return $this->query->findAll();
    }

    public function toCalendarEvents()
    {
        $events = array();

        foreach ($this->query->findAll() as $task) {
            $events[] = array(
                'timezoneParam' => $this->config->getCurrentTimezone(),
                'id' => $task['id'],
                'title' => t('#%d', $task['id']).' '.$task['title'],
                'start' => date('Y-m-d', $task['date_due']),
                'end' => date('Y-m-d', $task['date_due']),
                'allday' => true,
                'backgroundColor' => $this->color->getBackgroundColor($task['color_id']),
                'borderColor' => $this->color->getBorderColor($task['color_id']),
                'textColor' => 'black',
                'url' => $this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])),
            );
        }

        return $events;
    }
}