1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aiur18\Question\HTMLForm; |
4
|
|
|
|
5
|
|
|
use Anax\HTMLForm\FormModel; |
6
|
|
|
use Psr\Container\ContainerInterface; |
7
|
|
|
use Aiur18\Question\Comment; |
8
|
|
|
use Aiur18\Filter\MyTextFilter; |
9
|
|
|
use Aiur18\getset\getset; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Form to create an item. |
13
|
|
|
*/ |
14
|
|
|
class CreateComment extends FormModel |
15
|
|
|
{ |
16
|
|
|
public $idForQuestion; |
17
|
|
|
public $idForAnswer; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Constructor injects with DI container. |
21
|
|
|
* |
22
|
|
|
* @param Psr\Container\ContainerInterface $di a service container |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
public function __construct(ContainerInterface $di, $idAnswer, $idQuestion) |
25
|
|
|
{ |
26
|
|
|
parent::__construct($di); |
27
|
|
|
$this->idForAnswer = $idAnswer; |
28
|
|
|
$this->idForQuestion = $idQuestion; |
29
|
|
|
$this->form->create( |
30
|
|
|
[ |
31
|
|
|
"id" => __CLASS__, |
32
|
|
|
"legend" => "Details of the item", |
33
|
|
|
], |
34
|
|
|
[ |
35
|
|
|
|
36
|
|
|
"comment" => [ |
37
|
|
|
"type" => "textarea", |
38
|
|
|
"validation" => ["not_empty"], |
39
|
|
|
], |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
"submit" => [ |
43
|
|
|
"type" => "submit", |
44
|
|
|
"value" => "Create item", |
45
|
|
|
"callback" => [$this, "callbackSubmit"] |
46
|
|
|
], |
47
|
|
|
] |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** Method |
54
|
|
|
*/ |
55
|
|
|
public function callbackSubmit() : bool |
56
|
|
|
{ |
57
|
|
|
$answer = new Comment(); |
58
|
|
|
$answer->setDb($this->di->get("dbqb")); |
59
|
|
|
|
60
|
|
|
//Markdown filter applied |
61
|
|
|
$filterMarkdown = new \Aiur18\Filter\MyTextFilter(); |
62
|
|
|
$commentRes = $filterMarkdown->markdown($this->form->value("comment")); |
63
|
|
|
|
64
|
|
|
$getServer = new getSet(); |
65
|
|
|
$answer->user_id = $getServer->getServer('user_id'); |
66
|
|
|
$answer->comment = $commentRes; |
67
|
|
|
$answer->id_answer = $this->idForAnswer; |
|
|
|
|
68
|
|
|
$answer->id_question = $this->idForQuestion; |
|
|
|
|
69
|
|
|
$answer->save(); |
70
|
|
|
return true; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** Method |
74
|
|
|
*/ |
75
|
|
|
public function getItemDetails($id) : object |
76
|
|
|
{ |
77
|
|
|
$answer = new Comment(); |
78
|
|
|
$answer->setDb($this->di->get("dbqb")); |
79
|
|
|
$answer->find("id", $id); |
80
|
|
|
return $answer; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Method |
86
|
|
|
*/ |
87
|
|
|
public function setId($id) : bool |
88
|
|
|
{ |
89
|
|
|
$this->id = $id; |
|
|
|
|
90
|
|
|
return true; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Method |
96
|
|
|
*/ |
97
|
|
|
public function getId() : int |
98
|
|
|
{ |
99
|
|
|
return $this->id; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** Method |
105
|
|
|
*/ |
106
|
|
|
public function callbackSuccess() |
107
|
|
|
{ |
108
|
|
|
$this->di->get("response")->redirect("question")->send(); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|