summaryrefslogtreecommitdiff
path: root/app/Api/CommentApi.php
blob: f16b0f7fc93d71d9943c32807231afc3b3536711 (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
<?php

namespace Kanboard\Api;

use Kanboard\Core\Base;

/**
 * Comment API controller
 *
 * @package  Kanboard\Api
 * @author   Frederic Guillot
 */
class CommentApi extends Base
{
    public function getComment($comment_id)
    {
        return $this->comment->getById($comment_id);
    }

    public function getAllComments($task_id)
    {
        return $this->comment->getAll($task_id);
    }

    public function removeComment($comment_id)
    {
        return $this->comment->remove($comment_id);
    }

    public function createComment($task_id, $user_id, $content, $reference = '')
    {
        $values = array(
            'task_id' => $task_id,
            'user_id' => $user_id,
            'comment' => $content,
            'reference' => $reference,
        );

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

        return $valid ? $this->comment->create($values) : false;
    }

    public function updateComment($id, $content)
    {
        $values = array(
            'id' => $id,
            'comment' => $content,
        );

        list($valid, ) = $this->commentValidator->validateModification($values);
        return $valid && $this->comment->update($values);
    }
}