1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Radchasay\Comment\HTMLForm; |
4
|
|
|
|
5
|
|
|
use \Anax\HTMLForm\FormModel; |
6
|
|
|
use \Anax\DI\DIInterface; |
7
|
|
|
use \Radchasay\Comment\Comment; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Form to update an item. |
11
|
|
|
*/ |
12
|
|
|
class UpdateCommentForm 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
|
|
|
public function __construct(DIInterface $di, $id) |
21
|
|
|
{ |
22
|
|
|
parent::__construct($di); |
23
|
|
|
$commentInfo = $this->getItemDetails($id); |
24
|
|
|
$this->form->create( |
25
|
|
|
[ |
26
|
|
|
"id" => __CLASS__, |
27
|
|
|
"legend" => "Update details of the item", |
28
|
|
|
], |
29
|
|
|
[ |
30
|
|
|
"id" => [ |
31
|
|
|
"type" => "hidden", |
32
|
|
|
"value" => $commentInfo->idcomment, |
33
|
|
|
], |
34
|
|
|
"text" => [ |
35
|
|
|
"type" => "text", |
36
|
|
|
"value" => $commentInfo->commenttext, |
37
|
|
|
], |
38
|
|
|
|
39
|
|
|
"submit" => [ |
40
|
|
|
"type" => "submit", |
41
|
|
|
"value" => "Edit comment", |
42
|
|
|
"callback" => [$this, "callbackSubmit"], |
43
|
|
|
], |
44
|
|
|
] |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get details on item to load form with. |
51
|
|
|
* |
52
|
|
|
* @param integer $id get details on item with id. |
53
|
|
|
* |
54
|
|
|
* @return $comment |
|
|
|
|
55
|
|
|
*/ |
56
|
|
|
public function getItemDetails($id) |
57
|
|
|
{ |
58
|
|
|
$comment = new Comment(); |
59
|
|
|
$comment->setDb($this->di->get("db")); |
60
|
|
|
$comment->find("idcomment", $id); |
61
|
|
|
return $comment; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Callback for submit-button which should return true if it could |
68
|
|
|
* carry out its work and false if something failed. |
69
|
|
|
* |
70
|
|
|
* @return boolean true if okey, false if something went wrong. |
71
|
|
|
*/ |
72
|
|
|
public function callbackSubmit() |
73
|
|
|
{ |
74
|
|
|
$comment = new Comment(); |
75
|
|
|
$comment->setDb($this->di->get("db")); |
76
|
|
|
$comment->find("idcomment", $this->form->value("id")); |
77
|
|
|
$data = htmlentities($this->form->value("text")); |
78
|
|
|
$text = htmlentities($this->di->get("textfilter")->doFilter($data, ["bbcode", |
79
|
|
|
"clickable", "shortcode", "markdown", "purify"])); |
80
|
|
|
$comment->commenttext = $text; |
81
|
|
|
$id = $this->form->value("id"); |
82
|
|
|
$comment->save("idcomment", $id); |
83
|
|
|
$id = $this->form->value("id"); |
|
|
|
|
84
|
|
|
$postid = $comment->idpost; |
85
|
|
|
$url = $this->di->get("url")->create("comment/retrieve/{$postid}"); |
86
|
|
|
$this->di->get("response")->redirect($url); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.