1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Device detector |
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\device\controllers; |
11
|
|
|
|
12
|
|
|
use gplcart\core\controllers\backend\Controller; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Handles incoming requests and outputs data related to Device 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('stores', $this->store->getList()); |
29
|
|
|
$this->setData('settings', $this->module->getSettings('device')); |
30
|
|
|
$this->setData('themes', $this->getFrontendThemesSettings()); |
31
|
|
|
|
32
|
|
|
$this->submitSettings(); |
33
|
|
|
$this->outputEditSettings(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Returns an array of frontend themes |
38
|
|
|
*/ |
39
|
|
|
protected function getFrontendThemesSettings() |
40
|
|
|
{ |
41
|
|
|
$themes = $this->module->getByType('theme', true); |
42
|
|
|
unset($themes[$this->theme_backend]); |
43
|
|
|
return $themes; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Set title on the module settings page |
48
|
|
|
*/ |
49
|
|
|
protected function setTitleEditSettings() |
50
|
|
|
{ |
51
|
|
|
$title = $this->text('Edit %name settings', array('%name' => $this->text('Device detector'))); |
52
|
|
|
$this->setTitle($title); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Set breadcrumbs on the module settings page |
57
|
|
|
*/ |
58
|
|
|
protected function setBreadcrumbEditSettings() |
59
|
|
|
{ |
60
|
|
|
$breadcrumbs = array(); |
61
|
|
|
|
62
|
|
|
$breadcrumbs[] = array( |
63
|
|
|
'text' => $this->text('Dashboard'), |
64
|
|
|
'url' => $this->url('admin') |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$breadcrumbs[] = array( |
68
|
|
|
'text' => $this->text('Modules'), |
69
|
|
|
'url' => $this->url('admin/module/list') |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$this->setBreadcrumbs($breadcrumbs); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Saves the submitted settings |
77
|
|
|
*/ |
78
|
|
|
protected function submitSettings() |
79
|
|
|
{ |
80
|
|
|
if ($this->isPosted('save') && $this->validateSettings()) { |
81
|
|
|
$this->updateSettings(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Validate submitted module settings |
87
|
|
|
*/ |
88
|
|
|
protected function validateSettings() |
89
|
|
|
{ |
90
|
|
|
$this->setSubmitted('settings'); |
91
|
|
|
return !$this->hasErrors(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Update module settings |
96
|
|
|
*/ |
97
|
|
|
protected function updateSettings() |
98
|
|
|
{ |
99
|
|
|
$this->controlAccess('module_edit'); |
100
|
|
|
$this->module->setSettings('device', $this->getSubmitted()); |
101
|
|
|
$this->redirect('', $this->text('Settings have been updated'), 'success'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Render and output the module settings page |
106
|
|
|
*/ |
107
|
|
|
protected function outputEditSettings() |
108
|
|
|
{ |
109
|
|
|
$this->output('device|settings'); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|