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\getset\getset; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Form to update an item. |
12
|
|
|
*/ |
13
|
|
|
class UpdateForm extends FormModel |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Constructor injects with DI container and the id to update. |
17
|
|
|
* |
18
|
|
|
* @param Psr\Container\ContainerInterface $di a service container |
|
|
|
|
19
|
|
|
* @param integer $id to update |
20
|
|
|
*/ |
21
|
|
|
public function __construct(ContainerInterface $di, $id) |
22
|
|
|
{ |
23
|
|
|
parent::__construct($di); |
24
|
|
|
$question = $this->getItemDetails($id); |
25
|
|
|
$this->form->create( |
26
|
|
|
[ |
27
|
|
|
"id" => __CLASS__, |
28
|
|
|
"legend" => "Update details of the item", |
29
|
|
|
], |
30
|
|
|
[ |
31
|
|
|
"id" => [ |
32
|
|
|
"type" => "text", |
33
|
|
|
"validation" => ["not_empty"], |
34
|
|
|
"readonly" => true, |
35
|
|
|
"value" => $question->id, |
36
|
|
|
], |
37
|
|
|
|
38
|
|
|
"column1" => [ |
39
|
|
|
"type" => "text", |
40
|
|
|
"validation" => ["not_empty"], |
41
|
|
|
"value" => $question->column1, |
42
|
|
|
], |
43
|
|
|
|
44
|
|
|
"column2" => [ |
45
|
|
|
"type" => "text", |
46
|
|
|
"validation" => ["not_empty"], |
47
|
|
|
"value" => $question->column2, |
48
|
|
|
], |
49
|
|
|
|
50
|
|
|
"submit" => [ |
51
|
|
|
"type" => "submit", |
52
|
|
|
"value" => "Save", |
53
|
|
|
"callback" => [$this, "callbackSubmit"] |
54
|
|
|
], |
55
|
|
|
|
56
|
|
|
"reset" => [ |
57
|
|
|
"type" => "reset", |
58
|
|
|
], |
59
|
|
|
] |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** Method |
66
|
|
|
*/ |
67
|
|
|
public function getItemDetails($id) : object |
68
|
|
|
{ |
69
|
|
|
$question = new Question(); |
70
|
|
|
$question->setDb($this->di->get("dbqb")); |
71
|
|
|
$question->find("id", $id); |
72
|
|
|
return $question; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** Method |
78
|
|
|
*/ |
79
|
|
|
public function callbackSubmit() : bool |
80
|
|
|
{ |
81
|
|
|
$question = new Question(); |
82
|
|
|
$question->setDb($this->di->get("dbqb")); |
83
|
|
|
$question->find("id", $this->form->value("id")); |
84
|
|
|
$question->column1 = $this->form->value("column1"); |
|
|
|
|
85
|
|
|
$question->column2 = $this->form->value("column2"); |
|
|
|
|
86
|
|
|
$question->save(); |
87
|
|
|
return true; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|