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 ModelDesignSticker extends \Divine\Engine\Core\Model |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
public function addSticker($data) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->db->query(" |
28
|
|
|
INSERT INTO sticker |
29
|
|
|
SET name = '" . $this->db->escape($data['name']) . "', |
30
|
|
|
status = '" . (int)$data['status'] . "' |
31
|
|
|
"); |
32
|
|
|
|
33
|
|
|
$sticker_id = $this->db->getLastId(); |
34
|
|
|
|
35
|
|
|
if (isset($data['image'])) { |
36
|
|
|
$this->db->query(" |
37
|
|
|
UPDATE sticker |
38
|
|
|
SET image = '" . $this->db->escape(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8')) . "' |
39
|
|
|
WHERE sticker_id = '" . (int)$sticker_id . "' |
40
|
|
|
"); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function editSticker($sticker_id, $data) |
45
|
|
|
{ |
46
|
|
|
$this->db->query(" |
47
|
|
|
UPDATE sticker |
48
|
|
|
SET name = '" . $this->db->escape($data['name']) . "', |
49
|
|
|
status = '" . (int)$data['status'] . "' |
50
|
|
|
WHERE sticker_id = '" . (int)$sticker_id . "' |
51
|
|
|
"); |
52
|
|
|
|
53
|
|
|
if (isset($data['image'])) { |
54
|
|
|
$this->db->query(" |
55
|
|
|
UPDATE sticker |
56
|
|
|
SET image = '" . $this->db->escape(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8')) . "' |
57
|
|
|
WHERE sticker_id = '" . (int)$sticker_id . "' |
58
|
|
|
"); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function deleteSticker($sticker_id) |
63
|
|
|
{ |
64
|
|
|
$this->db->query(" |
65
|
|
|
DELETE |
66
|
|
|
FROM sticker |
67
|
|
|
WHERE sticker_id = '" . (int)$sticker_id . "' |
68
|
|
|
"); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getSticker($sticker_id) |
72
|
|
|
{ |
73
|
|
|
$query = $this->db->query(" |
74
|
|
|
SELECT DISTINCT * |
75
|
|
|
FROM sticker |
76
|
|
|
WHERE sticker_id = '" . (int)$sticker_id . "' |
77
|
|
|
"); |
78
|
|
|
|
79
|
|
|
return $query->row; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getStickers($data = array()) |
83
|
|
|
{ |
84
|
|
|
$sql = " |
|
|
|
|
85
|
|
|
SELECT * |
86
|
|
|
FROM sticker |
87
|
|
|
"; |
88
|
|
|
|
89
|
|
|
$sort_data = array( |
90
|
|
|
'name', |
91
|
|
|
'status' |
92
|
|
|
); |
93
|
|
|
|
94
|
|
|
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
95
|
|
|
$sql .= " ORDER BY " . $data['sort']; |
|
|
|
|
96
|
|
|
} else { |
97
|
|
|
$sql .= " ORDER BY name"; |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if (isset($data['order']) && ($data['order'] == 'DESC')) { |
101
|
|
|
$sql .= " DESC"; |
|
|
|
|
102
|
|
|
} else { |
103
|
|
|
$sql .= " ASC"; |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if (isset($data['start']) || isset($data['limit'])) { |
107
|
|
|
if ($data['start'] < 0) { |
108
|
|
|
$data['start'] = 0; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
if ($data['limit'] < 1) { |
112
|
|
|
$data['limit'] = 20; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$query = $this->db->query($sql); |
119
|
|
|
|
120
|
|
|
return $query->rows; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function getStickersProduct($data = array()) |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
$sql = " |
|
|
|
|
126
|
|
|
SELECT * |
127
|
|
|
FROM sticker |
128
|
|
|
"; |
129
|
|
|
|
130
|
|
|
$query = $this->db->query($sql); |
131
|
|
|
|
132
|
|
|
return $query->rows; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function getProductSticker($product_id) |
136
|
|
|
{ |
137
|
|
|
$stickers = array(); |
138
|
|
|
|
139
|
|
|
$query = $this->db->query(" |
140
|
|
|
SELECT sticker_id, |
141
|
|
|
position |
142
|
|
|
FROM product_to_sticker |
143
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
144
|
|
|
GROUP BY position |
145
|
|
|
"); |
146
|
|
|
|
147
|
|
|
foreach ($query->rows as $sticker) { |
148
|
|
|
$stickers[$sticker['position']] = $sticker['sticker_id']; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $stickers; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function getTotalStickers() |
155
|
|
|
{ |
156
|
|
|
$query = $this->db->query(" |
|
|
|
|
157
|
|
|
SELECT COUNT(*) AS total |
158
|
|
|
FROM sticker |
159
|
|
|
"); |
160
|
|
|
|
161
|
|
|
return $query->row['total']; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function validateDelete($selected) |
165
|
|
|
{ |
166
|
|
|
$query = $this->db->query(" |
|
|
|
|
167
|
|
|
SELECT COUNT(*) AS total |
168
|
|
|
FROM product_to_sticker |
169
|
|
|
WHERE sticker_id IN (". $selected .") |
|
|
|
|
170
|
|
|
"); |
171
|
|
|
|
172
|
|
|
return $query->row['total']; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
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.