Completed
Push — master ( aa08df...50a885 )
by Iurii
01:04
created

Settings::getDevModuleSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package Dev
5
 * @author Iurii Makukh
6
 * @copyright Copyright (c) 2017, Iurii Makukh
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\dev\controllers;
11
12
use gplcart\core\controllers\backend\Controller as BackendController;
13
14
/**
15
 * Handles incoming requests and outputs data related to Dev module
16
 */
17
class Settings extends BackendController
18
{
19
20
    /**
21
     * Constructor
22
     */
23
    public function __construct()
24
    {
25
        parent::__construct();
26
    }
27
28
    /**
29
     * Route page callback to display the module settings page
30
     */
31
    public function editSettings()
32
    {
33
        $this->setTitleEditSettings();
34
        $this->setBreadcrumbEditSettings();
35
36
        $this->setData('settings', $this->getModuleSettings('dev'));
37
38
        $this->submitSettings();
39
        $this->outputEditSettings();
40
    }
41
42
    /**
43
     * Set title on the module settings page
44
     */
45
    protected function setTitleEditSettings()
46
    {
47
        $this->setTitle($this->text('Edit %name settings', array('%name' => $this->text('Dev'))));
48
    }
49
50
    /**
51
     * Set breadcrumbs on the module settings page
52
     */
53
    protected function setBreadcrumbEditSettings()
54
    {
55
        $breadcrumbs = array();
56
57
        $breadcrumbs[] = array(
58
            'text' => $this->text('Dashboard'),
59
            'url' => $this->url('admin')
60
        );
61
62
        $breadcrumbs[] = array(
63
            'text' => $this->text('Modules'),
64
            'url' => $this->url('admin/module/list')
65
        );
66
67
        $this->setBreadcrumbs($breadcrumbs);
68
    }
69
70
    /**
71
     * Saves the submitted settings
72
     */
73
    protected function submitSettings()
74
    {
75
        if ($this->isPosted('save') && $this->validateSettings()) {
76
            $this->updateSettings();
77
        }
78
    }
79
80
    /**
81
     * Validate submitted module settings
82
     */
83
    protected function validateSettings()
84
    {
85
        $this->setSubmitted('settings');
86
        return !$this->hasErrors();
87
    }
88
89
    /**
90
     * Update module settings
91
     */
92
    protected function updateSettings()
93
    {
94
        $this->controlAccess('module_edit');
95
        $this->module->setSettings('dev', $this->getSubmitted());
96
        $this->redirect('', $this->text('Settings have been updated'), 'success');
97
    }
98
99
    /**
100
     * Render and output the module settings page
101
     */
102
    protected function outputEditSettings()
103
    {
104
        $this->output('dev|settings');
105
    }
106
107
}
108