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

namespace Kanboard\Controller;

use Kanboard\Filter\TaskAssigneeFilter;
use Kanboard\Filter\TaskProjectFilter;
use Kanboard\Filter\TaskStatusFilter;
use Kanboard\Model\TaskModel;

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

        $this->response->html($this->helper->layout->app('calendar/show', array(
            'project' => $project,
            'title' => $project['name'],
            'description' => $this->helper->projectHeader->getDescription($project),
            'check_interval' => $this->configModel->get('board_private_refresh_interval'),
        )));
    }

    /**
     * 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');
        $search = $this->userSession->getFilters($project_id);
        $queryBuilder = $this->taskLexer->build($search)->withFilter(new TaskProjectFilter($project_id));

        $events = $this->helper->calendar->getTaskDateDueEvents(clone($queryBuilder), $start, $end);
        $events = array_merge($events, $this->helper->calendar->getTaskEvents(clone($queryBuilder), $start, $end));

        $events = $this->hook->merge('controller:calendar:project:events', $events, array(
            'project_id' => $project_id,
            'start' => $start,
            'end' => $end,
        ));

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

    /**
     * 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');
        $queryBuilder = $this->taskQuery
            ->withFilter(new TaskAssigneeFilter($user_id))
            ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN));

        $events = $this->helper->calendar->getTaskDateDueEvents(clone($queryBuilder), $start, $end);
        $events = array_merge($events, $this->helper->calendar->getTaskEvents(clone($queryBuilder), $start, $end));

        if ($this->configModel->get('calendar_user_subtasks_time_tracking') == 1) {
            $events = array_merge($events, $this->helper->calendar->getSubtaskTimeTrackingEvents($user_id, $start, $end));
        }

        $events = $this->hook->merge('controller:calendar:user:events', $events, array(
            'user_id' => $user_id,
            'start' => $start,
            'end' => $end,
        ));

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

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

            $this->taskModificationModel->update(array(
                'id' => $values['task_id'],
                'date_due' => substr($values['date_due'], 0, 10),
            ));
        }
    }
}