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