diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-01-17 17:11:51 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-01-17 17:11:51 -0500 |
commit | 84b0f0df90442775b9122457648f06c9485df1f1 (patch) | |
tree | 5f0fb91ed9280bbf10bb60d69f3523cafc928f5c /app/Model/TaskFilter.php | |
parent | 4b45b2aa3533309898670f1b13756dfdfce355a7 (diff) |
Add project calendars (merge/refactoring of #490)
Diffstat (limited to 'app/Model/TaskFilter.php')
-rw-r--r-- | app/Model/TaskFilter.php | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php new file mode 100644 index 00000000..eac90aab --- /dev/null +++ b/app/Model/TaskFilter.php @@ -0,0 +1,117 @@ +<?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( + '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; + } +} |