1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Divine CMS - Open source CMS for widespread use. |
4
|
|
|
Copyright (c) 2019 Mykola Burakov ([email protected]) |
5
|
|
|
|
6
|
|
|
See SOURCE.txt for other and additional information. |
7
|
|
|
|
8
|
|
|
This file is part of Divine CMS. |
9
|
|
|
|
10
|
|
|
This program is free software: you can redistribute it and/or modify |
11
|
|
|
it under the terms of the GNU General Public License as published by |
12
|
|
|
the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
(at your option) any later version. |
14
|
|
|
|
15
|
|
|
This program is distributed in the hope that it will be useful, |
16
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
GNU General Public License for more details. |
19
|
|
|
|
20
|
|
|
You should have received a copy of the GNU General Public License |
21
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
22
|
|
|
|
23
|
|
|
class ModelDesignLayout extends \Divine\Engine\Core\Model |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
public function addLayout($data) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->db->query(" |
28
|
|
|
INSERT INTO layout |
29
|
|
|
SET name = '" . $this->db->escape($data['name']) . "' |
30
|
|
|
"); |
31
|
|
|
|
32
|
|
|
$layout_id = $this->db->getLastId(); |
33
|
|
|
|
34
|
|
|
if (isset($data['layout_route'])) { |
35
|
|
|
foreach ($data['layout_route'] as $layout_route) { |
36
|
|
|
$this->db->query(" |
37
|
|
|
INSERT INTO layout_route |
38
|
|
|
SET layout_id = '" . (int)$layout_id . "', |
39
|
|
|
route = '" . $this->db->escape($layout_route['route']) . "' |
40
|
|
|
"); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if (isset($data['layout_module'])) { |
45
|
|
|
foreach ($data['layout_module'] as $layout_module) { |
46
|
|
|
$this->db->query(" |
47
|
|
|
INSERT INTO layout_module |
48
|
|
|
SET layout_id = '" . (int)$layout_id . "', |
49
|
|
|
code = '" . $this->db->escape($layout_module['code']) . "', |
50
|
|
|
position = '" . $this->db->escape($layout_module['position']) . "', |
51
|
|
|
sort_order = '" . (int)$layout_module['sort_order'] . "' |
52
|
|
|
"); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $layout_id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function editLayout($layout_id, $data) |
60
|
|
|
{ |
61
|
|
|
$this->db->query(" |
62
|
|
|
UPDATE layout |
63
|
|
|
SET name = '" . $this->db->escape($data['name']) . "' |
64
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
65
|
|
|
"); |
66
|
|
|
|
67
|
|
|
$this->db->query(" |
68
|
|
|
DELETE |
69
|
|
|
FROM layout_route |
70
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
71
|
|
|
"); |
72
|
|
|
|
73
|
|
|
if (isset($data['layout_route'])) { |
74
|
|
|
foreach ($data['layout_route'] as $layout_route) { |
75
|
|
|
$this->db->query(" |
76
|
|
|
INSERT INTO layout_route |
77
|
|
|
SET layout_id = '" . (int)$layout_id . "', |
78
|
|
|
route = '" . $this->db->escape($layout_route['route']) . "' |
79
|
|
|
"); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->db->query(" |
84
|
|
|
DELETE |
85
|
|
|
FROM layout_module |
86
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
87
|
|
|
"); |
88
|
|
|
|
89
|
|
|
if (isset($data['layout_module'])) { |
90
|
|
|
foreach ($data['layout_module'] as $layout_module) { |
91
|
|
|
$this->db->query(" |
92
|
|
|
INSERT INTO layout_module |
93
|
|
|
SET layout_id = '" . (int)$layout_id . "', |
94
|
|
|
code = '" . $this->db->escape($layout_module['code']) . "', |
95
|
|
|
position = '" . $this->db->escape($layout_module['position']) . "', |
96
|
|
|
sort_order = '" . (int)$layout_module['sort_order'] . "' |
97
|
|
|
"); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function deleteLayout($layout_id) |
103
|
|
|
{ |
104
|
|
|
$this->db->query(" |
105
|
|
|
DELETE |
106
|
|
|
FROM layout |
107
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
108
|
|
|
"); |
109
|
|
|
$this->db->query(" |
110
|
|
|
DELETE |
111
|
|
|
FROM layout_route |
112
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
113
|
|
|
"); |
114
|
|
|
$this->db->query(" |
115
|
|
|
DELETE |
116
|
|
|
FROM layout_module |
117
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
118
|
|
|
"); |
119
|
|
|
$this->db->query(" |
120
|
|
|
DELETE |
121
|
|
|
FROM category_to_layout |
122
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
123
|
|
|
"); |
124
|
|
|
$this->db->query(" |
125
|
|
|
DELETE |
126
|
|
|
FROM product_to_layout |
127
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
128
|
|
|
"); |
129
|
|
|
$this->db->query(" |
130
|
|
|
DELETE |
131
|
|
|
FROM information_to_layout |
132
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
133
|
|
|
"); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function getLayout($layout_id) |
137
|
|
|
{ |
138
|
|
|
$query = $this->db->query(" |
139
|
|
|
SELECT DISTINCT * |
140
|
|
|
FROM layout |
141
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
142
|
|
|
"); |
143
|
|
|
|
144
|
|
|
return $query->row; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function getLayouts($data = array()) |
148
|
|
|
{ |
149
|
|
|
$sql = " |
|
|
|
|
150
|
|
|
SELECT * |
151
|
|
|
FROM layout |
152
|
|
|
"; |
153
|
|
|
|
154
|
|
|
$sort_data = array('name'); |
155
|
|
|
|
156
|
|
|
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
157
|
|
|
$sql .= " ORDER BY " . $data['sort']; |
|
|
|
|
158
|
|
|
} else { |
159
|
|
|
$sql .= " ORDER BY name"; |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if (isset($data['order']) && ($data['order'] == 'DESC')) { |
163
|
|
|
$sql .= " DESC"; |
|
|
|
|
164
|
|
|
} else { |
165
|
|
|
$sql .= " ASC"; |
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
if (isset($data['start']) || isset($data['limit'])) { |
169
|
|
|
if ($data['start'] < 0) { |
170
|
|
|
$data['start'] = 0; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if ($data['limit'] < 1) { |
174
|
|
|
$data['limit'] = 20; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
|
|
|
|
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
$query = $this->db->query($sql); |
181
|
|
|
|
182
|
|
|
return $query->rows; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function getLayoutRoutes($layout_id) |
186
|
|
|
{ |
187
|
|
|
$query = $this->db->query(" |
188
|
|
|
SELECT * |
189
|
|
|
FROM layout_route |
190
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
191
|
|
|
"); |
192
|
|
|
|
193
|
|
|
return $query->rows; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function getLayoutModules($layout_id) |
197
|
|
|
{ |
198
|
|
|
$query = $this->db->query(" |
199
|
|
|
SELECT * |
200
|
|
|
FROM layout_module |
201
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
202
|
|
|
ORDER BY position ASC, sort_order ASC |
203
|
|
|
"); |
204
|
|
|
|
205
|
|
|
return $query->rows; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function getTotalLayouts() |
209
|
|
|
{ |
210
|
|
|
$query = $this->db->query(" |
|
|
|
|
211
|
|
|
SELECT COUNT(*) AS total |
212
|
|
|
FROM layout |
213
|
|
|
"); |
214
|
|
|
|
215
|
|
|
return $query->row['total']; |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.