Passed
Push — master ( 6494fd...7e1229 )
by Nicklas
02:09
created

CommentController::getIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nicklas\Comment;
4
5
use \Nicklas\Comment\HTMLForm\Comment\CreateQuestionForm;
6
use \Nicklas\Comment\HTMLForm\Comment\EditCommentForm;
7
8
use \Nicklas\Comment\Modules\Comment;
9
10
/**
11
 * Extends the UserController, for comments
12
 */
13
class CommentController extends AdminController
14
{
15
16
17
    /**
18
     * Show all items.
19
     *
20
     * @return void
21
     */
22 1
    public function getIndex()
23
    {
24 1
        $comment = new Comment($this->di);
25 1
        $comment->setDb($this->di->get("db"));
26
27
        $views = [
28 1
            ["comment/crud/view-all", ["questions" => $comment->getPosts("type = ?", ["question"])], "main"]
29 1
        ];
30
31 1
        $this->di->get("pageRenderComment")->renderPage([
32 1
            "views" => $views,
33
            "title" => "All questions"
34 1
        ]);
35 1
    }
36
37
    /**
38
     * Show all items.
39
     *
40
     * @return void
41
     */
42
    public function getPostCreateQuestion()
43
    {
44
        $comment = new Comment($this->di);
45
        $comment->setDb($this->di->get("db"));
46
47
        $form       = new CreateQuestionForm($this->di);
48
        $form->check();
49
50
        $views = [
51
            ["comment/crud/createQuestion", ["form" => $form->getHTML()], "main"],
52
            ["comment/crud/view-all", ["questions" => $comment->getPosts("type = ?", ["question"])], "main"]
53
        ];
54
55
        // If not logged in, render other views
56
        if (!$this->di->get("session")->has("user")) {
57
            $views = [
58
                ["comment/loginComment", [], "main"]
59
            ];
60
        }
61
62
        $this->di->get("pageRenderComment")->renderPage([
63
            "views" => $views,
64
            "title" => "Create your question"
65
        ]);
66
    }
67
68
    /**
69
     * Show all items.
70
     *
71
     * @return void
72
     */
73
    public function getPostQuestionAnswer($id)
74
    {
75
        $question = new Comment($this->di);
76
        $question->setDb($this->di->get("db"));
77
78
        $question = $question->getPost($id);
79
80
        // If not logged in, render other views
81 View Code Duplication
        if ($question->type == "question") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
            $views = [
83
                ["comment/crud/question", ["question" => $question], "main"]
84
             ];
85
            $this->di->get("pageRenderComment")->renderPage([
86
                "views" => $views,
87
                "title" => "Create your question"
88
            ]);
89
        }
90
        return false;
91
    }
92
}
93