1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* oledrion |
14
|
|
|
* |
15
|
|
|
* @copyright {@link http://xoops.org/ XOOPS Project} |
16
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
17
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Facade pour les produits |
22
|
|
|
*/ |
23
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
24
|
|
|
|
25
|
|
|
class Oledrion_shelf |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
private $handlers; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Oledrion_shelf constructor. |
31
|
|
|
*/ |
32
|
|
|
public function __construct() |
33
|
|
|
{ |
34
|
|
|
$this->initHandlers(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Chargement des handlers |
39
|
|
|
*/ |
40
|
|
|
private function initHandlers() |
41
|
|
|
{ |
42
|
|
|
$this->handlers = OledrionHandler::getInstance(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Retourne le nombre de produits d'un certain type |
47
|
|
|
* |
48
|
|
|
* @param string $type Le type de produits dont on veut récupérer le nombre |
49
|
|
|
* @param int $category |
50
|
|
|
* @param int $excluded |
51
|
|
|
* @return int |
52
|
|
|
*/ |
53
|
|
|
public function getProductsCount($type = 'recent', $category = 0, $excluded = 0) |
54
|
|
|
{ |
55
|
|
|
switch (strtolower($type)) { |
56
|
|
|
case 'recent': |
57
|
|
|
return $this->handlers->h_oledrion_products->getRecentProductsCount($category, $excluded); |
|
|
|
|
58
|
|
|
break; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return 0; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Supprime un produit (et tout ce qui lui est relatif) |
66
|
|
|
* @param oledrion_products $product |
67
|
|
|
*/ |
68
|
|
|
public function deleteProduct(Oledrion_products $product) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
global $xoopsModule; |
|
|
|
|
71
|
|
|
$id = $product->getVar('product_id'); |
72
|
|
|
|
73
|
|
|
// On commence par supprimer les commentaires |
74
|
|
|
$mid = $xoopsModule->getVar('mid'); |
75
|
|
|
xoops_comment_delete($mid, $id); |
76
|
|
|
|
77
|
|
|
// Puis les votes |
78
|
|
|
$this->handlers->h_oledrion_votedata->deleteProductRatings($id); |
|
|
|
|
79
|
|
|
|
80
|
|
|
// Puis les produits relatifs |
81
|
|
|
$this->handlers->h_oledrion_related->deleteProductRelatedProducts($id); |
|
|
|
|
82
|
|
|
|
83
|
|
|
// Les images (la grande et la miniature) |
84
|
|
|
$product->deletePictures(); |
85
|
|
|
|
86
|
|
|
// Le fichier attaché |
87
|
|
|
$product->deleteAttachment(); |
88
|
|
|
|
89
|
|
|
// Les fichiers attachés |
90
|
|
|
$this->handlers->h_oledrion_files->deleteProductFiles($id); |
|
|
|
|
91
|
|
|
|
92
|
|
|
// Suppression dans les paniers persistants enregistrés |
93
|
|
|
$this->handlers->h_oledrion_persistent_cart->deleteProductForAllCarts($id); |
|
|
|
|
94
|
|
|
|
95
|
|
|
// Les attributs qui lui sont rattachés |
96
|
|
|
$this->handlers->h_oledrion_attributes->deleteProductAttributes($id); |
|
|
|
|
97
|
|
|
|
98
|
|
|
// Le produit dans les listes |
99
|
|
|
$this->handlers->h_oledrion_products_list->deleteProductFromLists($id); |
|
|
|
|
100
|
|
|
|
101
|
|
|
// La relation entre le produit et le fabricant |
102
|
|
|
$this->handlers->h_oledrion_productsmanu->removeManufacturerProduct($id); |
|
|
|
|
103
|
|
|
|
104
|
|
|
// Le produit dans les remises |
105
|
|
|
$this->handlers->h_oledrion_discounts->removeProductFromDiscounts($id); |
|
|
|
|
106
|
|
|
|
107
|
|
|
// Et le produit en lui même, à la fin |
108
|
|
|
return $this->handlers->h_oledrion_products->delete($product, true); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Cherche et retourne la liste de produits relatifs à une liste de produits |
113
|
|
|
* |
114
|
|
|
* @param array $productsIds La liste des produits dont on cherche les produits relatifs |
115
|
|
|
* @return array Clé = ID Produit, valeurs (deuxième dimension) = liste des produits relatifs |
116
|
|
|
*/ |
117
|
|
|
private function getRelatedProductsFromProductsIds($productsIds) |
118
|
|
|
{ |
119
|
|
|
$relatedProducts = $relatedProductsIds = array(); |
|
|
|
|
120
|
|
|
if (is_array($productsIds) && count($productsIds) > 0) { |
121
|
|
|
$relatedProductsIds = $this->handlers->h_oledrion_related->getRelatedProductsFromProductsIds($productsIds); |
|
|
|
|
122
|
|
|
if (count($relatedProductsIds) > 0) { |
123
|
|
|
$tmp = array(); |
124
|
|
|
foreach ($relatedProductsIds as $relatedProductId) { |
125
|
|
|
$tmp[] = $relatedProductId->getVar('related_product_related'); |
126
|
|
|
} |
127
|
|
|
$tmp = array_unique($tmp); |
128
|
|
|
sort($tmp); |
129
|
|
|
if (count($tmp) > 0) { |
130
|
|
|
$tempRelatedProducts = $this->handlers->h_oledrion_products->getProductsFromIDs($tmp); |
|
|
|
|
131
|
|
|
foreach ($relatedProductsIds as $relatedProductId) { |
132
|
|
|
if (isset($tempRelatedProducts[$relatedProductId->getVar('related_product_related')])) { |
133
|
|
|
$relatedProducts[$relatedProductId->getVar('related_product_id')][] = $tempRelatedProducts[$relatedProductId->getVar('related_product_related')]; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return $relatedProducts; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Retourne une liste de produits selon certains critères |
145
|
|
|
* |
146
|
|
|
* @param oledrion_shelf_parameters $parameters Les paramètres de filtrage |
147
|
|
|
* @return array Tableau prêt à être utilisé dans les templates |
148
|
|
|
*/ |
149
|
|
|
public function getProducts(Oledrion_shelf_parameters $parameters) |
150
|
|
|
{ |
151
|
|
|
global $vatArray; |
|
|
|
|
152
|
|
|
$parametersValues = $parameters->getParameters(); |
153
|
|
|
$productType = $parametersValues['productsType']; |
154
|
|
|
$start = $parametersValues['start']; |
155
|
|
|
$limit = $parametersValues['limit']; |
156
|
|
|
$category = $parametersValues['category']; |
157
|
|
|
$sort = $parametersValues['sort']; |
158
|
|
|
$order = $parametersValues['order']; |
159
|
|
|
$excluded = $parametersValues['excluded']; |
160
|
|
|
$withXoopsUser = $parametersValues['withXoopsUser']; |
161
|
|
|
$withRelatedProducts = $parametersValues['withRelatedProducts']; |
162
|
|
|
$withQuantity = $parametersValues['withQuantity']; |
163
|
|
|
$thisMonthOnly = $parametersValues['thisMonthOnly']; |
164
|
|
|
$ret = $xoopsUsersIDs = $users = $relatedProducts = $productsManufacturers = $manufacturersPerProduct = $products = $productsIds = $categoriesIds = $vendorsIds = $manufacturersIds = $manufacturers = $categories = $vendors = array(); |
|
|
|
|
165
|
|
|
// On commence par récupérer la liste des produits |
166
|
|
|
switch (strtolower($productType)) { |
167
|
|
|
case 'recent': |
168
|
|
|
$products = $this->handlers->h_oledrion_products->getRecentProducts(new Oledrion_parameters(array( |
|
|
|
|
169
|
|
|
'start' => $start, |
170
|
|
|
'limit' => $limit, |
171
|
|
|
'category' => $category, |
172
|
|
|
'sort' => $sort, |
173
|
|
|
'order' => $order, |
174
|
|
|
'excluded' => $excluded, |
175
|
|
|
'thisMonthOnly' => $thisMonthOnly |
176
|
|
|
))); |
177
|
|
|
break; |
178
|
|
|
|
179
|
|
|
case 'mostsold': |
180
|
|
|
$tempProductsIds = array(); |
|
|
|
|
181
|
|
|
$tempProductsIds = $this->handlers->h_oledrion_caddy->getMostSoldProducts($start, $limit, $category, $withQuantity); |
|
|
|
|
182
|
|
|
if (count($tempProductsIds) > 0) { |
183
|
|
|
$products = $this->handlers->h_oledrion_products->getProductsFromIDs(array_keys($tempProductsIds)); |
|
|
|
|
184
|
|
|
} |
185
|
|
|
break; |
186
|
|
|
|
187
|
|
|
case 'recentlysold': |
188
|
|
|
$tempProductsIds = array(); |
|
|
|
|
189
|
|
|
$tempProductsIds = $this->handlers->h_oledrion_caddy->getRecentlySoldProducts($start, $limit); |
|
|
|
|
190
|
|
|
if (count($tempProductsIds) > 0) { |
191
|
|
|
$tempProductsIds = array_unique($tempProductsIds); |
192
|
|
|
} |
193
|
|
|
if (count($tempProductsIds) > 0) { |
194
|
|
|
$products = $this->handlers->h_oledrion_products->getProductsFromIDs(array_keys($tempProductsIds)); |
|
|
|
|
195
|
|
|
} |
196
|
|
|
break; |
197
|
|
|
|
198
|
|
View Code Duplication |
case 'mostviewed': |
|
|
|
|
199
|
|
|
$products = $this->handlers->h_oledrion_products->getMostViewedProducts(new Oledrion_parameters(array( |
|
|
|
|
200
|
|
|
'start' => $start, |
201
|
|
|
'limit' => $limit, |
202
|
|
|
'category' => $category, |
203
|
|
|
'sort' => $sort, |
204
|
|
|
'order' => $order |
205
|
|
|
))); |
206
|
|
|
break; |
207
|
|
|
|
208
|
|
View Code Duplication |
case 'bestrated': |
|
|
|
|
209
|
|
|
$products = $this->handlers->h_oledrion_products->getBestRatedProducts(new Oledrion_parameters(array( |
|
|
|
|
210
|
|
|
'start' => $start, |
211
|
|
|
'limit' => $limit, |
212
|
|
|
'category' => $category, |
213
|
|
|
'sort' => $sort, |
214
|
|
|
'order' => $order |
215
|
|
|
))); |
216
|
|
|
break; |
217
|
|
|
|
218
|
|
View Code Duplication |
case 'recommended': |
|
|
|
|
219
|
|
|
$products = $this->handlers->h_oledrion_products->getRecentRecommended(new Oledrion_parameters(array( |
|
|
|
|
220
|
|
|
'start' => $start, |
221
|
|
|
'limit' => $limit, |
222
|
|
|
'category' => $category, |
223
|
|
|
'sort' => $sort, |
224
|
|
|
'order' => $order |
225
|
|
|
))); |
226
|
|
|
break; |
227
|
|
|
|
228
|
|
View Code Duplication |
case 'promotional': |
|
|
|
|
229
|
|
|
$products = $this->handlers->h_oledrion_products->getPromotionalProducts(new Oledrion_parameters(array( |
|
|
|
|
230
|
|
|
'start' => $start, |
231
|
|
|
'limit' => $limit, |
232
|
|
|
'category' => $category, |
233
|
|
|
'sort' => $sort, |
234
|
|
|
'order' => $order |
235
|
|
|
))); |
236
|
|
|
break; |
237
|
|
|
|
238
|
|
View Code Duplication |
case 'random': |
|
|
|
|
239
|
|
|
$products = $this->handlers->h_oledrion_products->getRandomProducts(new Oledrion_parameters(array( |
|
|
|
|
240
|
|
|
'start' => $start, |
241
|
|
|
'limit' => $limit, |
242
|
|
|
'category' => $category, |
243
|
|
|
'sort' => $sort, |
244
|
|
|
'order' => $order, |
245
|
|
|
'thisMonthOnly' => $thisMonthOnly |
246
|
|
|
))); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
if (count($products) > 0) { |
250
|
|
|
$productsIds = array_keys($products); |
251
|
|
|
} else { |
252
|
|
|
return $ret; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
// Recherche des Id des catégories et des vendeurs |
256
|
|
|
foreach ($products as $product) { |
257
|
|
|
$categoriesIds[] = $product->getVar('product_cid'); |
258
|
|
|
$vendorsIds[] = $product->getVar('product_vendor_id'); |
259
|
|
|
if ($withXoopsUser) { |
260
|
|
|
$xoopsUsersIDs[] = $product->getVar('product_submitter'); |
261
|
|
|
} |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
$productsManufacturers = $this->handlers->h_oledrion_productsmanu->getFromProductsIds($productsIds); |
|
|
|
|
265
|
|
|
// Regroupement des fabricants par produit |
266
|
|
View Code Duplication |
foreach ($productsManufacturers as $item) { |
|
|
|
|
267
|
|
|
$manufacturersIds[] = $item->getVar('pm_manu_id'); |
268
|
|
|
$manufacturersPerProduct[$item->getVar('pm_product_id')][] = $item; |
269
|
|
|
} |
270
|
|
|
// On récupère la liste des personnes qui ont soumis les produits |
271
|
|
|
if ($withXoopsUser) { |
272
|
|
|
$users = Oledrion_utils::getUsersFromIds($xoopsUsersIDs); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
// Il faut récupérer la liste des produits relatifs |
276
|
|
|
if ($withRelatedProducts) { |
277
|
|
|
$relatedProducts = $this->getRelatedProductsFromProductsIds($productsIds); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
$categoriesIds = array_unique($categoriesIds); |
281
|
|
|
sort($categoriesIds); |
282
|
|
|
|
283
|
|
|
$vendorsIds = array_unique($vendorsIds); |
284
|
|
|
sort($vendorsIds); |
285
|
|
|
|
286
|
|
|
$manufacturersIds = array_unique($manufacturersIds); |
287
|
|
|
sort($manufacturersIds); |
288
|
|
|
|
289
|
|
|
// Récupération des fabricants, des vendeurs et des catégories |
290
|
|
|
if (count($manufacturersIds) > 0) { |
291
|
|
|
$manufacturers = $this->handlers->h_oledrion_manufacturer->getManufacturersFromIds($manufacturersIds); |
|
|
|
|
292
|
|
|
} |
293
|
|
|
if (count($categoriesIds) > 0) { |
294
|
|
|
$categories = $this->handlers->h_oledrion_cat->getCategoriesFromIds($categoriesIds); |
|
|
|
|
295
|
|
|
} |
296
|
|
|
if (count($vendorsIds) > 0) { |
297
|
|
|
$vendors = $this->handlers->h_oledrion_vendors->getVendorsFromIds($vendorsIds); |
|
|
|
|
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
$count = 1; |
301
|
|
|
$lastTitle = ''; |
302
|
|
|
foreach ($products as $product) { |
303
|
|
|
$tmp = array(); |
|
|
|
|
304
|
|
|
$tmp = $product->toArray(); |
305
|
|
|
$lastTitle = $product->getVar('product_title'); |
306
|
|
|
// Le vendeur |
307
|
|
|
if (isset($vendors[$product->getVar('product_vendor_id')])) { |
308
|
|
|
$tmp['product_vendor'] = $vendors[$product->getVar('product_vendor_id')]->toArray(); |
309
|
|
|
} |
310
|
|
|
// La catégorie |
311
|
|
|
if (isset($categories[$product->getVar('product_cid')])) { |
312
|
|
|
$tmp['product_category'] = $categories[$product->getVar('product_cid')]->toArray(); |
313
|
|
|
} |
314
|
|
|
// Les produits relatifs |
315
|
|
|
if ($withRelatedProducts) { |
316
|
|
|
if (isset($relatedProducts[$product->getVar('product_id')])) { |
317
|
|
|
$productsRelatedToThisOne = $relatedProducts[$product->getVar('product_id')]; |
318
|
|
|
foreach ($productsRelatedToThisOne as $oneRelatedProdut) { |
319
|
|
|
$tmp['product_related_products'][] = $oneRelatedProdut->toArray(); |
320
|
|
|
} |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
// Les fabricants du produit |
324
|
|
|
if (isset($manufacturersPerProduct[$product->getVar('product_id')])) { |
325
|
|
|
$productManufacturers = $manufacturersPerProduct[$product->getVar('product_id')]; |
326
|
|
|
$tmpManufacturersList = array(); |
327
|
|
|
foreach ($productManufacturers as $productManufacturer) { |
328
|
|
|
if (isset($manufacturers[$productManufacturer->getVar('pm_manu_id')])) { |
329
|
|
|
$manufacturer = $manufacturers[$productManufacturer->getVar('pm_manu_id')]; |
330
|
|
|
$tmp['product_manufacturers'][] = $manufacturer->toArray(); |
331
|
|
|
$tmpManufacturersList[] = $manufacturer->getVar('manu_commercialname') . ' ' . $manufacturer->getVar('manu_name'); |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
if (count($tmpManufacturersList) > 0) { |
335
|
|
|
$tmp['product_joined_manufacturers'] = implode(OLEDRION_STRING_TO_JOIN_MANUFACTURERS, $tmpManufacturersList); |
336
|
|
|
} |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
// L'utilisateur Xoops (éventuellement) |
340
|
|
|
if ($withXoopsUser && isset($users[$product->getVar('product_submitter')])) { |
341
|
|
|
$thisUser = $users[$product->getVar('product_submitter')]; |
342
|
|
|
if (xoops_trim($thisUser->getVar('name')) != '') { |
343
|
|
|
$name = $thisUser->getVar('name'); |
344
|
|
|
} else { |
345
|
|
|
$name = $thisUser->getVar('uname'); |
346
|
|
|
} |
347
|
|
|
$tmp['product_submiter_name'] = $name; |
348
|
|
|
$userLink = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $thisUser->getVar('uid') . '">' . $name . '</a>'; |
349
|
|
|
$tmp['product_submiter_link'] = $userLink; |
350
|
|
|
} |
351
|
|
|
$tmp['product_count'] = $count; // Compteur pour les templates (pour gérer les colonnes) |
352
|
|
|
$ret[] = $tmp; |
353
|
|
|
++$count; |
354
|
|
|
} |
355
|
|
|
$ret['lastTitle'] = $lastTitle; |
356
|
|
|
|
357
|
|
|
return $ret; |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.