|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kifekenny\Comment\HTMLForm; |
|
4
|
|
|
|
|
5
|
|
|
use \Anax\HTMLForm\FormModel; |
|
6
|
|
|
use \Anax\DI\DIInterface; |
|
7
|
|
|
use \Kifekenny\Comment\Comment; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Form to update an item. |
|
11
|
|
|
*/ |
|
12
|
|
|
class Com2Delete extends FormModel |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Constructor injects with DI container and the id to update. |
|
16
|
|
|
* |
|
17
|
|
|
* @param Anax\DI\DIInterface $di a service container |
|
|
|
|
|
|
18
|
|
|
* @param integer $id to update |
|
19
|
|
|
*/ |
|
20
|
2 |
|
public function __construct(DIInterface $dis, $id) |
|
21
|
|
|
{ |
|
22
|
2 |
|
parent::__construct($dis); |
|
23
|
2 |
|
$currId = $this->di->get("session")->get("user_id"); |
|
24
|
2 |
|
$comment2 = $this->isgetItemDetails($id); |
|
25
|
2 |
|
if ($currId != 1) { |
|
26
|
2 |
|
if ($comment2->userId != $currId) { |
|
27
|
2 |
|
$this->di->get("response")->redirect(""); |
|
28
|
2 |
|
} |
|
29
|
2 |
|
} |
|
30
|
2 |
|
$this->form->create( |
|
31
|
|
|
[ |
|
32
|
2 |
|
"id" => __CLASS__, |
|
33
|
2 |
|
"legend" => "Update details of the book", |
|
34
|
2 |
|
], |
|
35
|
|
|
[ |
|
36
|
|
|
"id" => [ |
|
37
|
2 |
|
"type" => "hidden", |
|
38
|
2 |
|
"value" => $comment2->id, |
|
39
|
2 |
|
], |
|
40
|
|
|
|
|
41
|
|
|
"Title" => [ |
|
42
|
2 |
|
"type" => "text", |
|
43
|
2 |
|
"validation" => ["not_empty"], |
|
44
|
2 |
|
"readonly" => true, |
|
45
|
2 |
|
"value" => $comment2->title, |
|
46
|
2 |
|
], |
|
47
|
|
|
|
|
48
|
|
|
"Content" => [ |
|
49
|
2 |
|
"type" => "textarea", |
|
50
|
2 |
|
"validation" => ["not_empty"], |
|
51
|
2 |
|
"value" => $comment2->content, |
|
52
|
2 |
|
"readonly" => true, |
|
53
|
2 |
|
"class" => "editText", |
|
54
|
2 |
|
], |
|
55
|
|
|
|
|
56
|
|
|
"submit" => [ |
|
57
|
2 |
|
"type" => "submit", |
|
58
|
2 |
|
"value" => "Delete", |
|
59
|
2 |
|
"class" => "red", |
|
60
|
2 |
|
"callback" => [$this, "callbackSubmit"] |
|
61
|
2 |
|
], |
|
62
|
|
|
] |
|
63
|
2 |
|
); |
|
64
|
2 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get details on item to load form with. |
|
70
|
|
|
* |
|
71
|
|
|
* @param integer $id get details on item with id. |
|
72
|
|
|
* |
|
73
|
|
|
* @return boolean true if okey, false if something went wrong. |
|
74
|
|
|
*/ |
|
75
|
2 |
View Code Duplication |
public function isgetItemDetails($id) |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
2 |
|
$comment2 = new Comment(); |
|
78
|
2 |
|
$comment2->setDb($this->di->get("db")); |
|
79
|
2 |
|
$comment2->find("id", $id); |
|
80
|
2 |
|
return $comment2; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Callback for submit-button which should return true if it could |
|
87
|
|
|
* carry out its work and false if something failed. |
|
88
|
|
|
* |
|
89
|
|
|
* @return boolean true if okey, false if something went wrong. |
|
90
|
|
|
*/ |
|
91
|
|
|
public function callbackSubmit() |
|
92
|
|
|
{ |
|
93
|
|
|
$comment = new Comment(); |
|
94
|
|
|
$comment->setDb($this->di->get("db")); |
|
95
|
|
|
$comment->find("id", $this->form->value("id")); |
|
96
|
|
|
$comment->delete(); |
|
97
|
|
|
$this->di->get("response")->redirect(""); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.