Config::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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