|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Language detector |
|
5
|
|
|
* @author Iurii Makukh <[email protected]> |
|
6
|
|
|
* @copyright Copyright (c) 2015, Iurii Makukh |
|
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace gplcart\modules\langdetect\controllers; |
|
11
|
|
|
|
|
12
|
|
|
use gplcart\core\controllers\backend\Controller; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Handles incoming requests and outputs data related to Language detector module |
|
16
|
|
|
*/ |
|
17
|
|
|
class Settings extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Route page callback to display the module settings page |
|
21
|
|
|
*/ |
|
22
|
|
|
public function editSettings() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->setTitleEditSettings(); |
|
25
|
|
|
$this->setBreadcrumbEditSettings(); |
|
26
|
|
|
|
|
27
|
|
|
$this->setData('languages', $this->getLanguagesSettings()); |
|
28
|
|
|
$this->setData('settings', $this->module->getSettings('langdetect')); |
|
29
|
|
|
|
|
30
|
|
|
$this->submitSettings(); |
|
31
|
|
|
$this->outputEditSettings(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Returns an array of languages |
|
36
|
|
|
* @return array |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function getLanguagesSettings() |
|
39
|
|
|
{ |
|
40
|
|
|
$languages = $this->language->getList(); |
|
41
|
|
|
return gplcart_array_split($languages, 6); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Set title on the module settings page |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function setTitleEditSettings() |
|
48
|
|
|
{ |
|
49
|
|
|
$title = $this->text('Edit %name settings', array('%name' => $this->text('Language detector'))); |
|
50
|
|
|
$this->setTitle($title); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Set breadcrumbs on the module settings page |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function setBreadcrumbEditSettings() |
|
57
|
|
|
{ |
|
58
|
|
|
$breadcrumbs = array(); |
|
59
|
|
|
|
|
60
|
|
|
$breadcrumbs[] = array( |
|
61
|
|
|
'text' => $this->text('Dashboard'), |
|
62
|
|
|
'url' => $this->url('admin') |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
$breadcrumbs[] = array( |
|
66
|
|
|
'text' => $this->text('Modules'), |
|
67
|
|
|
'url' => $this->url('admin/module/list') |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$this->setBreadcrumbs($breadcrumbs); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Saves the submitted settings |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function submitSettings() |
|
77
|
|
|
{ |
|
78
|
|
|
if ($this->isPosted('save') && $this->validateSettings()) { |
|
79
|
|
|
$this->updateSettings(); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Validate submitted module settings |
|
85
|
|
|
* @return bool |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function validateSettings() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->setSubmitted('settings'); |
|
90
|
|
|
return !$this->hasErrors(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Update module settings |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function updateSettings() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->controlAccess('module_edit'); |
|
99
|
|
|
$this->module->setSettings('langdetect', $this->getSubmitted()); |
|
100
|
|
|
$this->redirect('', $this->text('Settings have been updated'), 'success'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Render and output the module settings page |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function outputEditSettings() |
|
107
|
|
|
{ |
|
108
|
|
|
$this->output('langdetect|settings'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|