summaryrefslogtreecommitdiff
path: root/plugins/Timetrackingeditor/Controller/SubtaskStatusController.php
blob: c27881a166c015ae225fd46ce16158db3421bed4 (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
<?php

namespace Kanboard\Plugin\Timetrackingeditor\Controller;

use Kanboard\Model\SubtaskModel;

/**
 * SubtaskStatusController.
 *
 * @author Thomas Stinner
 */
class SubtaskStatusController extends \Kanboard\Controller\SubtaskStatusController
{
    /**
     * Change status to the next status: Toto -> In Progress -> Done.
     */
    public function change()
    {
        $task = $this->getTask();
        $subtask = $this->getSubtask();

        if ($subtask['status'] == SubtaskModel::STATUS_DONE) {
            $status = SubtaskModel::STATUS_TODO;
        } else {
            $status = SubtaskModel::STATUS_DONE;
        }
        $subtask['status'] = $status;
        $this->subtaskModel->update($subtask);

        if ($this->request->getIntegerParam('refresh-table') === 0) {

            $html = $this->helper->subtask->toggleStatus($subtask, $task['project_id']);
        } else {
            $html = $this->renderTable($task);
        }

        $this->response->html($html);
    }

    protected function renderTable(array $task)
    {
        return $this->template->render('subtask/table', array(
                'task' => $task,
                'subtasks' => $this->subtaskModel->getAll($task['id']),
                'editable' => true,
            ));
    }
}
?>