|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Anax\Profile; |
|
4
|
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
7
|
|
|
use Anax\User\HTMLForm\EditUserForm; |
|
8
|
|
|
|
|
9
|
|
|
class ProfileController implements ContainerInjectableInterface |
|
10
|
|
|
{ |
|
11
|
|
|
use ContainerInjectableTrait; |
|
12
|
|
|
|
|
13
|
|
|
public function indexAction() |
|
14
|
|
|
{ |
|
15
|
|
|
$title = "Your profile"; |
|
16
|
|
|
$user = new \Anax\User\User(); |
|
17
|
|
|
$forum = new \Anax\Forum\Forum(); |
|
18
|
|
|
$answer = new \Anax\Forum\Answer(); |
|
19
|
|
|
$comments = new \Anax\Forum\Comment(); |
|
20
|
|
|
$anscomments = new \Anax\Forum\AnswerComment(); |
|
21
|
|
|
$user->setDb($this->di->get("dbqb")); |
|
22
|
|
|
$forum->setDb($this->di->get("dbqb")); |
|
23
|
|
|
$answer->setDb($this->di->get("dbqb")); |
|
24
|
|
|
$comments->setDb($this->di->get("dbqb")); |
|
25
|
|
|
$anscomments->setDb($this->di->get("dbqb")); |
|
26
|
|
|
$session = $this->di->get("session"); |
|
27
|
|
|
$loginId = $session->get("login"); |
|
28
|
|
|
|
|
29
|
|
|
$page = $this->di->get("page"); |
|
30
|
|
|
|
|
31
|
|
|
$page->add("profile/index", [ |
|
32
|
|
|
"items" => $user->findAllWhere("id = ?", $loginId), |
|
33
|
|
|
"posts" => $forum->findAllWhere("user = ?", $loginId), |
|
34
|
|
|
"answers" => $answer->findAllWhere("user = ?", $loginId), |
|
35
|
|
|
"comments" => $comments->findAllWhere("user = ?", $loginId), |
|
36
|
|
|
"anscomments" => $anscomments->findAllWhere("user = ?", $loginId), |
|
37
|
|
|
]); |
|
38
|
|
|
|
|
39
|
|
|
return $page->render([ |
|
40
|
|
|
"title" => $title, |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function allAction() |
|
45
|
|
|
{ |
|
46
|
|
|
$title = "All users"; |
|
47
|
|
|
$user = new \Anax\User\User(); |
|
48
|
|
|
$user->setDb($this->di->get("dbqb")); |
|
49
|
|
|
|
|
50
|
|
|
$page = $this->di->get("page"); |
|
51
|
|
|
|
|
52
|
|
|
$page->add("profile/all", [ |
|
53
|
|
|
"users" => $user->findAll(), |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
return $page->render([ |
|
57
|
|
|
"title" => $title, |
|
58
|
|
|
]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function profilesAction(int $id) |
|
62
|
|
|
{ |
|
63
|
|
|
$title = "Specific user"; |
|
64
|
|
|
$user = new \Anax\User\User(); |
|
65
|
|
|
$forum = new \Anax\Forum\Forum(); |
|
66
|
|
|
$answer = new \Anax\Forum\Answer(); |
|
67
|
|
|
$comments = new \Anax\Forum\Comment(); |
|
68
|
|
|
$anscomments = new \Anax\Forum\AnswerComment(); |
|
69
|
|
|
|
|
70
|
|
|
$user->setDb($this->di->get("dbqb")); |
|
71
|
|
|
$forum->setDb($this->di->get("dbqb")); |
|
72
|
|
|
$answer->setDb($this->di->get("dbqb")); |
|
73
|
|
|
$comments->setDb($this->di->get("dbqb")); |
|
74
|
|
|
$anscomments->setDb($this->di->get("dbqb")); |
|
75
|
|
|
|
|
76
|
|
|
$page = $this->di->get("page"); |
|
77
|
|
|
|
|
78
|
|
|
$page->add("profile/specific", [ |
|
79
|
|
|
"users" => $user->findAllWhere("id = ?", $id), |
|
80
|
|
|
"questions" => $forum->findAllWhere("user = ?", $id), |
|
81
|
|
|
"answers" => $answer->findAllWhere("user = ?", $id), |
|
82
|
|
|
"comments" => $comments->findAllWhere("user = ?", $id), |
|
83
|
|
|
"anscomments" => $anscomments->findAllWhere("user = ?", $id), |
|
84
|
|
|
]); |
|
85
|
|
|
|
|
86
|
|
|
return $page->render([ |
|
87
|
|
|
"title" => $title, |
|
88
|
|
|
]); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function editAction(int $id) |
|
92
|
|
|
{ |
|
93
|
|
|
$title = "Edit user"; |
|
94
|
|
|
$page = $this->di->get("page"); |
|
95
|
|
|
$form = new EditUserForm($this->di, $id); |
|
96
|
|
|
$form->check(); |
|
97
|
|
|
|
|
98
|
|
|
$page->add("anax/v2/article/default", [ |
|
99
|
|
|
"content" => $form->getHTML(), |
|
100
|
|
|
]); |
|
101
|
|
|
|
|
102
|
|
|
return $page->render([ |
|
103
|
|
|
"title" => $title, |
|
104
|
|
|
]); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|