Settings::updateSettings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package Twig
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2015, Iurii Makukh
7
 * @license https://www.gnu.org/licenses/gpl.html GNU/GPLv3
8
 */
9
10
namespace gplcart\modules\twig\controllers;
11
12
use gplcart\core\controllers\backend\Controller;
13
14
/**
15
 * Handles incoming requests and outputs data related to Twig 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('twig'));
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('Twig')));
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
80
        $this->setSubmittedBool('cache');
81
        $this->setSubmittedBool('debug');
82
        $this->setSubmittedBool('auto_reload');
83
        $this->setSubmittedBool('strict_variables');
84
85
        return !$this->hasErrors();
86
    }
87
88
    /**
89
     * Update module settings
90
     */
91
    protected function updateSettings()
92
    {
93
        $this->controlAccess('module_edit');
94
        $this->module->setSettings('twig', $this->getSubmitted());
95
        $this->redirect('', $this->text('Settings have been updated'), 'success');
96
    }
97
98
    /**
99
     * Render and output the module settings page
100
     */
101
    protected function outputEditSettings()
102
    {
103
        $this->output('twig|settings');
104
    }
105
106
}
107