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

namespace Api;

/**
 * Comment API controller
 *
 * @package  api
 * @author   Frederic Guillot
 */
class Comment 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)
    {
        $values = array(
            'task_id' => $task_id,
            'user_id' => $user_id,
            'comment' => $content,
        );

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

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

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

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