1
|
|
|
<?php |
2
|
|
|
use cmsemail\email; |
3
|
|
|
use CMSFactory\ModuleSettings; |
4
|
|
|
use core\models\Route; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @property CI_DB_active_record $db |
8
|
|
|
* @property DX_Auth $dx_auth |
9
|
|
|
*/ |
10
|
|
|
class Wishlist_model extends CI_Model |
11
|
|
|
{ |
|
|
|
|
12
|
|
|
|
13
|
|
|
public function __construct() { |
14
|
|
|
parent::__construct(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Get module settings |
19
|
|
|
* @return array |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
public function getSettings() { |
22
|
|
|
|
23
|
|
|
return ModuleSettings::ofModule('wishlist')->get(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Save settings |
28
|
|
|
* @param array $settings |
29
|
|
|
* @return boolean |
|
|
|
|
30
|
|
|
*/ |
31
|
|
|
public function setSettings($settings) { |
32
|
|
|
|
33
|
|
|
return ModuleSettings::ofModule('wishlist')->set($settings); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* get wish lists |
38
|
|
|
* |
39
|
|
|
* @param integer|null $userID filter by user id |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public function getWishLists($userID = NULL) { |
43
|
|
|
if (!$userID) { |
44
|
|
|
$userID = $this->dx_auth->get_user_id(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->db |
48
|
|
|
->where('user_id', $userID) |
49
|
|
|
->get('mod_wish_list') |
50
|
|
|
->result_array(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* get all users |
55
|
|
|
* |
56
|
|
|
* @return array|boolean |
57
|
|
|
*/ |
58
|
|
|
public function getAllUsers() { |
59
|
|
|
$users = $this->db |
60
|
|
|
->order_by('user_name') |
61
|
|
|
->get('mod_wish_list_users'); |
62
|
|
|
|
63
|
|
|
if ($users) { |
64
|
|
|
return $users->result_array(); |
65
|
|
|
} else { |
66
|
|
|
return FALSE; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* get user by id |
72
|
|
|
* |
73
|
|
|
* @param integer $id |
74
|
|
|
* @return array|bool |
75
|
|
|
*/ |
76
|
|
|
public function getUserByID($id) { |
77
|
|
|
$query = $this->db |
78
|
|
|
->where('id', $id) |
79
|
|
|
->get('mod_wish_list_users'); |
80
|
|
|
|
81
|
|
|
if ($query) { |
82
|
|
|
return $query->row_array(); |
83
|
|
|
} else { |
84
|
|
|
return FALSE; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* get wish list by user id |
90
|
|
|
* |
91
|
|
|
* @param integer $user_id |
92
|
|
|
* @param array $access |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
public function getWLsByUserId($user_id, $access = ['shared']) { |
96
|
|
|
return $this->db |
97
|
|
|
->where('user_id', $user_id) |
98
|
|
|
->where_in('access', $access) |
99
|
|
|
->get('mod_wish_list') |
100
|
|
|
->result_array(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* get user wish list |
105
|
|
|
* |
106
|
|
|
* @param integer $user_id |
107
|
|
|
* @param integer $list_id |
108
|
|
|
* @param array $access |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
|
|
public function getUserWishList($user_id, $list_id, $access = ['public', 'shared', 'private']) { |
112
|
|
|
$locale = \MY_Controller::getCurrentLocale(); |
113
|
|
|
$query = $this->db |
114
|
|
|
->where('mod_wish_list.user_id', $user_id) |
115
|
|
|
->where_in('access', $access) |
116
|
|
|
->where('mod_wish_list.id', $list_id) |
117
|
|
|
->where('shop_products_i18n.locale', $locale) |
118
|
|
|
->where('shop_product_variants_i18n.locale', $locale) |
119
|
|
|
->join('mod_wish_list_products', 'mod_wish_list_products.wish_list_id=mod_wish_list.id') |
120
|
|
|
->join('shop_product_variants', 'shop_product_variants.id=mod_wish_list_products.variant_id') |
121
|
|
|
->join('shop_product_variants_i18n', 'shop_product_variants_i18n.id=shop_product_variants.id') |
122
|
|
|
->join('shop_products', 'shop_products.id=shop_product_variants.product_id') |
123
|
|
|
->join('shop_products_i18n', 'shop_products_i18n.id=shop_products.id') |
124
|
|
|
->join('route', 'route.id = shop_products.route_id') |
125
|
|
|
->get('mod_wish_list') |
126
|
|
|
->result_array(); |
127
|
|
|
|
128
|
|
|
if (!$query) { |
129
|
|
|
return $this->db |
130
|
|
|
->select('*, mod_wish_list.id AS `wish_list_id`') |
131
|
|
|
->where_in('mod_wish_list.access', $access) |
132
|
|
|
->where('mod_wish_list_products.wish_list_id', NULL) |
133
|
|
|
->where('mod_wish_list.id', $list_id) |
134
|
|
|
->where('mod_wish_list.user_id', $user_id) |
135
|
|
|
->join('mod_wish_list_products', 'mod_wish_list_products.wish_list_id=mod_wish_list.id', 'left') |
136
|
|
|
->get('mod_wish_list') |
137
|
|
|
->result_array(); |
138
|
|
|
}else{ |
|
|
|
|
139
|
|
View Code Duplication |
foreach ($query as $key => $item) { |
140
|
|
|
$query[$key]['full_url'] = Route::createRouteUrl($item['url'], $item['parent_url'], Route::TYPE_PRODUCT); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $query; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* get user wish list by hash |
150
|
|
|
* |
151
|
|
|
* @param integer $hash |
152
|
|
|
* @param array $access |
153
|
|
|
* @return array |
154
|
|
|
*/ |
155
|
|
|
public function getUserWishListByHash($hash, $access = ['public', 'shared', 'private']) { |
156
|
|
|
$locale = \MY_Controller::getCurrentLocale(); |
157
|
|
|
|
158
|
|
|
$query = $this->db->select('*, mod_wish_list.user_id as wl_user_id, shop_product_variants.mainImage as image') |
159
|
|
|
->where_in('access', $access) |
160
|
|
|
->where('mod_wish_list.hash', $hash) |
161
|
|
|
->where('shop_products_i18n.locale', $locale) |
162
|
|
|
->where('shop_product_variants_i18n.locale', $locale) |
163
|
|
|
->join('mod_wish_list_products', 'mod_wish_list_products.wish_list_id=mod_wish_list.id') |
164
|
|
|
->join('shop_product_variants', 'shop_product_variants.id=mod_wish_list_products.variant_id') |
165
|
|
|
->join('shop_product_variants_i18n', 'shop_product_variants_i18n.id=shop_product_variants.id') |
166
|
|
|
->join('shop_products', 'shop_products.id=shop_product_variants.product_id') |
167
|
|
|
->join('shop_products_i18n', 'shop_products_i18n.id=shop_products.id') |
168
|
|
|
->get('mod_wish_list') |
169
|
|
|
->result_array(); |
170
|
|
|
|
171
|
|
|
if (!$query) { |
172
|
|
|
return $this->db |
173
|
|
|
->select('*, mod_wish_list.id AS `wish_list_id`') |
174
|
|
|
->where_in('mod_wish_list.access', $access) |
175
|
|
|
->where('mod_wish_list_products.wish_list_id', NULL) |
176
|
|
|
->where('mod_wish_list.hash', $hash) |
177
|
|
|
->join('mod_wish_list_products', 'mod_wish_list_products.wish_list_id=mod_wish_list.id', 'left') |
178
|
|
|
->get('mod_wish_list') |
179
|
|
|
->result_array(); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
return $query; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* delete item from list |
187
|
|
|
* |
188
|
|
|
* @param integer $variant_id |
189
|
|
|
* @param integer $wish_list_id |
190
|
|
|
* @return boolean |
191
|
|
|
*/ |
192
|
|
|
public function deleteItem($variant_id, $wish_list_id) { |
193
|
|
|
$this->db |
194
|
|
|
->delete( |
195
|
|
|
'mod_wish_list_products', |
196
|
|
|
[ |
197
|
|
|
'variant_id' => $variant_id, |
198
|
|
|
'wish_list_id' => $wish_list_id, |
199
|
|
|
] |
200
|
|
|
); |
201
|
|
|
if ($this->db->affected_rows() == 0) { |
|
|
|
|
202
|
|
|
return FALSE; |
203
|
|
|
} else { |
204
|
|
|
return TRUE; |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* delete items by ids |
210
|
|
|
* |
211
|
|
|
* @param array $ids |
212
|
|
|
* @return array |
213
|
|
|
*/ |
214
|
|
|
public function deleteItemsByIDs($ids) { |
215
|
|
|
return $this->db->where_in('id', $ids) |
216
|
|
|
->delete('mod_wish_list_products'); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* get user wish list by id |
221
|
|
|
* |
222
|
|
|
* @param integer $user_id |
223
|
|
|
* @param array $access |
224
|
|
|
* @return array |
|
|
|
|
225
|
|
|
*/ |
226
|
|
|
public function getUserWishListsByID($user_id, $access = ['public', 'shared', 'private']) { |
227
|
|
|
$locale = \MY_Controller::getCurrentLocale(); |
228
|
|
|
$queryFirst = $this->db |
229
|
|
|
->select('*, shop_product_variants.mainImage AS `image`, mod_wish_list_products.id AS list_product_id, route.url, route.parent_url') |
230
|
|
|
->where('mod_wish_list.user_id', $user_id) |
231
|
|
|
->join('mod_wish_list_products', 'mod_wish_list_products.wish_list_id=mod_wish_list.id', 'left') |
232
|
|
|
->where_in('mod_wish_list.access', $access) |
233
|
|
|
->where('shop_products_i18n.locale', $locale) |
234
|
|
|
->where('shop_product_variants_i18n.locale', $locale) |
235
|
|
|
->join('shop_product_variants', 'shop_product_variants.id=mod_wish_list_products.variant_id') |
236
|
|
|
->join('shop_product_variants_i18n', 'shop_product_variants_i18n.id=shop_product_variants.id') |
237
|
|
|
->join('shop_products', 'shop_products.id=shop_product_variants.product_id') |
238
|
|
|
->join('route', 'route.id = shop_products.route_id') |
239
|
|
|
->join('shop_products_i18n', 'shop_products_i18n.id=shop_products.id') |
240
|
|
|
->get('mod_wish_list'); |
241
|
|
|
|
242
|
|
|
if ($queryFirst) { |
243
|
|
|
$queryFirst = $queryFirst->result_array(); |
244
|
|
|
|
245
|
|
View Code Duplication |
foreach ($queryFirst as $key => $item) { |
246
|
|
|
$queryFirst[$key]['full_url'] = Route::createRouteUrl($item['url'], $item['parent_url'], Route::TYPE_PRODUCT); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
$querySecond = $this->db |
252
|
|
|
->select('*, mod_wish_list.id AS `wish_list_id`') |
253
|
|
|
->where_in('mod_wish_list.access', $access) |
254
|
|
|
->where('mod_wish_list_products.wish_list_id', NULL) |
255
|
|
|
->where('mod_wish_list.user_id', $user_id) |
256
|
|
|
->join('mod_wish_list_products', 'mod_wish_list_products.wish_list_id=mod_wish_list.id', 'left') |
257
|
|
|
->get('mod_wish_list'); |
258
|
|
|
|
259
|
|
|
if ($querySecond) { |
260
|
|
|
$querySecond = $querySecond->result_array(); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
$arr = array_merge($queryFirst, $querySecond); |
264
|
|
|
if (count($arr) > 0) { |
265
|
|
|
return $arr; |
266
|
|
|
} else { |
267
|
|
|
return FALSE; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* delete wish list by id |
273
|
|
|
* |
274
|
|
|
* @param integer$id |
|
|
|
|
275
|
|
|
* @return boolean |
276
|
|
|
*/ |
277
|
|
|
public function delWishListById($id) { |
278
|
|
|
$this->db |
279
|
|
|
->where_in('id', $id) |
280
|
|
|
->delete('mod_wish_list'); |
281
|
|
|
return $this->db->affected_rows(); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* delete wish list products by wish list id |
286
|
|
|
* |
287
|
|
|
* @param integer $id |
288
|
|
|
* @return boolean |
289
|
|
|
*/ |
290
|
|
|
public function delWishListProductsByWLId($id) { |
291
|
|
|
$this->db->where_in('wish_list_id', (array) $id); |
292
|
|
|
$this->db->delete('mod_wish_list_products'); |
293
|
|
|
return $this->db->affected_rows(); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* get user wish list products |
298
|
|
|
* |
299
|
|
|
* @param integer $userID |
300
|
|
|
* @return array |
301
|
|
|
*/ |
302
|
|
|
public function getUserWishProducts($userID = null) { |
303
|
|
|
if (!$userID) { |
304
|
|
|
$userID = $this->dx_auth->get_user_id(); |
305
|
|
|
} |
306
|
|
|
$ID = []; |
307
|
|
|
$ids = $this->db |
308
|
|
|
->where('mod_wish_list.user_id', $userID) |
309
|
|
|
->join('mod_wish_list_products', 'mod_wish_list_products.wish_list_id=mod_wish_list.id') |
310
|
|
|
->group_by('variant_id') |
311
|
|
|
->get('mod_wish_list'); |
312
|
|
|
|
313
|
|
|
if ($ids) { |
314
|
|
|
$ids = $ids->result_array(); |
315
|
|
|
|
316
|
|
|
foreach ($ids as $id) { |
317
|
|
|
$ID[] = $id['variant_id']; |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
return $ID; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* |
326
|
|
|
* |
327
|
|
|
* @param integer $userID |
328
|
|
|
* @return array |
329
|
|
|
*/ |
330
|
|
|
public function getAllUserWLs($userID = null) { |
331
|
|
|
if (!$userID) { |
332
|
|
|
$userID = $this->dx_auth->get_user_id(); |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
$ID = []; |
336
|
|
|
|
337
|
|
|
$ids = $this->db |
338
|
|
|
->where('mod_wish_list.user_id', $userID) |
339
|
|
|
->get('mod_wish_list'); |
340
|
|
|
|
341
|
|
|
if ($ids) { |
342
|
|
|
$ids = $ids->result_array(); |
343
|
|
|
|
344
|
|
|
foreach ($ids as $id) { |
345
|
|
|
$ID[] = $id['id']; |
346
|
|
|
} |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
return $ID; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* get most popular products |
354
|
|
|
* |
355
|
|
|
* @param integer $limit |
356
|
|
|
* @return array |
357
|
|
|
*/ |
358
|
|
|
public function getMostPopularProducts($limit = 10) { |
359
|
|
|
$query = $this->db |
360
|
|
|
->select('COUNT(id) as productCount, variant_id,') |
361
|
|
|
->order_by('productCount', 'desc') |
362
|
|
|
->group_by('variant_id') |
363
|
|
|
->limit($limit) |
364
|
|
|
->get('mod_wish_list_products'); |
365
|
|
|
if ($query) { |
366
|
|
|
return $query->result_array(); |
367
|
|
|
} else { |
368
|
|
|
return FALSE; |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* insert wish list |
374
|
|
|
* |
375
|
|
|
* @param string $title |
376
|
|
|
* @param string $access |
377
|
|
|
* @param integer $user_id |
378
|
|
|
* @return boolean |
379
|
|
|
*/ |
380
|
|
|
public function insertWishList($title, $access, $user_id) { |
381
|
|
|
return $this->db->set('title', $title) |
382
|
|
|
->set('access', $access) |
383
|
|
|
->set('user_id', $user_id) |
384
|
|
|
->insert('mod_wish_list'); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* update wish list |
389
|
|
|
* |
390
|
|
|
* @param integer $id |
391
|
|
|
* @param array|null $data |
392
|
|
|
* @return boolean |
393
|
|
|
*/ |
394
|
|
|
public function updateWishList($id, $data) { |
395
|
|
|
$this->db->where('id', $id) |
396
|
|
|
->update('mod_wish_list', $data); |
397
|
|
|
|
398
|
|
|
if ($this->db->affected_rows() == 0) { |
|
|
|
|
399
|
|
|
return FALSE; |
400
|
|
|
} else { |
401
|
|
|
return TRUE; |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* update wish lists items comments |
407
|
|
|
* |
408
|
|
|
* @param integer $wish_list_id |
409
|
|
|
* @param array $comments |
410
|
|
|
* @return boolean |
411
|
|
|
*/ |
412
|
|
|
public function updateWishListItemsComments($wish_list_id, $comments) { |
413
|
|
|
foreach ($comments as $key => $coments) { |
414
|
|
|
if (!$this->db->where('wish_list_id', $wish_list_id)->where('variant_id ', $key)->set('comment', $coments)->update('mod_wish_list_products') |
415
|
|
|
) { |
416
|
|
|
return FALSE; |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
return TRUE; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* insert user |
424
|
|
|
* |
425
|
|
|
* @param integer $user_id |
426
|
|
|
* @param string $user_image |
427
|
|
|
* @param integer $user_birthday |
428
|
|
|
* @param string $user_name |
429
|
|
|
* @return boolean |
430
|
|
|
*/ |
431
|
|
|
public function insertUser($user_id, $user_image, $user_birthday, $user_name = null) { |
432
|
|
|
if (!$user_name) { |
433
|
|
|
$user_name = $this->dx_auth->get_username(); |
434
|
|
|
} |
435
|
|
|
return $this->db->set('id', $user_id) |
436
|
|
|
->set('user_name', $user_name) |
437
|
|
|
->set('user_image', $user_image) |
438
|
|
|
->set('user_birthday', $user_birthday) |
439
|
|
|
->insert('mod_wish_list_users'); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* add item to wish list |
444
|
|
|
* |
445
|
|
|
* @param integer $varId |
446
|
|
|
* @param string $listId |
447
|
|
|
* @param string $listName |
448
|
|
|
* @param integer $user_id |
449
|
|
|
* @return boolean |
450
|
|
|
*/ |
451
|
|
|
public function addItem($varId, $listId, $listName, $user_id = null) { |
452
|
|
|
if (!$user_id) { |
453
|
|
|
$user_id = $this->dx_auth->get_user_id(); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
if (!$listId) { |
457
|
|
|
if ($listName != '') { |
458
|
|
|
$this->createWishList($listName, $user_id); |
459
|
|
|
$listId = $this->db->insert_id(); |
460
|
|
|
} else { |
461
|
|
|
return FALSE; |
462
|
|
|
} |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
$data = [ |
466
|
|
|
'variant_id' => $varId, |
467
|
|
|
'wish_list_id' => $listId, |
468
|
|
|
]; |
469
|
|
|
|
470
|
|
|
return $this->db->insert('mod_wish_list_products', $data); |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* create user wish list if not exist |
475
|
|
|
* |
476
|
|
|
* @param integer $user_id |
477
|
|
|
* @param string $user_name |
478
|
|
|
* @return boolean |
479
|
|
|
*/ |
480
|
|
|
public function createUserIfNotExist($user_id, $user_name = null) { |
481
|
|
|
if (!$user_name) { |
482
|
|
|
$user_name = $this->dx_auth->get_username(); |
483
|
|
|
} |
484
|
|
|
$user = $this->db->where('id', $user_id)->get('mod_wish_list_users'); |
485
|
|
|
if ($user) { |
486
|
|
|
$user = $user->result_array(); |
487
|
|
|
} else { |
488
|
|
|
$user = FALSE; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
if (!$user) { |
492
|
|
|
$this->db->insert( |
493
|
|
|
'mod_wish_list_users', |
494
|
|
|
[ |
495
|
|
|
'id' => $user_id, |
496
|
|
|
'user_name' => $user_name, |
497
|
|
|
] |
498
|
|
|
); |
499
|
|
|
return TRUE; |
500
|
|
|
} |
501
|
|
|
return FALSE; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* update user |
506
|
|
|
* |
507
|
|
|
* @param integer $userID |
508
|
|
|
* @param string $user_name |
509
|
|
|
* @param integer $user_birthday |
510
|
|
|
* @param string $description |
511
|
|
|
* @return boolean |
512
|
|
|
*/ |
513
|
|
|
public function updateUser($userID, $user_name, $user_birthday, $description) { |
514
|
|
|
return $this->db->where('id', $userID) |
515
|
|
|
->set('user_name', $user_name) |
516
|
|
|
->set('user_birthday', $user_birthday) |
517
|
|
|
->set('description', $description) |
518
|
|
|
->update('mod_wish_list_users'); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* create wish list |
523
|
|
|
* |
524
|
|
|
* @param string $listName |
525
|
|
|
* @param integer $user_id |
526
|
|
|
* @param string $access |
527
|
|
|
* @param string $description |
528
|
|
|
* @return boolean |
529
|
|
|
*/ |
530
|
|
|
public function createWishList($listName, $user_id, $access = 'shared', $description) { |
|
|
|
|
531
|
|
|
$this->createUserIfNotExist($user_id); |
532
|
|
|
$data = [ |
533
|
|
|
'title' => $listName, |
534
|
|
|
'user_id' => $user_id, |
535
|
|
|
'description' => $description, |
536
|
|
|
'hash' => random_string('alpha', 16), |
537
|
|
|
'access' => $access, |
538
|
|
|
]; |
539
|
|
|
|
540
|
|
|
email::getInstance()->sendEmail( |
541
|
|
|
$this->dx_auth->get_user_email(), |
542
|
|
|
'wish_list', |
543
|
|
|
[ |
544
|
|
|
'wishListViews' => '', |
545
|
|
|
'userName' => $this->dx_auth->get_username(), |
546
|
|
|
'wishName' => $listName, |
547
|
|
|
'wishLink' => site_url('wishlist/show') . '/' . $data['hash'], |
548
|
|
|
] |
549
|
|
|
); |
550
|
|
|
|
551
|
|
|
return $this->db->insert('mod_wish_list', $data); |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* update WishList item |
556
|
|
|
* |
557
|
|
|
* @param integer $varId |
558
|
|
|
* @param integer $wish_list_id |
559
|
|
|
* @param array $data |
560
|
|
|
* @return boolean |
561
|
|
|
*/ |
562
|
|
|
public function updateWishListItem($varId, $wish_list_id, $data) { |
563
|
|
|
return $this->db |
564
|
|
|
->where('wish_list_id', $wish_list_id) |
565
|
|
|
->where('variant_id', $varId) |
566
|
|
|
->update('mod_wish_list_products', $data); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* get user wish list count |
571
|
|
|
* |
572
|
|
|
* @param integer $user_id |
573
|
|
|
* @return integer |
574
|
|
|
*/ |
575
|
|
|
public function getUserWishListCount($user_id) { |
576
|
|
|
$query = $this->db |
577
|
|
|
->where('user_id', $user_id) |
578
|
|
|
->get('mod_wish_list'); |
579
|
|
|
if ($query) { |
580
|
|
|
return count($query->result_array()); |
581
|
|
|
} else { |
582
|
|
|
return 0; |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* get user wish list items count |
588
|
|
|
* |
589
|
|
|
* @param integer $user_id |
590
|
|
|
* @return integer |
591
|
|
|
*/ |
592
|
|
|
public function getUserWishListItemsCount($user_id) { |
593
|
|
|
$query = $this->db->where('mod_wish_list.user_id', $user_id) |
594
|
|
|
->join('mod_wish_list_products', 'mod_wish_list_products.wish_list_id=mod_wish_list.id') |
595
|
|
|
->get('mod_wish_list'); |
596
|
|
|
if ($query) { |
597
|
|
|
return count($query->result_array()); |
598
|
|
|
} else { |
599
|
|
|
return 0; |
600
|
|
|
} |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* add list rewiev |
605
|
|
|
* |
606
|
|
|
* @param string $hash |
607
|
|
|
* @return boolean |
608
|
|
|
*/ |
609
|
|
|
public function addReview($hash) { |
610
|
|
|
$count = $this->db->where('hash', $hash) |
611
|
|
|
->select('review_count') |
612
|
|
|
->get('mod_wish_list') |
613
|
|
|
->row_array(); |
614
|
|
|
if (!$count) { |
615
|
|
|
return FALSE; |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
return $this->db->where('hash', $hash) |
619
|
|
|
->set('review_count', $count['review_count'] + 1) |
620
|
|
|
->update('mod_wish_list'); |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
/** |
624
|
|
|
* get most view wish lists |
625
|
|
|
* |
626
|
|
|
* @param integer $limit |
627
|
|
|
* @return boolean |
628
|
|
|
*/ |
629
|
|
|
public function getMostViewedWishLists($limit = 10) { |
630
|
|
|
return $this->db |
631
|
|
|
->select('id,title,review_count') |
632
|
|
|
->where('review_count <>', 0) |
633
|
|
|
->limit($limit) |
634
|
|
|
->get('mod_wish_list') |
635
|
|
|
->result_array(); |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
/** |
639
|
|
|
* |
640
|
|
|
* @param integer $userID |
641
|
|
|
* @param string $file_name |
642
|
|
|
* @return boolean |
643
|
|
|
*/ |
644
|
|
|
public function setUserImage($userID, $file_name) { |
645
|
|
|
return $this->db |
646
|
|
|
->where('id', $userID) |
647
|
|
|
->update( |
648
|
|
|
'mod_wish_list_users', |
649
|
|
|
['user_image' => $file_name] |
650
|
|
|
); |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
/** |
654
|
|
|
* |
655
|
|
|
* @param integer $userID |
656
|
|
|
* @return boolean |
657
|
|
|
*/ |
658
|
|
|
public function delUser($userID) { |
659
|
|
|
$WLs = $this->getAllUserWLs($userID); |
660
|
|
|
$this->delWishListProductsByWLId($WLs); |
661
|
|
|
$this->delWishListById($WLs); |
662
|
|
|
$this->db |
663
|
|
|
->where('id', $userID) |
664
|
|
|
->delete('mod_wish_list_users'); |
665
|
|
|
return TRUE; |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* install module(create db tables, set default values) |
670
|
|
|
*/ |
671
|
|
|
public function install() { |
672
|
|
|
|
673
|
|
|
$this->load->dbforge(); |
674
|
|
|
($this->dx_auth->is_admin()) OR exit; |
675
|
|
|
@mkdir('./uploads/mod_wishlist', 0777); |
|
|
|
|
676
|
|
|
|
677
|
|
|
$fields = [ |
678
|
|
|
'id' => [ |
679
|
|
|
'type' => 'INT', |
680
|
|
|
'auto_increment' => TRUE, |
681
|
|
|
], |
682
|
|
|
'title' => [ |
683
|
|
|
'type' => 'VARCHAR', |
684
|
|
|
'constraint' => '254', |
685
|
|
|
'null' => FALSE, |
686
|
|
|
], |
687
|
|
|
'description' => [ |
688
|
|
|
'type' => 'Text', |
689
|
|
|
'null' => TRUE, |
690
|
|
|
], |
691
|
|
|
'access' => [ |
692
|
|
|
'type' => 'ENUM', |
693
|
|
|
'constraint' => "'public','private','shared'", |
694
|
|
|
'default' => 'shared', |
695
|
|
|
], |
696
|
|
|
'user_id' => [ |
697
|
|
|
'type' => 'INT', |
698
|
|
|
'null' => FALSE, |
699
|
|
|
], |
700
|
|
|
'review_count' => [ |
701
|
|
|
'type' => 'INT', |
702
|
|
|
'null' => FALSE, |
703
|
|
|
'default' => 0, |
704
|
|
|
], |
705
|
|
|
'hash' => [ |
706
|
|
|
'type' => 'VARCHAR', |
707
|
|
|
'constraint' => '16', |
708
|
|
|
'null' => FALSE, |
709
|
|
|
], |
710
|
|
|
]; |
711
|
|
|
|
712
|
|
|
$this->dbforge->add_field($fields); |
713
|
|
|
$this->dbforge->add_key('id', TRUE); |
714
|
|
|
$this->dbforge->create_table('mod_wish_list'); |
715
|
|
|
|
716
|
|
|
$fields = [ |
717
|
|
|
'id' => [ |
718
|
|
|
'type' => 'INT', |
719
|
|
|
'auto_increment' => TRUE, |
720
|
|
|
], |
721
|
|
|
'wish_list_id' => [ |
722
|
|
|
'type' => 'INT', |
723
|
|
|
'null' => FALSE, |
724
|
|
|
], |
725
|
|
|
'variant_id' => [ |
726
|
|
|
'type' => 'INT', |
727
|
|
|
'null' => FALSE, |
728
|
|
|
], |
729
|
|
|
'comment' => [ |
730
|
|
|
'type' => 'TEXT', |
731
|
|
|
'null' => TRUE, |
732
|
|
|
], |
733
|
|
|
]; |
734
|
|
|
$this->dbforge->add_field($fields); |
735
|
|
|
$this->dbforge->add_key('id', TRUE); |
736
|
|
|
$this->dbforge->create_table('mod_wish_list_products'); |
737
|
|
|
|
738
|
|
|
$fields = [ |
739
|
|
|
'id' => [ |
740
|
|
|
'type' => 'INT', |
741
|
|
|
'null' => FALSE, |
742
|
|
|
], |
743
|
|
|
'user_name' => [ |
744
|
|
|
'type' => 'VARCHAR', |
745
|
|
|
'constraint' => '254', |
746
|
|
|
'null' => TRUE, |
747
|
|
|
], |
748
|
|
|
'user_image' => [ |
749
|
|
|
'type' => 'TEXT', |
750
|
|
|
'null' => TRUE, |
751
|
|
|
], |
752
|
|
|
'user_birthday' => [ |
753
|
|
|
'type' => 'INT', |
754
|
|
|
'null' => TRUE, |
755
|
|
|
], |
756
|
|
|
'description' => [ |
757
|
|
|
'type' => 'TEXT', |
758
|
|
|
'null' => TRUE, |
759
|
|
|
], |
760
|
|
|
]; |
761
|
|
|
|
762
|
|
|
$this->dbforge->add_field($fields); |
763
|
|
|
$this->dbforge->add_key('id', TRUE); |
764
|
|
|
$this->dbforge->create_table('mod_wish_list_users'); |
765
|
|
|
|
766
|
|
|
$this->db |
767
|
|
|
->where('identif', 'wishlist') |
768
|
|
|
->update( |
769
|
|
|
'components', |
770
|
|
|
[ |
771
|
|
|
'settings' => serialize( |
772
|
|
|
[ |
773
|
|
|
'maxUserName' => 256, |
774
|
|
|
'maxListName' => 254, |
775
|
|
|
'maxListsCount' => 10, |
776
|
|
|
'maxItemsCount' => 100, |
777
|
|
|
'maxCommentLenght' => 500, |
778
|
|
|
'maxDescLenght' => 1000, |
779
|
|
|
'maxWLDescLenght' => 1000, |
780
|
|
|
'maxImageWidth' => 150, |
781
|
|
|
'maxImageHeight' => 150, |
782
|
|
|
'maxImageSize' => 2000000, |
783
|
|
|
] |
784
|
|
|
), |
785
|
|
|
'enabled' => 1, |
786
|
|
|
'autoload' => 0, |
787
|
|
|
] |
788
|
|
|
); |
789
|
|
|
|
790
|
|
|
$this->insertPaterns(); |
791
|
|
|
|
792
|
|
|
return TRUE; |
793
|
|
|
} |
794
|
|
|
|
795
|
|
|
public function insertPaterns() { |
796
|
|
|
$this->db->where_in('id', '111')->delete('mod_email_paterns'); |
797
|
|
|
$this->db->where_in('id', '111')->delete('mod_email_paterns_i18n'); |
798
|
|
|
|
799
|
|
|
$file = $this->load->file(__DIR__ . '/patern.sql', true); |
800
|
|
|
$this->db->query($file); |
801
|
|
|
|
802
|
|
|
$file = $this->load->file(__DIR__ . '/patern_i18n.sql', true); |
803
|
|
|
$this->db->query($file); |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
/** |
807
|
|
|
* deinstall module |
808
|
|
|
*/ |
809
|
|
|
public function deinstall() { |
810
|
|
|
$this->load->dbforge(); |
811
|
|
|
($this->dx_auth->is_admin()) OR exit; |
812
|
|
|
@rmdir('./uploads/mod_wishlist'); |
|
|
|
|
813
|
|
|
|
814
|
|
|
$this->dbforge->drop_table('mod_wish_list_products'); |
815
|
|
|
$this->dbforge->drop_table('mod_wish_list_users'); |
816
|
|
|
$this->dbforge->drop_table('mod_wish_list'); |
817
|
|
|
|
818
|
|
|
$this->db->where_in('id', '111')->delete('mod_email_paterns'); |
819
|
|
|
$this->db->where_in('id', '111')->delete('mod_email_paterns_i18n'); |
820
|
|
|
|
821
|
|
|
return TRUE; |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
} |