1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Radchasay\Comment\HTMLForm; |
4
|
|
|
|
5
|
|
|
use \Anax\HTMLForm\FormModel; |
6
|
|
|
use \Anax\DI\DIInterface; |
7
|
|
|
use \Radchasay\Comment\CommentComments; |
8
|
|
|
use \Radchasay\User\User; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Example of FormModel implementation. |
12
|
|
|
*/ |
13
|
|
|
class CreateCommentCommentForm extends FormModel |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Constructor injects with DI container. |
17
|
|
|
* |
18
|
|
|
* @param Anax\DI\DIInterface $di a service container |
19
|
|
|
*/ |
20
|
|
|
public function __construct(DIInterface $di, $idcomment, $idpost) |
21
|
|
|
{ |
22
|
|
|
parent::__construct($di); |
23
|
|
|
|
24
|
|
|
$this->form->create( |
25
|
|
|
[ |
26
|
|
|
"id" => __CLASS__, |
27
|
|
|
"legend" => "Create new comment" |
28
|
|
|
], |
29
|
|
|
[ |
30
|
|
|
"text" => [ |
31
|
|
|
"type" => "textarea" |
32
|
|
|
], |
33
|
|
|
|
34
|
|
|
"hiddenid" => [ |
35
|
|
|
"type" => "hidden", |
36
|
|
|
"value" => $idcomment, |
37
|
|
|
], |
38
|
|
|
|
39
|
|
|
"hiddenpost" => [ |
40
|
|
|
"type" => "hidden", |
41
|
|
|
"value" => $idpost, |
42
|
|
|
], |
43
|
|
|
|
44
|
|
|
"submit" => [ |
45
|
|
|
"type" => "submit", |
46
|
|
|
"value" => "Create comment", |
47
|
|
|
"callback" => [$this, "callbackSubmit"], |
48
|
|
|
], |
49
|
|
|
] |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Callback for submit-button which should return true if it could |
56
|
|
|
* carry out its work and false if something failed. |
57
|
|
|
* |
58
|
|
|
* @return boolean true if okey, false if something went wrong. |
59
|
|
|
*/ |
60
|
|
|
public function callbackSubmit() |
61
|
|
|
{ |
62
|
|
|
// Get values from the submitted form |
63
|
|
|
// |
64
|
|
|
$commentComment = new CommentComments(); |
65
|
|
|
$commentComment->setDB($this->di->get("db")); |
66
|
|
|
$data = $this->form->value("text"); |
67
|
|
|
$text = $this->di->get("textfilter")->doFilter($data, ["bbcode", "clickable", |
68
|
|
|
"shortcode", "markdown", "purify"]); |
69
|
|
|
$commentComment->textcomment = $text; |
70
|
|
|
$commentComment->idcommentcomment = htmlentities($this->form->value("hiddenid")); |
71
|
|
|
$commentComment->postuser = $this->di->get("session")->get("email"); |
72
|
|
|
|
73
|
|
|
$idpost = htmlentities($this->form->value("hiddenpost")); |
74
|
|
|
$user = new User(); |
75
|
|
|
$user->setDb($this->di->get("db")); |
76
|
|
|
$user->getInformation($commentComment->postuser); |
77
|
|
|
$user->points += 1; |
|
|
|
|
78
|
|
|
|
79
|
|
|
$user->save(); |
80
|
|
|
$commentComment->save(); |
81
|
|
|
|
82
|
|
|
$url = $this->di->get("url")->create("comment/retrieve/$idpost"); |
83
|
|
|
$this->di->get("response")->redirect($url); |
84
|
|
|
return true; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.