|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Mobile |
|
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\mobile\controllers; |
|
11
|
|
|
|
|
12
|
|
|
use gplcart\core\controllers\backend\Controller; |
|
13
|
|
|
use gplcart\core\models\ImageStyle; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Handles incoming requests and outputs data related to Mobile theme settings |
|
17
|
|
|
*/ |
|
18
|
|
|
class Settings extends Controller |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Image style model instance |
|
23
|
|
|
* @var \gplcart\core\models\ImageStyle $image_style |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $image_style; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Settings constructor. |
|
29
|
|
|
* @param ImageStyle $image_style |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(ImageStyle $image_style) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct(); |
|
34
|
|
|
|
|
35
|
|
|
$this->image_style = $image_style; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Displays the module settings page |
|
40
|
|
|
*/ |
|
41
|
|
|
public function editSettings() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->setTitleEditSettings(); |
|
44
|
|
|
$this->setBreadcrumbEditSettings(); |
|
45
|
|
|
|
|
46
|
|
|
$this->setData('imagestyles', $this->image_style->getList()); |
|
47
|
|
|
$this->setData('settings', $this->module->getSettings('mobile')); |
|
48
|
|
|
$this->setData('imagestyle_fields', $this->getImageStyleFieldsSettings()); |
|
49
|
|
|
|
|
50
|
|
|
$this->submitSettings(); |
|
51
|
|
|
$this->outputEditSettings(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns an array of image style settings keys and their corresponding field labels |
|
56
|
|
|
* @return array |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function getImageStyleFieldsSettings() |
|
59
|
|
|
{ |
|
60
|
|
|
return array( |
|
61
|
|
|
'image_style_category' => $this->text('Category page'), |
|
62
|
|
|
'image_style_category_child' => $this->text('Category page (child)'), |
|
63
|
|
|
'image_style_product' => $this->text('Product page'), |
|
64
|
|
|
'image_style_page' => $this->text('Page'), |
|
65
|
|
|
'image_style_product_grid' => $this->text('Product catalog (grid)'), |
|
66
|
|
|
'image_style_product_list' => $this->text('Product catalog (list)'), |
|
67
|
|
|
'image_style_cart' => $this->text('Cart'), |
|
68
|
|
|
'image_style_option' => $this->text('Product option'), |
|
69
|
|
|
'image_style_collection_file' => $this->text('File collection (banners)'), |
|
70
|
|
|
'image_style_collection_page' => $this->text('Page collection (news/articles)'), |
|
71
|
|
|
'image_style_collection_product' => $this->text('Product collection (featured products)'), |
|
72
|
|
|
'mobile_image_style_popup' => $this->text('Popup image'), |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Saves the submitted settings |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function submitSettings() |
|
80
|
|
|
{ |
|
81
|
|
|
if ($this->isPosted('reset')) { |
|
82
|
|
|
$this->resetSettings(); |
|
83
|
|
|
} else if ($this->isPosted('save') && $this->validateSettings()) { |
|
84
|
|
|
$this->updateSettings(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Resets module settings to default values |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function resetSettings() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->controlAccess('module_edit'); |
|
94
|
|
|
$this->module->setSettings('mobile', array()); |
|
95
|
|
|
$this->redirect('', $this->text('Settings have been reset to default values'), 'success'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Updates module settings with an array of submitted values |
|
100
|
|
|
*/ |
|
101
|
|
|
protected function updateSettings() |
|
102
|
|
|
{ |
|
103
|
|
|
$this->controlAccess('module_edit'); |
|
104
|
|
|
$this->module->setSettings('mobile', array_filter($this->getSubmitted())); |
|
105
|
|
|
$this->redirect('', $this->text('Settings have been updated'), 'success'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Validates an array of submitted settings |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function validateSettings() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->setSubmitted('settings'); |
|
114
|
|
|
$this->validateElement('catalog_limit', 'numeric'); |
|
115
|
|
|
$this->validateElement('catalog_limit', 'length', array(1, 2)); |
|
116
|
|
|
|
|
117
|
|
|
return !$this->hasErrors(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Sets bread crumbs on the module settings page |
|
122
|
|
|
*/ |
|
123
|
|
|
protected function setBreadcrumbEditSettings() |
|
124
|
|
|
{ |
|
125
|
|
|
$breadcrumbs = array(); |
|
126
|
|
|
|
|
127
|
|
|
$breadcrumbs[] = array( |
|
128
|
|
|
'text' => $this->text('Dashboard'), |
|
129
|
|
|
'url' => $this->url('admin') |
|
130
|
|
|
); |
|
131
|
|
|
|
|
132
|
|
|
$breadcrumbs[] = array( |
|
133
|
|
|
'text' => $this->text('Modules'), |
|
134
|
|
|
'url' => $this->url('admin/module/list') |
|
135
|
|
|
); |
|
136
|
|
|
|
|
137
|
|
|
$this->setBreadcrumbs($breadcrumbs); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Renders the module settings page templates |
|
142
|
|
|
*/ |
|
143
|
|
|
protected function outputEditSettings() |
|
144
|
|
|
{ |
|
145
|
|
|
$this->output('mobile|settings'); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Sets titles on the module settings page |
|
150
|
|
|
*/ |
|
151
|
|
|
protected function setTitleEditSettings() |
|
152
|
|
|
{ |
|
153
|
|
|
$this->setTitle($this->text('Edit %name settings', array('%name' => $this->text('Mobile')))); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
|