summaryrefslogtreecommitdiff
path: root/app/Controller/Calendar.php
blob: 2a11edab4929f7fbedf6f3082d98805504c120f0 (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
<?php

namespace Controller;

use Model\Task as TaskModel;

/**
 * Project Calendar controller
 *
 * @package  controller
 * @author   Frederic Guillot
 * @author   Timo Litzbarski
 */
class Calendar extends Base
{
    /**
     * Show calendar view for projects
     *
     * @access public
     */
    public function show()
    {
        $project = $this->getProject();

        $this->response->html($this->template->layout('calendar/show', array(
            'check_interval' => $this->config->get('board_private_refresh_interval'),
            'users_list' => $this->projectPermission->getMemberList($project['id'], true, true),
            'categories_list' => $this->category->getList($project['id'], true, true),
            'columns_list' => $this->board->getColumnsList($project['id'], true),
            'swimlanes_list' => $this->swimlane->getList($project['id'], true),
            'colors_list' => $this->color->getList(true),
            'status_list' => $this->taskStatus->getList(true),
            'project' => $project,
            'title' => t('Calendar for "%s"', $project['name']),
            'board_selector' => $this->projectPermission->getAllowedProjects($this->userSession->getId()),
        )));
    }

    /**
     * Get tasks to display on the calendar (project view)
     *
     * @access public
     */
    public function project()
    {
        $project_id = $this->request->getIntegerParam('project_id');
        $start = $this->request->getStringParam('start');
        $end = $this->request->getStringParam('end');

        $due_tasks = $this->taskFilter
            ->create()
            ->filterByProject($project_id)
            ->filterByCategory($this->request->getIntegerParam('category_id', -1))
            ->filterByOwner($this->request->getIntegerParam('owner_id', -1))
            ->filterByColumn($this->request->getIntegerParam('column_id', -1))
            ->filterBySwimlane($this->request->getIntegerParam('swimlane_id', -1))
            ->filterByColor($this->request->getStringParam('color_id'))
            ->filterByStatus($this->request->getIntegerParam('is_active', -1))
            ->filterByDueDateRange($start, $end)
            ->toCalendarEvents();

        $this->response->json($due_tasks);
    }

    /**
     * Get tasks to display on the calendar (user view)
     *
     * @access public
     */
    public function user()
    {
        $user_id = $this->request->getIntegerParam('user_id');
        $start = $this->request->getStringParam('start');
        $end = $this->request->getStringParam('end');

        $due_tasks = $this->taskFilter
                          ->create()
                          ->filterByOwner($user_id)
                          ->filterByStatus(TaskModel::STATUS_OPEN)
                          ->filterByDueDateRange($start, $end)
                          ->toCalendarEvents();

        $subtask_timeslots = $this->subtaskTimeTracking->getUserCalendarEvents($user_id, $start, $end);

        $this->response->json(array_merge($due_tasks, $subtask_timeslots));
    }

    /**
     * Update task due date
     *
     * @access public
     */
    public function save()
    {
        if ($this->request->isAjax() && $this->request->isPost()) {

            $values = $this->request->getJson();

            $this->taskModification->update(array(
                'id' => $values['task_id'],
                'date_due' => $values['date_due'],
            ));
        }
    }
}