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