Passed
Push — Showing-Posts ( a59326...b4fc92 )
by Stone
01:47
created

Config::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controllers\Admin;
4
5
use App\Models\ConfigModel;
6
use Core\AdminController;
7
use Core\Traits\StringFunctions;
8
9
/**
10
 * all to do with the config page
11
 * Class Config
12
 * @package App\Controllers\Admin
13
 */
14
class Config extends AdminController
15
{
16
17
    use StringFunctions;
18
19
    private $configModel;
20
21
    public function __construct(Container $container)
0 ignored issues
show
Bug introduced by
The type App\Controllers\Admin\Container was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
    {
23
        parent::__construct($container);
24
        $this->configModel = new ConfigModel($this->container);
25
    }
26
27
    /**
28
     * Shows the config page with all of the config options
29
     * @throws \Twig_Error_Loader
30
     * @throws \Twig_Error_Runtime
31
     * @throws \Twig_Error_Syntax
32
     * @throws \ReflectionException
33
     */
34
    public function index()
35
    {
36
        $this->onlyAdmin();
37
38
        $this->data['configList'] = $this->configModel->getAllConfigOrdered();
39
        $this->renderView('Admin/Config');
40
    }
41
42
43
    /**
44
     * gets the information in post and sets the corresponding site config details
45
     * this is pure php with no ajax
46
     * @throws \Exception
47
     */
48
    public function updateConfig()
49
    {
50
        //Security checks
51
        $this->onlyAdmin();
52
        if (!$this->container->getRequest()->isPost()) {
53
            $this->alertBox->setAlert('Only post messages allowed', 'error');
54
            $this->container->getResponse()->redirect('admin');
55
        }
56
        
57
        $posts = $this->container->getRequest()->getDataFull();
58
        $success = true;
59
60
        foreach ($posts as $key => $config) {
61
            if (!$this->configModel->updateConfig($key, $config)) {
62
                $success = false;
63
            }
64
        }
65
        if ($success) {
66
            $this->alertBox->setAlert('Configuration updates successfully');
67
        } else {
68
            $this->alertBox->setAlert('error in configuration update', 'error');
69
        }
70
        $this->container->getResponse()->redirect('admin/config');
71
    }
72
}
73