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