1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace wishlist\classes; |
4
|
|
|
|
5
|
|
|
use CI_DB_active_record; |
6
|
|
|
use CI_Input; |
7
|
|
|
use CI_URI; |
8
|
|
|
use cmsemail\email; |
9
|
|
|
use DX_Auth; |
10
|
|
|
use MY_Controller; |
11
|
|
|
use MY_Lang; |
12
|
|
|
use Wishlist_model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Image CMS |
16
|
|
|
* Module Wishlist |
17
|
|
|
* @property Wishlist_model $wishlist_model |
18
|
|
|
* @property DX_Auth $dx_auth |
19
|
|
|
* @property CI_URI $uri |
20
|
|
|
* @property CI_DB_active_record $db |
21
|
|
|
* @property CI_Input $input |
22
|
|
|
* @version 1.0 big start! |
23
|
|
|
*/ |
24
|
|
|
class ParentWishlist extends MY_Controller |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* array that contains wishlist settings |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
public $settings = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* contains output data |
35
|
|
|
* @var mixed |
36
|
|
|
*/ |
37
|
|
|
public $dataModel; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* contains errors array |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
public $errors = []; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* contains array of user wish products |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
public $userWishProducts; |
50
|
|
|
|
51
|
|
|
public function __construct() { |
52
|
|
|
parent::__construct(); |
53
|
|
|
$lang = new MY_Lang(); |
54
|
|
|
$lang->load('wishlist'); |
55
|
|
|
|
56
|
|
|
$this->writeCookies(); |
57
|
|
|
$this->load->model('wishlist_model'); |
58
|
|
|
$this->load->helper(['form', 'url']); |
59
|
|
|
$this->load->language('wishlist'); |
60
|
|
|
$this->settings = $this->wishlist_model->getSettings(); |
|
|
|
|
61
|
|
|
|
62
|
|
|
if ($this->settings) { |
63
|
|
|
$this->userWishProducts = $this->wishlist_model->getUserWishProducts(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* set in cookie previous page url |
69
|
|
|
* |
70
|
|
|
* @access private |
71
|
|
|
* @author DevImageCms |
72
|
|
|
* @copyright (c) 2013, ImageCMS |
73
|
|
|
*/ |
74
|
|
|
private function writeCookies() { |
75
|
|
|
$this->load->helper('cookie'); |
76
|
|
|
if (!strstr($this->uri->uri_string(), 'wishlist') && !strstr($this->uri->uri_string(), 'sync')) { |
77
|
|
|
$cookie = [ |
78
|
|
|
'name' => 'url', |
79
|
|
|
'value' => $this->uri->uri_string(), |
80
|
|
|
'expire' => '15000', |
81
|
|
|
'prefix' => '', |
82
|
|
|
]; |
83
|
|
|
@$this->input->set_cookie($cookie); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* get all users wish lists |
89
|
|
|
* |
90
|
|
|
* @access public |
91
|
|
|
* @param array $access - list access |
92
|
|
|
* @author DevImageCms |
93
|
|
|
* @copyright (c) 2013, ImageCMS |
94
|
|
|
* @return boolean |
95
|
|
|
*/ |
96
|
|
|
public function all($access = ['public']) { |
97
|
|
|
$users = $this->wishlist_model->getAllUsers(); |
98
|
|
|
if (!$users) { |
99
|
|
|
$this->errors[] = lang('No users', 'wishlist'); |
100
|
|
|
return FALSE; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
foreach ($users as $user) { |
|
|
|
|
104
|
|
|
$lists[] = [ |
|
|
|
|
105
|
|
|
'user' => $user, |
106
|
|
|
'lists' => $this->wishlist_model->getWLsByUserId($user['id'], $access), |
107
|
|
|
]; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if ($lists) { |
111
|
|
|
$this->dataModel = $lists; |
112
|
|
|
return TRUE; |
113
|
|
|
} else { |
114
|
|
|
$this->errors[] = lang('No lists', 'wishlist'); |
115
|
|
|
return FALSE; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* get user wish list |
121
|
|
|
* |
122
|
|
|
* @access public |
123
|
|
|
* @param integer $hash |
124
|
|
|
* @param array $access list access |
125
|
|
|
* @author DevImageCms |
126
|
|
|
* @copyright (c) 2013, ImageCMS |
127
|
|
|
* @return boolean |
128
|
|
|
*/ |
129
|
|
|
public function show($hash, $access = ['shared', 'private', 'public']) { |
130
|
|
|
if (!$hash) { |
131
|
|
|
return FALSE; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$wishlist = $this->wishlist_model->getUserWishListByHash($hash, $access); |
135
|
|
|
$user_data = $this->wishlist_model->getUserByID($wishlist[0]['wl_user_id']); |
136
|
|
|
if ($wishlist[0]['access'] == 'private') { |
137
|
|
|
if ($wishlist[0]['user_id'] != $this->dx_auth->get_user_id()) { |
138
|
|
|
$this->core->error_404(); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
if ($wishlist) { |
143
|
|
|
self::addReview($hash); |
144
|
|
|
$this->dataModel['wish_list'] = $wishlist; |
145
|
|
|
$this->dataModel['user'] = $user_data; |
146
|
|
|
|
147
|
|
|
return TRUE; |
148
|
|
|
} else { |
149
|
|
|
$this->errors[] = lang('Invalid request', 'wishlist'); |
150
|
|
|
return FALSE; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* add view point to list |
156
|
|
|
* |
157
|
|
|
* @access public |
158
|
|
|
* @param integer $hash |
159
|
|
|
* @author DevImageCms |
160
|
|
|
* @copyright (c) 2013, ImageCMS |
161
|
|
|
* @return boolean |
162
|
|
|
*/ |
163
|
|
|
public static function addReview($hash) { |
164
|
|
|
$CI = & get_instance(); |
165
|
|
|
$listsAdded = []; |
166
|
|
|
|
167
|
|
|
if ($CI->input->cookie('wishListViewer')) { |
168
|
|
|
$listsAdded = unserialize($CI->input->cookie('wishListViewer')); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
if (!in_array($hash, $listsAdded)) { |
172
|
|
|
array_push($listsAdded, $hash); |
173
|
|
|
if ($CI->wishlist_model->addReview($hash)) { |
174
|
|
|
$cookie = [ |
175
|
|
|
'name' => 'wishListViewer', |
176
|
|
|
'value' => serialize($listsAdded), |
177
|
|
|
'expire' => 60 * 60 * 24, |
178
|
|
|
'prefix' => '', |
179
|
|
|
]; |
180
|
|
|
@$CI->input->set_cookie($cookie); |
|
|
|
|
181
|
|
|
return TRUE; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
return FALSE; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* get most viewed wish list |
189
|
|
|
* |
190
|
|
|
* @access public |
191
|
|
|
* @param integer $limit count lists to get |
192
|
|
|
* @author DevImageCms |
193
|
|
|
* @copyright (c) 2013, ImageCMS |
194
|
|
|
* @return boolean |
195
|
|
|
*/ |
196
|
|
|
public function getMostViewedWishLists($limit = 10) { |
197
|
|
|
$views = $this->wishlist_model->getMostViewedWishLists($limit); |
198
|
|
|
if ($views) { |
199
|
|
|
$this->dataModel = $views; |
200
|
|
|
return TRUE; |
201
|
|
|
} else { |
202
|
|
|
$this->errors[] = lang('No views', 'wishlist'); |
203
|
|
|
return FALSE; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* render user lists |
209
|
|
|
* |
210
|
|
|
* @access public |
211
|
|
|
* @param integer $user_id |
212
|
|
|
* @param array $access |
213
|
|
|
* @author DevImageCms |
214
|
|
|
* @copyright (c) 2013, ImageCMS |
215
|
|
|
* @return boolean |
216
|
|
|
*/ |
217
|
|
|
public function user($user_id, $access = ['public']) { |
218
|
|
|
if ($this->getUserWL($user_id, $access)) { |
219
|
|
|
$this->dataModel = $this->dataModel['wishlists']; |
220
|
|
|
return TRUE; |
221
|
|
|
} else { |
222
|
|
|
$this->errors[] = lang('Invalid request', 'wishlist'); |
223
|
|
|
return FALSE; |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* update user information |
229
|
|
|
* |
230
|
|
|
* @access public |
231
|
|
|
* @param integer $userID |
232
|
|
|
* @param string $user_name |
233
|
|
|
* @param string $user_birthday |
234
|
|
|
* @param string $description |
235
|
|
|
* @author DevImageCms |
236
|
|
|
* @copyright (c) 2013, ImageCMS |
237
|
|
|
* @return boolean |
238
|
|
|
*/ |
239
|
|
|
public function userUpdate($userID, $user_name, $user_birthday, $description) { |
240
|
|
|
if (!$userID) { |
241
|
|
|
$userID = $this->dx_auth->get_user_id(); |
242
|
|
|
} |
243
|
|
|
$this->wishlist_model->createUserIfNotExist($userID); |
244
|
|
|
|
245
|
|
|
return $this->wishlist_model->updateUser($userID, $user_name, $user_birthday, $description); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* update wish list |
250
|
|
|
* |
251
|
|
|
* @access public |
252
|
|
|
* @param integer $id |
253
|
|
|
* @param array $data |
254
|
|
|
* @param array $comments |
255
|
|
|
* @author DevImageCms |
256
|
|
|
* @copyright (c) 2013, ImageCMS |
257
|
|
|
* @return boolean |
258
|
|
|
*/ |
259
|
|
|
public function updateWL($id, $data, $comments) { |
260
|
|
|
$return = $this->wishlist_model->updateWishList($id, $data); |
261
|
|
|
if ($comments) { |
262
|
|
|
$this->wishlist_model->updateWishListItemsComments($id, $comments); |
263
|
|
|
} |
264
|
|
|
if ($return) { |
265
|
|
|
$this->dataModel[] = lang('Updated', 'wishlist'); |
266
|
|
|
} else { |
267
|
|
|
$this->errors[] = lang('Not updated', 'wishlist'); |
268
|
|
|
} |
269
|
|
|
return $return; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* create wish list |
274
|
|
|
* |
275
|
|
|
* @access public |
276
|
|
|
* @param integer $user_id |
277
|
|
|
* @param string $listName |
278
|
|
|
* @param string $wlType |
279
|
|
|
* @param string $wlDescription |
280
|
|
|
* @return bool |
281
|
|
|
* @author DevImageCms |
282
|
|
|
* @copyright (c) 2013, ImageCMS |
283
|
|
|
*/ |
284
|
|
|
public function createWishList($user_id, $listName, $wlType, $wlDescription) { |
285
|
|
|
|
286
|
|
|
if ($listName) { |
287
|
|
|
$count_lists = $this->wishlist_model->getUserWishListCount($user_id); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
if ($count_lists >= $this->settings['maxListsCount']) { |
291
|
|
|
$this->errors[] = lang('Wish Lists limit exhausted', 'wishlist') . '. ' . lang('List maximum', 'wishlist') . ' - ' . $this->settings['maxListsCount']; |
292
|
|
|
return FALSE; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
if (iconv_strlen($wlDescription, 'UTF-8') > $this->settings['maxWLDescLenght']) { |
296
|
|
|
$wlDescription = mb_substr($wlDescription, 0, (int) $this->settings['maxWLDescLenght'], 'utf-8'); |
297
|
|
|
$this->errors[] = lang('List description limit exhausted', 'wishlist') . '. ' . lang('List description max count', 'wishlist') . ' - ' . $this->settings['maxWLDescLenght']; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
if ($listName) { |
301
|
|
|
if (iconv_strlen($listName, 'UTF-8') > $this->settings['maxListName']) { |
302
|
|
|
$listName = mb_substr($listName, 0, (int) $this->settings['maxListName'], 'utf-8'); |
|
|
|
|
303
|
|
|
$this->errors[] = lang('Wish list name will be changed', 'wishlist') . '. ' . lang('List name length maximum', 'wishlist') . ' - ' . $this->settings['maxListName']; |
304
|
|
|
} else { |
305
|
|
|
$this->wishlist_model->createWishList($listName, $user_id, $wlType, $wlDescription); |
306
|
|
|
} |
307
|
|
|
} else { |
308
|
|
|
$this->errors[] = lang('Wish List name can not be empty!', 'wishlist'); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
View Code Duplication |
if (count($this->errors)) { |
312
|
|
|
return FALSE; |
313
|
|
|
} else { |
314
|
|
|
$this->dataModel = lang('Created', 'wishlist'); |
315
|
|
|
return TRUE; |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* delete full WL |
321
|
|
|
* |
322
|
|
|
* @access public |
323
|
|
|
* @param integer $id list id |
324
|
|
|
* @author DevImageCms |
325
|
|
|
* @copyright (c) 2013, ImageCMS |
326
|
|
|
* @return boolean |
327
|
|
|
*/ |
328
|
|
|
public function deleteWL($id) { |
329
|
|
|
$forReturn = $this->wishlist_model->delWishListById($id); |
330
|
|
|
|
331
|
|
|
if ($forReturn) { |
332
|
|
|
$this->wishlist_model->delWishListProductsByWLId($id); |
333
|
|
|
} else { |
334
|
|
|
$this->errors[] = lang('You can not delete Wish List', 'wishlist'); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
View Code Duplication |
if (count($this->errors)) { |
338
|
|
|
return FALSE; |
339
|
|
|
} else { |
340
|
|
|
$this->dataModel = lang('Successfully deleted', 'wishlist'); |
341
|
|
|
return TRUE; |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* delete all wishlists |
347
|
|
|
* @param integer $UserID |
348
|
|
|
* @return boolean |
349
|
|
|
*/ |
350
|
|
|
public function deleteAllWL($UserID) { |
351
|
|
|
$forReturn = TRUE; |
352
|
|
|
|
353
|
|
|
$WLs = $this->wishlist_model->getAllUserWLs($UserID); |
354
|
|
|
if ($forReturn) { |
355
|
|
|
foreach ($WLs as $wl) { |
356
|
|
|
$this->wishlist_model->delWishListById($wl); |
357
|
|
|
$forReturn = $this->wishlist_model->delWishListProductsByWLId($wl); |
358
|
|
|
|
359
|
|
|
if (!$forReturn) { |
360
|
|
|
$this->errors[] = lang('Can not remove items from wishlist', 'wishlist'); |
361
|
|
|
} |
362
|
|
|
} |
363
|
|
|
} else { |
364
|
|
|
$this->errors[] = lang('You can not delete Wish List', 'wishlist'); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
View Code Duplication |
if (count($this->errors)) { |
368
|
|
|
return FALSE; |
369
|
|
|
} else { |
370
|
|
|
$this->dataModel = lang('Successfully deleted', 'wishlist'); |
371
|
|
|
return TRUE; |
372
|
|
|
} |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* add item to wish list |
377
|
|
|
* |
378
|
|
|
* @access public |
379
|
|
|
* @param integer $varId |
380
|
|
|
* @param string $listId |
381
|
|
|
* @param string $listName |
382
|
|
|
* @param integer $userId |
383
|
|
|
* @author DevImageCms |
384
|
|
|
* @copyright (c) 2013, ImageCMS |
385
|
|
|
* @return boolean |
386
|
|
|
*/ |
387
|
|
|
public function _addItem($varId, $listId, $listName, $userId = null) { |
388
|
|
|
if (!$userId) { |
389
|
|
|
$userId = $this->dx_auth->get_user_id(); |
390
|
|
|
} |
391
|
|
|
$count_lists = 0; |
392
|
|
|
$count_items = $this->wishlist_model->getUserWishListItemsCount($userId); |
393
|
|
|
|
394
|
|
|
if (!$this->settings) { |
395
|
|
|
$this->settings = $this->wishlist_model->getSettings(); |
|
|
|
|
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
if ($count_items >= $this->settings['maxItemsCount']) { |
399
|
|
|
$this->errors[] = lang('Limit of list items exhausted', 'wishlist'); |
400
|
|
|
return FALSE; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
if (!$this->dx_auth->is_logged_in()) { |
404
|
|
|
$this->errors[] = lang('User is not logged in', 'wishlist'); |
405
|
|
|
return FALSE; |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
if (mb_strlen($listName, 'utf-8') > $this->settings['maxListName']) { |
409
|
|
|
$listName = mb_substr($listName, 0, (int) $this->settings['maxListName'], 'utf-8'); |
410
|
|
|
$this->errors[] = lang('Wishlist name will be changed', 'wishlist') . '. ' . lang('Maximum length of wishlist name', 'wishlist') . ' - ' . $this->settings['maxListName']; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
if ($listName) { |
414
|
|
|
$listId = ''; |
415
|
|
|
$count_lists = $this->wishlist_model->getUserWishListCount($userId); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
if ($count_lists >= $this->settings['maxListsCount']) { |
419
|
|
|
$this->errors[] = lang('Wish Lists limit exhausted', 'wishlist') . '. ' . lang('List maximum', 'wishlist') . ' - ' . $this->settings['maxListsCount']; |
420
|
|
|
return FALSE; |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
if (!$this->wishlist_model->addItem($varId, $listId, $listName, $userId)) { |
424
|
|
|
$this->errors[] = lang('You can not add', 'wishlist'); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
if (count($this->errors)) { |
428
|
|
|
return FALSE; |
429
|
|
|
} else { |
430
|
|
|
$this->userWishProducts = $this->wishlist_model->getUserWishProducts(); |
431
|
|
|
$this->dataModel = lang('Added to wishlist', 'wishlist'); |
432
|
|
|
return TRUE; |
433
|
|
|
} |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* move item from one wish list to another |
438
|
|
|
* |
439
|
|
|
* @param integer $varId |
440
|
|
|
* @param integer $wish_list_id |
441
|
|
|
* @param int|string $to_listId |
442
|
|
|
* @param int|string $to_listName |
443
|
|
|
* @param null $user_id |
444
|
|
|
* @return bool |
445
|
|
|
* @access public |
446
|
|
|
* @author DevImageCms |
447
|
|
|
* @copyright (c) 2013, ImageCMS |
448
|
|
|
*/ |
449
|
|
|
public function moveItem($varId, $wish_list_id, $to_listId = '', $to_listName = '', $user_id = null) { |
450
|
|
|
if (!$user_id) { |
451
|
|
|
$user_id = $this->dx_auth->get_user_id(); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
if ($to_listName) { |
455
|
|
|
$this->wishlist_model->createWishList($to_listName, $user_id); |
456
|
|
|
$to_listId = $this->db->insert_id(); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
$data = ['wish_list_id' => $to_listId]; |
460
|
|
|
return $this->wishlist_model->updateWishListItem($varId, $wish_list_id, $data); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* delete item from wish list |
465
|
|
|
* |
466
|
|
|
* @param integer $variant_id |
467
|
|
|
* @param integer $wish_list_id |
468
|
|
|
* @access public |
469
|
|
|
* @author DevImageCms |
470
|
|
|
* @copyright (c) 2013, ImageCMS |
471
|
|
|
* @return boolean |
472
|
|
|
*/ |
473
|
|
|
public function deleteItem($variant_id, $wish_list_id) { |
474
|
|
|
$forReturn = $this->wishlist_model->deleteItem($variant_id, $wish_list_id); |
475
|
|
|
if ($forReturn == 0) { |
476
|
|
|
$this->errors[] = lang('Can not remove items from wishlist', 'wishlist'); |
477
|
|
|
} else { |
478
|
|
|
$this->dataModel = lang('Item deleted', 'wishlist'); |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
return $forReturn; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* get user info |
486
|
|
|
* |
487
|
|
|
* @param integer $id |
488
|
|
|
* @access public |
489
|
|
|
* @author DevImageCms |
490
|
|
|
* @copyright (c) 2013, ImageCMS |
491
|
|
|
* @return boolean |
|
|
|
|
492
|
|
|
*/ |
493
|
|
|
public function getUserInfo($id) { |
494
|
|
|
return $this->wishlist_model->getUserByID($id); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* render user wish list |
499
|
|
|
* |
500
|
|
|
* @param integer $userId |
501
|
|
|
* @param array $access |
502
|
|
|
* @access public |
503
|
|
|
* @author DevImageCms |
504
|
|
|
* @copyright (c) 2013, ImageCMS |
505
|
|
|
* @return boolean |
506
|
|
|
*/ |
507
|
|
|
public function getUserWL($userId, $access = ['public', 'private', 'shared']) { |
508
|
|
|
$this->wishlist_model->createUserIfNotExist($userId); |
509
|
|
|
|
510
|
|
|
$wishlists = $this->wishlist_model->getUserWishListsByID($userId, $access); |
511
|
|
|
$userInfo = $this->getUserInfo($userId); |
512
|
|
|
$this->dataModel['user'] = $userInfo; |
513
|
|
|
|
514
|
|
|
if (!$wishlists) { |
515
|
|
|
return FALSE; |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
if (empty($userInfo)) { |
519
|
|
|
$this->errors[] = lang('User data is not found', 'wishlist'); |
520
|
|
|
return FALSE; |
521
|
|
|
} |
522
|
|
|
$w = []; |
523
|
|
|
|
524
|
|
|
foreach ($wishlists as $wishlist) { |
525
|
|
|
$w[$wishlist['wish_list_id']][] = $wishlist; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
$this->dataModel['wishlists'] = $w; |
529
|
|
|
|
530
|
|
|
return TRUE; |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* render user wish list edit page |
535
|
|
|
* |
536
|
|
|
* @param integer $wish_list_id |
537
|
|
|
* @param integer $userID |
538
|
|
|
* @access public |
539
|
|
|
* @author DevImageCms |
540
|
|
|
* @copyright (c) 2013, ImageCMS |
541
|
|
|
* @return boolean |
542
|
|
|
*/ |
543
|
|
|
public function renderUserWLEdit($wish_list_id, $userID = null) { |
544
|
|
|
if ($userID === null) { |
545
|
|
|
$userID = $this->dx_auth->get_user_id(); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
if ($wish_list_id) { |
549
|
|
|
$wishlists = $this->wishlist_model->getUserWishList($userID, $wish_list_id); |
550
|
|
|
if (empty($wishlists)) { |
551
|
|
|
return FALSE; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
$w = []; |
555
|
|
|
foreach ($wishlists as $wishlist) { |
556
|
|
|
$w[$wishlist['title']][] = $wishlist; |
557
|
|
|
} |
558
|
|
|
$this->dataModel = $w; |
559
|
|
|
return TRUE; |
560
|
|
|
} |
561
|
|
|
return FALSE; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* upload image for user |
566
|
|
|
* |
567
|
|
|
* @param integer $userID |
568
|
|
|
* @access public |
569
|
|
|
* @author DevImageCms |
570
|
|
|
* @copyright (c) 2013, ImageCMS |
571
|
|
|
* @return boolean |
572
|
|
|
*/ |
573
|
|
|
public function do_upload($userID = null) { |
574
|
|
|
|
575
|
|
|
if (!$userID) { |
576
|
|
|
$userID = $this->dx_auth->get_user_id(); |
|
|
|
|
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
$allowedFileFormats = [ |
580
|
|
|
'image/gif', |
581
|
|
|
'image/jpeg', |
582
|
|
|
'image/png', |
583
|
|
|
'image/jpg', |
584
|
|
|
]; |
585
|
|
|
|
586
|
|
|
list($width, $height) = getimagesize($_FILES['file']['tmp_name']); |
587
|
|
|
|
588
|
|
View Code Duplication |
if ($this->settings['maxImageSize'] < $_FILES['file']['size']) { |
589
|
|
|
$this->errors[] = lang('Maximum image size is exceeded', 'wishlist') . ' (' . lang('max size', 'wishlist') . ' ' . $this->settings['maxImageSize'] . ')'; |
590
|
|
|
} |
591
|
|
View Code Duplication |
if ($this->settings['maxImageWidth'] < $width) { |
592
|
|
|
$this->errors[] = lang('Maximum width of the image is exceeded', 'wishlist') . ' (' . lang('max width', 'wishlist') . ' ' . $this->settings['maxImageWidth'] . 'px)'; |
593
|
|
|
} |
594
|
|
View Code Duplication |
if ($this->settings['maxImageHeight'] < $height) { |
595
|
|
|
$this->errors[] = lang('Max image height exceeded', 'wishlist') . ' (' . lang('max height', 'wishlist') . ' ' . $this->settings['maxImageHeight'] . 'px)'; |
596
|
|
|
} |
597
|
|
|
if (!in_array($_FILES['file']['type'], $allowedFileFormats)) { |
598
|
|
|
$this->errors[] = lang('Invalid file format', 'wishlist'); |
599
|
|
|
} |
600
|
|
|
if ($this->errors) { |
601
|
|
|
return FALSE; |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
if (!file_exists('./uploads/mod_wishlist/')) { |
605
|
|
|
mkdir('./uploads/mod_wishlist/'); |
606
|
|
|
chmod('./uploads/mod_wishlist/', 0777); |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
$config['upload_path'] = './uploads/mod_wishlist/'; |
|
|
|
|
610
|
|
|
$config['allowed_types'] = 'gif|jpg|png|jpeg'; |
611
|
|
|
$config['max_size'] = $this->settings['maxImageSize']; |
612
|
|
|
$config['max_width'] = $this->settings['maxImageWidth']; |
613
|
|
|
$config['max_height'] = $this->settings['maxImageHeight']; |
614
|
|
|
|
615
|
|
|
$this->load->library('upload', $config); |
616
|
|
|
return TRUE; |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* get most popular items by wish list usage |
621
|
|
|
* |
622
|
|
|
* @param integer $limit |
623
|
|
|
* @access public |
624
|
|
|
* @author DevImageCms |
625
|
|
|
* @copyright (c) 2013, ImageCMS |
626
|
|
|
* @return boolean |
627
|
|
|
*/ |
628
|
|
|
public function getMostPopularItems($limit = 10) { |
629
|
|
|
$result = $this->wishlist_model->getMostPopularProducts($limit); |
630
|
|
|
|
631
|
|
|
if ($result !== FALSE) { |
632
|
|
|
$this->dataModel = $result; |
633
|
|
|
return TRUE; |
634
|
|
|
} else { |
635
|
|
|
$this->error[] = lang('Invalid request', 'wishlist'); |
636
|
|
|
return FALSE; |
637
|
|
|
} |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* get user wish list items count |
642
|
|
|
* |
643
|
|
|
* @param integer $user_id |
644
|
|
|
* @access public |
645
|
|
|
* @author DevImageCms |
646
|
|
|
* @copyright (c) 2013, ImageCMS |
647
|
|
|
* @return integer |
648
|
|
|
*/ |
649
|
|
|
public function getUserWishListItemsCount($user_id) { |
650
|
|
|
return $this->wishlist_model->getUserWishListItemsCount($user_id); |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
/** |
654
|
|
|
* delete list items by id's |
655
|
|
|
* |
656
|
|
|
* @param array $ids |
657
|
|
|
* @access public |
658
|
|
|
* @author DevImageCms |
659
|
|
|
* @copyright (c) 2013, ImageCMS |
660
|
|
|
* @return boolean |
|
|
|
|
661
|
|
|
*/ |
662
|
|
|
public function deleteItemsByIds($ids) { |
663
|
|
|
return $this->wishlist_model->deleteItemsByIDs($ids); |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
/** |
667
|
|
|
* delete image |
668
|
|
|
* |
669
|
|
|
* @param string $image image name |
670
|
|
|
* @access public |
671
|
|
|
* @author DevImageCms |
672
|
|
|
* @copyright (c) 2013, ImageCMS |
673
|
|
|
* @return boolean |
674
|
|
|
*/ |
675
|
|
|
public function deleteImage($image, $user_id) { |
676
|
|
|
$this->db->where('id', $user_id)->update('mod_wish_list_users', ['user_image' => '']); |
677
|
|
|
$basePath = substr(__DIR__, 0, strpos(__DIR__, 'application')); |
678
|
|
|
return unlink($basePath . 'uploads/mod_wishlist/' . $image); |
679
|
|
|
} |
680
|
|
|
|
681
|
|
|
/** |
682
|
|
|
* get popup for adding or moving items |
683
|
|
|
* |
684
|
|
|
* @param integer $userID |
685
|
|
|
* @access public |
686
|
|
|
* @author DevImageCms |
687
|
|
|
* @copyright (c) 2013, ImageCMS |
688
|
|
|
* @return boolean |
689
|
|
|
*/ |
690
|
|
|
public function renderPopup($userID = null) { |
691
|
|
|
$wish_lists = $this->wishlist_model->getWishLists($userID); |
692
|
|
|
if ($wish_lists) { |
693
|
|
|
$this->dataModel = $wish_lists; |
694
|
|
|
return TRUE; |
695
|
|
|
} else { |
696
|
|
|
return FALSE; |
697
|
|
|
} |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
/** |
701
|
|
|
* |
702
|
|
|
* @param integer $wish_list_id |
703
|
|
|
* @param string $email |
704
|
|
|
* @return boolean |
705
|
|
|
*/ |
706
|
|
|
public function send_email($wish_list_id, $email) { |
707
|
|
|
$user = $this->wishlist_model->getUserByID($this->dx_auth->get_user_id()); |
708
|
|
|
$wish_list = $this->db->where('id', $wish_list_id)->get('mod_wish_list'); |
709
|
|
|
|
710
|
|
|
if ($wish_list) { |
711
|
|
|
$wish_list = $wish_list->row_array(); |
712
|
|
|
} else { |
713
|
|
|
$wish_list = []; |
714
|
|
|
} |
715
|
|
|
$db_user = $this->db->where('id', $this->dx_auth->get_user_id())->get('users')->row_array(); |
716
|
|
|
|
717
|
|
|
if ($user) { |
718
|
|
|
$name = $user['user_name'] ? $user['user_name'] : $this->dx_auth->get_username(); |
719
|
|
|
$phone = $db_user['phone'] ? $db_user['phone'] : '(---) --- --- --- '; |
720
|
|
|
|
721
|
|
|
$user_variables = [ |
722
|
|
|
'userName' => $name, |
723
|
|
|
'userPhone' => $phone, |
724
|
|
|
'wishName' => $wish_list['title'], |
725
|
|
|
'wishLink' => site_url('wishlist/show/' . $wish_list['hash']), |
726
|
|
|
'wishListViews' => $wish_list['hash']['review_count'], |
727
|
|
|
]; |
728
|
|
|
|
729
|
|
|
email::getInstance()->sendEmail($email, 'wish_list', $user_variables); |
730
|
|
|
|
731
|
|
|
return TRUE; |
732
|
|
|
} else { |
733
|
|
|
return FALSE; |
734
|
|
|
} |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
public function autoload() { |
738
|
|
|
|
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
public static function adminAutoload() { |
742
|
|
|
parent::adminAutoload(); |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
public function _install() { |
746
|
|
|
$this->wishlist_model->install(); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
public function _deinstall() { |
750
|
|
|
$this->wishlist_model->deinstall(); |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
} |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.