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