Completed
Push — master ( ec1a89...79f0f5 )
by Nicklas
02:22
created

FrontController::postComment()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 4
nop 1
crap 12
1
<?php
2
3
namespace Nicklas\Comment;
4
5
use \Nicklas\Comment\Modules\Comment;
6
use \Nicklas\Comment\Modules\Vote;
7
8
/**
9
 * Extends the UserController, for comments
10
 */
11
class FrontController extends QuestionController
12
{
13
14
15
    /**
16
     * View specific question and create answer form
17
     *
18
     * @return void
19
     */
20
    public function postComment($id)
21
    {
22
        $text = isset($_POST["text"]) ? $_POST["text"] : "nothingfound";
23
24
        if ($text == "nothingfound") {
25
            return false;
26
        }
27
        $user = $this->di->get("session")->get("user");
28
        $comment = new Comment($this->di->get("db"));
29
        $comment->text = $text;
30
        $comment->parentId = $id;
31
        $comment->user = $user;
32
        $comment->save();
33
        return true;
34
    }
35
36
    /**
37
     * View specific question and create answer form
38
     *
39
     * @return void
40
     */
41
    public function postVote()
42
    {
43
        $vote = new Vote();
44
45
        $user = $this->di->get("session")->get("user");
46
47
        $parentType = isset($_POST["parentType"]) ? $_POST["parentType"] : "";
48
        $downVote   = isset($_POST["downVote"])   ? $_POST["downVote"]   : null;
49
        $parentId   = isset($_POST["parentId"])   ? $_POST["parentId"]   : "";
50
        $upVote     = isset($_POST["upVote"])     ? $_POST["upVote"]     : null;
51
52
        if ($upVote != null) {
53
            return $vote->like($user, $parentId, $parentType);
54
        }
55
        if ($downVote != null) {
56
            return $vote->dislike($user, $parentId, $parentType);
57
        }
58
        return false;
59
    }
60
}
61