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
|
|
|
use \Radchasay\Comment\CommentComments; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Form to update an item. |
12
|
|
|
*/ |
13
|
|
|
class UpdateCommentCommentForm extends FormModel |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Constructor injects with DI container and the id to update. |
17
|
|
|
* |
18
|
|
|
* @param Anax\DI\DIInterface $di a service container |
19
|
|
|
* @param integer $id to update |
20
|
|
|
*/ |
21
|
|
|
public function __construct(DIInterface $di, $id) |
22
|
|
|
{ |
23
|
|
|
parent::__construct($di); |
24
|
|
|
$commentInfo = $this->getItemDetails($id); |
25
|
|
|
$this->form->create( |
26
|
|
|
[ |
27
|
|
|
"id" => __CLASS__, |
28
|
|
|
"legend" => "Update details of the item", |
29
|
|
|
], |
30
|
|
|
[ |
31
|
|
|
"id" => [ |
32
|
|
|
"type" => "hidden", |
33
|
|
|
"value" => $commentInfo->idcommentc, |
34
|
|
|
], |
35
|
|
|
"text" => [ |
36
|
|
|
"type" => "text", |
37
|
|
|
"value" => $commentInfo->textcomment, |
38
|
|
|
], |
39
|
|
|
|
40
|
|
|
"submit" => [ |
41
|
|
|
"type" => "submit", |
42
|
|
|
"value" => "Edit comment", |
43
|
|
|
"callback" => [$this, "callbackSubmit"], |
44
|
|
|
], |
45
|
|
|
] |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get details on item to load form with. |
52
|
|
|
* |
53
|
|
|
* @param integer $id get details on item with id. |
54
|
|
|
* |
55
|
|
|
* @return $comment |
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
public function getItemDetails($id) |
58
|
|
|
{ |
59
|
|
|
$comment = new CommentComments(); |
60
|
|
|
$comment->setDb($this->di->get("db")); |
61
|
|
|
$comment->find("idcommentc", $id); |
62
|
|
|
return $comment; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Callback for submit-button which should return true if it could |
69
|
|
|
* carry out its work and false if something failed. |
70
|
|
|
* |
71
|
|
|
* @return boolean true if okey, false if something went wrong. |
72
|
|
|
*/ |
73
|
|
|
public function callbackSubmit() |
74
|
|
|
{ |
75
|
|
|
$comment = new CommentComments(); |
76
|
|
|
$comment->setDb($this->di->get("db")); |
77
|
|
|
$comment->find("idcommentc", $this->form->value("id")); |
78
|
|
|
$data = htmlentities($this->form->value("text")); |
79
|
|
|
$text = htmlentities($this->di->get("textfilter")->doFilter($data, ["bbcode", |
80
|
|
|
"clickable", "shortcode", "markdown", "purify"])); |
81
|
|
|
$comment->textcomment = $text; |
82
|
|
|
$id = $this->form->value("id"); |
83
|
|
|
$comment->save("idcommentc", $id); |
84
|
|
|
$id = $this->form->value("id"); |
|
|
|
|
85
|
|
|
// $postid = $comment->idpost; |
|
|
|
|
86
|
|
|
$url = $this->di->get("url")->create("comment/viewAllPosts"); |
87
|
|
|
$this->di->get("response")->redirect($url); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.