1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use App\Models\ConfigModel; |
6
|
|
|
use Core\AdminController; |
7
|
|
|
use Core\Traits\StringFunctions; |
8
|
|
|
use Core\Container; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* all to do with the config page |
12
|
|
|
* Class Config |
13
|
|
|
* @package App\Controllers\Admin |
14
|
|
|
*/ |
15
|
|
|
class Config extends AdminController |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
use StringFunctions; |
19
|
|
|
protected $siteConfig; |
20
|
|
|
private $configModel; |
21
|
|
|
|
22
|
|
|
public function __construct(Container $container) |
23
|
|
|
{ |
24
|
|
|
$this->loadModules[] = 'SiteConfig'; |
25
|
|
|
parent::__construct($container); |
26
|
|
|
$this->configModel = new ConfigModel($this->container); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Shows the config page with all of the config options |
31
|
|
|
* @throws \Twig_Error_Loader |
32
|
|
|
* @throws \Twig_Error_Runtime |
33
|
|
|
* @throws \Twig_Error_Syntax |
34
|
|
|
* @throws \ReflectionException |
35
|
|
|
*/ |
36
|
|
|
public function index() |
37
|
|
|
{ |
38
|
|
|
$this->onlyAdmin(); |
39
|
|
|
|
40
|
|
|
$this->data['configList'] = $this->configModel->getAllConfigOrdered(); |
41
|
|
|
$this->renderView('Admin/Config'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* gets the information in post and sets the corresponding site config details |
47
|
|
|
* this is pure php with no ajax |
48
|
|
|
* @throws \Exception |
49
|
|
|
*/ |
50
|
|
|
public function updateConfig() |
51
|
|
|
{ |
52
|
|
|
//Security checks |
53
|
|
|
$this->onlyAdmin(); |
54
|
|
|
$this->onlyPost(); |
55
|
|
|
|
56
|
|
|
$posts = $this->request->getDataFull(); |
57
|
|
|
$success = true; |
58
|
|
|
|
59
|
|
|
foreach ($posts as $key => $config) { |
60
|
|
|
if (!$this->configModel->updateConfig($key, $config)) { |
61
|
|
|
$success = false; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
if ($success) { |
65
|
|
|
$this->alertBox->setAlert('Configuration updates successfully'); |
66
|
|
|
} else { |
67
|
|
|
$this->alertBox->setAlert('error in configuration update', 'error'); |
68
|
|
|
} |
69
|
|
|
$this->container->getResponse()->redirect('admin/config'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|