1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Seb\AnswerComments\HTMLForm; |
4
|
|
|
|
5
|
|
|
use Anax\HTMLForm\FormModel; |
6
|
|
|
use Psr\Container\ContainerInterface; |
7
|
|
|
use Seb\AnswerComments\AnswerComments; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Form to create an item. |
11
|
|
|
*/ |
12
|
|
|
class CreateAnswerCommentsForm extends FormModel |
13
|
|
|
{ |
14
|
|
|
public $quid; |
15
|
|
|
public $anid; |
16
|
|
|
/** |
17
|
|
|
* Constructor injects with DI container. |
18
|
|
|
* |
19
|
|
|
* @param Psr\Container\ContainerInterface $di a service container |
|
|
|
|
20
|
|
|
*/ |
21
|
2 |
|
public function __construct(ContainerInterface $di, int $qid, int $aid) |
22
|
|
|
{ |
23
|
2 |
|
$this->quid = $qid; |
24
|
2 |
|
$this->anid = $aid; |
25
|
2 |
|
parent::__construct($di); |
26
|
2 |
|
$this->form->create( |
27
|
|
|
[ |
28
|
2 |
|
"id" => __CLASS__, |
29
|
|
|
"legend" => "Create Comment", |
30
|
|
|
], |
31
|
|
|
[ |
32
|
|
|
|
33
|
|
|
"answerid" => [ |
34
|
2 |
|
"type" => "hidden", |
35
|
|
|
"validation" => ["not_empty"], |
36
|
|
|
"readonly" => true, |
37
|
2 |
|
"value" => $aid, |
38
|
|
|
], |
39
|
|
|
|
40
|
|
|
"comment" => [ |
41
|
|
|
"type" => "textarea", |
42
|
|
|
"validation" => ["not_empty"], |
43
|
|
|
], |
44
|
|
|
|
45
|
|
|
"submit" => [ |
46
|
2 |
|
"type" => "submit", |
47
|
2 |
|
"value" => "Create item", |
48
|
2 |
|
"callback" => [$this, "callbackSubmit"] |
49
|
|
|
], |
50
|
|
|
] |
51
|
|
|
); |
52
|
2 |
|
} |
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 bool true if okey, false if something went wrong. |
59
|
|
|
*/ |
60
|
|
|
public function callbackSubmit() : bool |
61
|
|
|
{ |
62
|
|
|
$session = $this->di->get("session"); |
63
|
|
|
$comments = new AnswerComments(); |
64
|
|
|
$comments->setDb($this->di->get("dbqb")); |
65
|
|
|
$comments->acronym = $session->get("acronym"); |
66
|
|
|
$comments->userid = $session->get("userid"); |
67
|
|
|
$comments->comment = $this->form->value("comment"); |
68
|
|
|
$comments->answerid = $this->form->value("answerid"); |
69
|
|
|
$comments->save(); |
70
|
|
|
return true; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Callback what to do if the form was successfully submitted, this |
75
|
|
|
* happen when the submit callback method returns true. This method |
76
|
|
|
* can/should be implemented by the subclass for a different behaviour. |
77
|
|
|
*/ |
78
|
|
|
public function callbackSuccess() |
79
|
|
|
{ |
80
|
|
|
$this->di->get("response")->redirect("forum/topic/{$this->quid}")->send(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|