-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
240 lines (221 loc) · 6.73 KB
/
db.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php
/**
* Class plugins_gmap_db
*/
class plugins_homebanner_db
{
/**
* @param $config
* @param array $params
* @return mixed|null
*/
public function fetchData($config, array $params = [])
{
$sql = '';
if(is_array($config)) {
if($config['context'] === 'all') {
switch ($config['type']) {
case 'slides':
$sql = 'SELECT
id_slide,
link_url_slide,
link_label_slide,
link_title_slide,
img_slide,
title_slide,
desc_slide,
order_slide
FROM mc_homebanner as sl
LEFT JOIN mc_homebanner_content as slc USING(id_slide)
LEFT JOIN mc_lang as l USING(id_lang)
WHERE id_lang = :default_lang
ORDER BY order_slide';
break;
case 'homeSlides':
$sql = 'SELECT
id_slide,
link_url_slide,
link_label_slide,
link_title_slide,
blank_slide,
img_slide,
title_slide,
desc_slide,
order_slide
FROM mc_homebanner as sl
LEFT JOIN mc_homebanner_content as slc USING(id_slide)
LEFT JOIN mc_lang as l USING(id_lang)
WHERE iso_lang = :lang
AND published_slide = 1
ORDER BY order_slide';
break;
case 'slide':
$sql = 'SELECT a.*,c.*
FROM mc_homebanner AS a
JOIN mc_homebanner_content AS c USING(id_slide)
JOIN mc_lang AS lang ON(c.id_lang = lang.id_lang)
WHERE c.id_lang = :default_lang';
break;
case 'slideContent':
$sql = 'SELECT a.*,c.*
FROM mc_homebanner AS a
JOIN mc_homebanner_content AS c USING(id_slide)
JOIN mc_lang AS lang ON(c.id_lang = lang.id_lang)
WHERE c.id_slide = :id';
break;
case 'img':
$sql = 'SELECT s.id_slide, s.img_slide
FROM mc_homebanner AS s WHERE s.img_slide IS NOT NULL';
break;
case 'WSslides':
$sql = 'SELECT
id_slide,
slc.link_url_slide,
slc.link_label_slide,
slc.link_title_slide,
sl.img_slide,
slc.title_slide,
slc.desc_slide,
slc.id_lang,
l.iso_lang,l.default_lang
FROM mc_homebanner as sl
JOIN mc_homebanner_content as slc USING(id_slide)
JOIN mc_lang as l USING(id_lang)';
break;
}
return $sql ? component_routing_db::layer()->fetchAll($sql,$params) : null;
}
elseif($config['context'] === 'one') {
switch ($config['type']) {
case 'slideContent':
$sql = 'SELECT * FROM mc_homebanner_content WHERE id_slide = :id AND id_lang = :id_lang';
break;
case 'lastSlide':
$sql = 'SELECT * FROM mc_homebanner ORDER BY id_slide DESC LIMIT 0,1';
break;
case 'img':
$sql = 'SELECT * FROM mc_homebanner WHERE id_slide = :id';
break;
}
return $sql ? component_routing_db::layer()->fetch($sql,$params) : null;
}
}
}
/**
* @param $config
* @param array $params
* @return bool|string
*/
public function insert($config, $params = array())
{
if (!is_array($config)) return '$config must be an array';
$sql = '';
switch ($config['type']) {
case 'slide':
$sql = "INSERT INTO mc_homebanner(img_slide, order_slide)
SELECT '', COUNT(id_slide) FROM mc_homebanner";
break;
case 'slideContent':
$sql = 'INSERT INTO mc_homebanner_content(id_slide, id_lang, title_slide, desc_slide, link_url_slide, link_label_slide, link_title_slide, blank_slide, published_slide)
VALUES (:id_slide, :id_lang, :title_slide, :desc_slide, :link_url_slide, :link_label_slide, :link_title_slide, :blank_slide, :published_slide)';
break;
case 'content':
$sql = 'INSERT INTO mc_homebanner_content(id_slide, id_lang, title_slide, desc_slide, link_url_slide, link_label_slide, link_title_slide, blank_slide, published_slide)
VALUES (:id_slide, :id_lang, :title_slide, :desc_slide, :link_url_slide, :link_label_slide, :link_title_slide, :blank_slide, :published_slide)';
break;
case 'img':
$sql = 'UPDATE mc_homebanner
SET img_slide = :img_slide
WHERE id_slide = :id_slide';
break;
}
if($sql === '') return 'Unknown request asked';
try {
component_routing_db::layer()->insert($sql,$params);
return true;
}
catch (Exception $e) {
return 'Exception reçue : '.$e->getMessage();
}
}
/**
* @param $config
* @param array $params
* @return bool|string
*/
public function update($config, $params = array())
{
if (!is_array($config)) return '$config must be an array';
$sql = '';
switch ($config['type']) {
case 'slideContent':
$sql = 'UPDATE mc_homebanner_content
SET
title_slide = :title_slide,
desc_slide = :desc_slide,
link_url_slide = :link_url_slide,
link_label_slide = :link_label_slide,
link_title_slide = :link_title_slide,
blank_slide = :blank_slide,
published_slide = :published_slide
WHERE id_slide_content = :id
AND id_lang = :id_lang';
break;
case 'content':
$sql = 'UPDATE mc_homebanner_content
SET
title_slide = :title_slide,
desc_slide = :desc_slide,
link_url_slide = :link_url_slide,
link_label_slide = :link_label_slide,
link_title_slide = :link_title_slide,
blank_slide = :blank_slide,
published_slide = :published_slide
WHERE id_slide = :id_slide
AND id_lang = :id_lang';
break;
case 'img':
$sql = 'UPDATE mc_homebanner
SET
img_slide = :img
WHERE id_slide = :id';
break;
case 'order':
$sql = 'UPDATE mc_homebanner
SET order_slide = :order_slide
WHERE id_slide = :id_slide';
break;
}
if($sql === '') return 'Unknown request asked';
try {
component_routing_db::layer()->update($sql,$params);
return true;
}
catch (Exception $e) {
return 'Exception reçue : '.$e->getMessage();
}
}
/**
* @param $config
* @param array $params
* @return bool|string
*/
protected function delete($config, $params = array()) {
if (!is_array($config)) return '$config must be an array';
$sql = '';
switch ($config['type']) {
case 'slide':
$sql = 'DELETE FROM mc_homebanner
WHERE id_slide = :id';
break;
}
if($sql === '') return 'Unknown request asked';
try {
component_routing_db::layer()->delete($sql,$params);
return true;
}
catch (Exception $e) {
return 'Exception reçue : '.$e->getMessage();
}
}
}