|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Oledrion; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
You may not change or alter any portion of this comment or credits |
|
7
|
|
|
of supporting developers from this source code or any supporting source code |
|
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
|
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* oledrion |
|
17
|
|
|
* |
|
18
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
19
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
|
20
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Relation entre listes utilisateurs et produits |
|
25
|
|
|
* |
|
26
|
|
|
* @since 2.3.2009.06.13 |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
use XoopsModules\Oledrion; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Class ProductsListHandler |
|
33
|
|
|
*/ |
|
34
|
|
|
class ProductsListHandler extends OledrionPersistableObjectHandler |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* ProductsListHandler constructor. |
|
38
|
|
|
* @param \XoopsDatabase|null $db |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(\XoopsDatabase $db = null) |
|
41
|
|
|
{ |
|
42
|
|
|
// Table Classe Id |
|
43
|
|
|
parent::__construct($db, 'oledrion_products_list', ProductsList::class, 'productlist_id'); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Supprime les produits liés à une liste |
|
48
|
|
|
* |
|
49
|
|
|
* @param Lists $list |
|
50
|
|
|
* @return bool |
|
51
|
|
|
*/ |
|
52
|
|
|
public function deleteListProducts(Lists $list) |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->deleteAll(new \Criteria('productlist_list_id', $list->list_id, '=')); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Supprime un produit de toutes les listes |
|
59
|
|
|
* |
|
60
|
|
|
* @param int $productlist_product_id |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
|
|
public function deleteProductFromLists($productlist_product_id) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->deleteAll(new \Criteria('productlist_product_id', $productlist_product_id, '=')); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Retourne la liste des produits appartenants à une liste |
|
70
|
|
|
* |
|
71
|
|
|
* @param Lists $list |
|
72
|
|
|
* @return array |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getProductsFromList(Lists $list) |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->getObjects(new \Criteria('productlist_list_id', $list->getVar('list_id'), '=')); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Supprime un produit d'une liste |
|
81
|
|
|
* |
|
82
|
|
|
* @param int $productlist_list_id |
|
83
|
|
|
* @param int $productlist_product_id |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public function deleteProductFromList($productlist_list_id, $productlist_product_id) |
|
87
|
|
|
{ |
|
88
|
|
|
$criteria = new \CriteriaCompo(); |
|
89
|
|
|
$criteria->add(new \Criteria('productlist_list_id', $productlist_list_id, '=')); |
|
90
|
|
|
$criteria->add(new \Criteria('productlist_product_id', $productlist_product_id, '=')); |
|
91
|
|
|
|
|
92
|
|
|
return $this->deleteAll($criteria); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Ajoute un produit à une liste utilisateur |
|
97
|
|
|
* |
|
98
|
|
|
* @param $productlist_list_id |
|
99
|
|
|
* @param int $productlist_product_id Id du produit |
|
100
|
|
|
* @return bool |
|
101
|
|
|
* @internal param int $productlist_id Id de la liste |
|
102
|
|
|
*/ |
|
103
|
|
|
public function addProductToUserList($productlist_list_id, $productlist_product_id) |
|
104
|
|
|
{ |
|
105
|
|
|
$product_list = $this->create(true); |
|
106
|
|
|
$product_list->setVar('productlist_list_id', (int)$productlist_list_id); |
|
107
|
|
|
$product_list->setVar('productlist_product_id', (int)$productlist_product_id); |
|
108
|
|
|
$product_list->setVar('productlist_date', Oledrion\Utility::getCurrentSQLDate()); |
|
109
|
|
|
|
|
110
|
|
|
return $this->insert($product_list, true); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Indique si un produit se trouve déjà dans une liste |
|
115
|
|
|
* |
|
116
|
|
|
* @param int $productlist_list_id |
|
117
|
|
|
* @param int $productlist_product_id |
|
118
|
|
|
* @return bool |
|
119
|
|
|
*/ |
|
120
|
|
|
public function isProductAlreadyInList($productlist_list_id, $productlist_product_id) |
|
121
|
|
|
{ |
|
122
|
|
|
$criteria = new \CriteriaCompo(); |
|
123
|
|
|
$criteria->add(new \Criteria('productlist_list_id', $productlist_list_id, '=')); |
|
124
|
|
|
$criteria->add(new \Criteria('productlist_product_id', $productlist_product_id, '=')); |
|
125
|
|
|
|
|
126
|
|
|
return $this->getCount($criteria) > 0; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|