Settings   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 102
rs 10

8 Methods

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