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; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Handles incoming requests and outputs data related to Dev 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->getModuleSettings('dev')); |
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
|
|
|
$this->setTitle($this->text('Edit %name settings', array('%name' => $this->text('Dev')))); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Set breadcrumbs on the module settings page |
44
|
|
|
*/ |
45
|
|
|
protected function setBreadcrumbEditSettings() |
46
|
|
|
{ |
47
|
|
|
$breadcrumbs = array(); |
48
|
|
|
|
49
|
|
|
$breadcrumbs[] = array( |
50
|
|
|
'text' => $this->text('Dashboard'), |
51
|
|
|
'url' => $this->url('admin') |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$breadcrumbs[] = array( |
55
|
|
|
'text' => $this->text('Modules'), |
56
|
|
|
'url' => $this->url('admin/module/list') |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$this->setBreadcrumbs($breadcrumbs); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Saves the submitted settings |
64
|
|
|
*/ |
65
|
|
|
protected function submitSettings() |
66
|
|
|
{ |
67
|
|
|
if ($this->isPosted('save') && $this->validateSettings()) { |
68
|
|
|
$this->updateSettings(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Validate submitted module settings |
74
|
|
|
*/ |
75
|
|
|
protected function validateSettings() |
76
|
|
|
{ |
77
|
|
|
$this->setSubmitted('settings'); |
78
|
|
|
return !$this->hasErrors(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Update module settings |
83
|
|
|
*/ |
84
|
|
|
protected function updateSettings() |
85
|
|
|
{ |
86
|
|
|
$this->controlAccess('module_edit'); |
87
|
|
|
$this->module->setSettings('dev', $this->getSubmitted()); |
88
|
|
|
$this->redirect('', $this->text('Settings have been updated'), 'success'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Render and output the module settings page |
93
|
|
|
*/ |
94
|
|
|
protected function outputEditSettings() |
95
|
|
|
{ |
96
|
|
|
$this->output('dev|settings'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|