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

namespace Kanboard\Controller;

use Kanboard\Model\UserMetadataModel;

/**
 * Class CommentListController
 *
 * @package Kanboard\Controller
 * @author  Frederic Guillot
 */
class CommentListController extends BaseController
{
    public function show()
    {
        $project = $this->getProject();
        $task = $this->getTask();
        $commentSortingDirection = $this->userMetadataCacheDecorator->get(UserMetadataModel::KEY_COMMENT_SORTING_DIRECTION, 'ASC');

        $compactView = $this->request->getIntegerParam('compact', 0);

        $this->response->html($this->template->render('comment_list/show', array(
            'project'  => $project,
            'task'     => $task,
            'comments' => $this->commentModel->getAll($task['id'], $commentSortingDirection),
            'editable' => $this->helper->user->hasProjectAccess('CommentController', 'edit', $task['project_id']),
            'compact'  => (bool)$compactView,
        )));
    }

    public function save()
    {
        $task = $this->getTask();
        $values = $this->request->getValues();
        $values['task_id'] = $task['id'];
        $values['user_id'] = $this->userSession->getId();

        list($valid, ) = $this->commentValidator->validateCreation($values);

        if ($valid && $this->commentModel->create($values) !== false) {
            $this->flash->success(t('Comment added successfully.'));
        }

        $this->show();
    }

    public function toggleSorting()
    {
        $this->helper->comment->toggleSorting();
        $this->show();
    }
}