1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Seb\Profile; |
4
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
7
|
|
|
use Seb\Profile\HTMLForm\UpdateForm; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* A sample controller to show how a controller class can be implemented. |
11
|
|
|
*/ |
12
|
|
|
class ProfileController implements ContainerInjectableInterface |
13
|
|
|
{ |
14
|
|
|
use ContainerInjectableTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Show all items. |
18
|
|
|
* |
19
|
|
|
* @return object as a response object |
20
|
|
|
*/ |
21
|
1 |
|
public function indexActionGet() : object |
22
|
|
|
{ |
23
|
1 |
|
$page = $this->di->get("page"); |
24
|
1 |
|
$session = $this->di->get("session"); |
25
|
1 |
|
$acronym = $session->get("acronym"); |
26
|
1 |
|
$profile = new Profile(); |
27
|
1 |
|
$profile->setDb($this->di->get("dbqb")); |
28
|
|
|
|
29
|
1 |
|
if (!$session->get("acronym")) { |
30
|
1 |
|
$page->add("user/please"); |
31
|
1 |
|
return $page->render(); |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
$page->add("user/profile", [ |
35
|
1 |
|
"userInfo" => $profile->findAll(), |
36
|
1 |
|
"acro" => $acronym |
37
|
|
|
]); |
38
|
|
|
|
39
|
1 |
|
return $page->render([ |
40
|
1 |
|
"title" => "Profile", |
41
|
|
|
]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Handler with form to update an item. |
46
|
|
|
* |
47
|
|
|
* @param int $id the id to update. |
48
|
|
|
* |
49
|
|
|
* @return object as a response object |
50
|
|
|
*/ |
51
|
1 |
|
public function updateAction(int $id) : object |
52
|
|
|
{ |
53
|
1 |
|
$page = $this->di->get("page"); |
54
|
1 |
|
$form = new UpdateForm($this->di, $id); |
55
|
1 |
|
$form->check(); |
56
|
|
|
|
57
|
1 |
|
$page->add("user/update", [ |
58
|
1 |
|
"form" => $form->getHTML(), |
59
|
|
|
]); |
60
|
|
|
|
61
|
1 |
|
return $page->render([ |
62
|
1 |
|
"title" => "Update an item", |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Handler with form to update an item. |
68
|
|
|
* |
69
|
|
|
* @param int $id the id to update. |
70
|
|
|
* |
71
|
|
|
* @return object as a response object |
72
|
|
|
*/ |
73
|
1 |
|
public function logoutAction() |
74
|
|
|
{ |
75
|
1 |
|
$session = $this->di->get("session"); |
76
|
1 |
|
$session->set("acronym", null); |
77
|
1 |
|
$session->set("userid", null); |
78
|
1 |
|
$this->di->get("response")->redirect("user/login")->send(); |
79
|
1 |
|
} |
80
|
|
|
} |
81
|
|
|
|