Settings::editSettings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package reCAPTCHA
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\recaptcha\controllers;
11
12
use gplcart\core\controllers\backend\Controller;
13
14
/**
15
 * Handles incoming requests and outputs data related to reCAPTCHA 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
28
        $this->setData('settings', $this->module->getSettings('recaptcha'));
29
30
        $this->submitSettings();
31
        $this->outputEditSettings();
32
    }
33
34
    /**
35
     * Set title on the module settings page
36
     */
37
    protected function setTitleEditSettings()
38
    {
39
        $title = $this->text('Edit %name settings', array('%name' => $this->text('reCAPTCHA')));
40
        $this->setTitle($title);
41
    }
42
43
    /**
44
     * Set breadcrumbs on the module settings page
45
     */
46
    protected function setBreadcrumbEditSettings()
47
    {
48
        $breadcrumbs = array();
49
50
        $breadcrumbs[] = array(
51
            'text' => $this->text('Dashboard'),
52
            'url' => $this->url('admin')
53
        );
54
55
        $breadcrumbs[] = array(
56
            'text' => $this->text('Modules'),
57
            'url' => $this->url('admin/module/list')
58
        );
59
60
        $this->setBreadcrumbs($breadcrumbs);
61
    }
62
63
    /**
64
     * Saves the submitted settings
65
     */
66
    protected function submitSettings()
67
    {
68
        if ($this->isPosted('save') && $this->validateSettings()) {
69
            $this->updateSettings();
70
        }
71
    }
72
73
    /**
74
     * Validate submitted module settings
75
     */
76
    protected function validateSettings()
77
    {
78
        $this->setSubmitted('settings');
79
        return !$this->hasErrors();
80
    }
81
82
    /**
83
     * Update module settings
84
     */
85
    protected function updateSettings()
86
    {
87
        $this->controlAccess('module_edit');
88
        $this->module->setSettings('recaptcha', $this->getSubmitted());
89
        $this->redirect('', $this->text('Settings have been updated'), 'success');
90
    }
91
92
    /**
93
     * Render and output the module settings page
94
     */
95
    protected function outputEditSettings()
96
    {
97
        $this->output('recaptcha|settings');
98
    }
99
100
}
101