|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use App\Models\UserModel; |
|
8
|
|
|
use Core\Container; |
|
9
|
|
|
use Core\Traits\StringFunctions; |
|
10
|
|
|
|
|
11
|
|
|
class Home extends \Core\AdminController |
|
12
|
|
|
{ |
|
13
|
|
|
use StringFunctions; |
|
|
|
|
|
|
14
|
|
|
protected $siteConfig; |
|
15
|
|
|
|
|
16
|
|
|
private $userModel; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct(Container $container) |
|
19
|
|
|
{ |
|
20
|
|
|
$this->loadModules[] = 'SiteConfig'; |
|
21
|
|
|
parent::__construct($container); |
|
22
|
|
|
$this->userModel = new UserModel($this->container); |
|
23
|
|
|
|
|
24
|
|
|
$this->data['configs'] = $this->siteConfig->getSiteConfig(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The front page of the admin section. We display the user info |
|
29
|
|
|
* @throws \ReflectionException |
|
30
|
|
|
* @throws \Twig_Error_Loader |
|
31
|
|
|
* @throws \Twig_Error_Runtime |
|
32
|
|
|
* @throws \Twig_Error_Syntax |
|
33
|
|
|
*/ |
|
34
|
|
|
public function index() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->onlyUser(); |
|
37
|
|
|
|
|
38
|
|
|
$userId = $this->session->get("user_id"); |
|
39
|
|
|
$this->data["user"] = $this->userModel->getUserDetailsById($userId); |
|
40
|
|
|
|
|
41
|
|
|
$this->renderView('Admin/Home'); |
|
42
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Administrate a user as an admin |
|
47
|
|
|
* @param int $userId |
|
48
|
|
|
* @throws \ReflectionException |
|
49
|
|
|
* @throws \Twig_Error_Loader |
|
50
|
|
|
* @throws \Twig_Error_Runtime |
|
51
|
|
|
* @throws \Twig_Error_Syntax |
|
52
|
|
|
*/ |
|
53
|
|
|
public function viewUser(int $userId) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->onlyAdmin(); |
|
56
|
|
|
if(!$this->isInt($userId)) |
|
57
|
|
|
{ |
|
58
|
|
|
throw new \Exception("Error in passed ID"); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$this->data["user"] = $this->userModel->getUserDetailsById($userId); |
|
62
|
|
|
$this->renderView('Admin/Home'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Update the user info via post |
|
67
|
|
|
*/ |
|
68
|
|
|
public function updateUser() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->onlyPost(); |
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
} |