summaryrefslogtreecommitdiff
path: root/plugins/TaskIntervalButton/Controller/TaskIntervalController.php
blob: 27b9395d224f4ed312ac7d7790db75495fcefaab (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
<?php

namespace Kanboard\Plugin\TaskIntervalButton\Controller;

use Kanboard\Controller\BaseController;
use Kanboard\Core\Controller\AccessForbiddenException;

class TaskIntervalController extends BaseController
{
    public function confirm()
    {
        $task = $this->getTask();
        $user = $this->getUser();

        if ($user['username'] !== $task["assignee_username"]) {
            throw new AccessForbiddenException();
        }

        $this->response->html($this->template->render('TaskIntervalButton:task_add_interval/add_interval_confirm', array(
            'task' => $task,
            'user' => $user
        )));
    }

    public function addInterval()
    {
        $task = $this->getTask();
        $user = $this->getUser();
        $this->checkCSRFParam();

        if ($user['username'] !== $task["assignee_username"]) {
            throw new AccessForbiddenException();
        }

        $values = array('id' => $task['id'], 'time_spent' => $task['time_spent'] + 0.5);

        if ($this->taskModificationModel->update($values, false)) {
            $this->flash->success(t("Interval added."));
        } else {
            $this->flash->failure(t("Unable to add interval."));
        }

        return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true);
    }
}