1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nicklas\Comment; |
4
|
|
|
|
5
|
|
|
use \Nicklas\Comment\HTMLForm\CreateCommentForm; |
6
|
|
|
use \Nicklas\Comment\HTMLForm\EditCommentForm; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Extends the UserController, for comments |
10
|
|
|
*/ |
11
|
|
|
class CommentController extends AdminController |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Show all items. |
17
|
|
|
* |
18
|
|
|
* @return void |
19
|
|
|
*/ |
20
|
1 |
|
public function getIndex() |
21
|
|
|
{ |
22
|
1 |
|
$comment = new Comment($this->di); |
23
|
1 |
|
$comment->setDb($this->di->get("db")); |
24
|
|
|
|
25
|
1 |
|
$form = new CreateCommentForm($this->di); |
26
|
1 |
|
$form->check(); |
27
|
|
|
|
28
|
|
|
$views = [ |
29
|
1 |
|
["comment/view-all", ["comments" => $comment->getAll()], "main"], |
30
|
1 |
|
["comment/makeComment", ["form" => $form->getHTML()], "main"] |
31
|
1 |
|
]; |
32
|
|
|
|
33
|
|
|
// If not logged in, render other views |
34
|
1 |
|
if (!$this->di->get("session")->has("user")) { |
35
|
|
|
$views = [ |
36
|
1 |
|
["comment/view-all", ["comments" => $comment->getAll()], "main"], |
37
|
1 |
|
["comment/loginComment", [], "main"] |
38
|
1 |
|
]; |
39
|
1 |
|
} |
40
|
|
|
|
41
|
1 |
|
$this->renderPage($views, "A collection of comments"); |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param integer $id. |
|
|
|
|
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
1 |
|
public function getPostEditComment($id) |
50
|
|
|
{ |
51
|
|
|
|
52
|
1 |
|
$comment = new Comment($this->di); |
53
|
1 |
|
$comment->setDb($this->di->get("db")); |
54
|
1 |
|
$comment = $comment->get($id); |
55
|
|
|
|
56
|
1 |
|
$form = new EditCommentForm($this->di, $id); |
57
|
1 |
|
$form->check(); |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
$views = [ |
61
|
1 |
|
["comment/editComment", ["form" => $form->getHTML(), "comment" => $comment], "main"], |
62
|
1 |
|
]; |
63
|
|
|
|
64
|
|
|
// if it belongs to user, or user is admin ignore |
65
|
1 |
|
$userName = $this->di->get("session")->get("user"); |
66
|
1 |
|
if (!$comment->controlAuthority($userName)) { |
|
|
|
|
67
|
|
|
$views = [ |
68
|
1 |
|
["comment/fail", [], "main"], |
69
|
1 |
|
]; |
70
|
1 |
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
1 |
|
$this->renderPage($views, "A collection of comments"); |
74
|
1 |
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.