Settings   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

8 Methods

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