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->getDevModuleSettings()); |
37
|
|
|
|
38
|
|
|
$this->submitSettings(); |
39
|
|
|
$this->outputEditSettings(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns an array of module settings |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
protected function getDevModuleSettings() |
47
|
|
|
{ |
48
|
|
|
$settings = $this->getModuleSettings('dev'); |
49
|
|
|
$settings['exception'] = $this->config('error_to_exception', false); |
50
|
|
|
return $settings; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Set title on the module settings page |
55
|
|
|
*/ |
56
|
|
|
protected function setTitleEditSettings() |
57
|
|
|
{ |
58
|
|
|
$this->setTitle($this->text('Edit %name settings', array('%name' => $this->text('Dev')))); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Set breadcrumbs on the module settings page |
63
|
|
|
*/ |
64
|
|
|
protected function setBreadcrumbEditSettings() |
65
|
|
|
{ |
66
|
|
|
$breadcrumbs = array(); |
67
|
|
|
|
68
|
|
|
$breadcrumbs[] = array( |
69
|
|
|
'text' => $this->text('Dashboard'), |
70
|
|
|
'url' => $this->url('admin') |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$breadcrumbs[] = array( |
74
|
|
|
'text' => $this->text('Modules'), |
75
|
|
|
'url' => $this->url('admin/module/list') |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$this->setBreadcrumbs($breadcrumbs); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Saves the submitted settings |
83
|
|
|
*/ |
84
|
|
|
protected function submitSettings() |
85
|
|
|
{ |
86
|
|
|
if ($this->isPosted('save') && $this->validateSettings()) { |
87
|
|
|
$this->updateSettings(); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Validate submitted module settings |
93
|
|
|
*/ |
94
|
|
|
protected function validateSettings() |
95
|
|
|
{ |
96
|
|
|
$this->setSubmitted('settings'); |
97
|
|
|
return !$this->hasErrors(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Update module settings |
102
|
|
|
*/ |
103
|
|
|
protected function updateSettings() |
104
|
|
|
{ |
105
|
|
|
$this->controlAccess('module_edit'); |
106
|
|
|
|
107
|
|
|
$submitted = $this->getSubmitted(); |
108
|
|
|
$this->config->set('error_to_exception', !empty($submitted['exception'])); |
109
|
|
|
unset($submitted['exception']); |
110
|
|
|
|
111
|
|
|
$this->module->setSettings('dev', $submitted); |
112
|
|
|
$this->redirect('', $this->text('Settings have been updated'), 'success'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Render and output the module settings page |
117
|
|
|
*/ |
118
|
|
|
protected function outputEditSettings() |
119
|
|
|
{ |
120
|
|
|
$this->output('dev|settings'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
} |
124
|
|
|
|