|
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
|
|
|
* Gestion des fabricants |
|
22
|
|
|
*/ |
|
23
|
|
|
require __DIR__ . '/classheader.php'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class Oledrion_manufacturer |
|
27
|
|
|
*/ |
|
28
|
|
|
class Oledrion_manufacturer extends Oledrion_Object |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* constructor |
|
32
|
|
|
* |
|
33
|
|
|
* normally, this is called from child classes only |
|
34
|
|
|
* |
|
35
|
|
|
* @access public |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->initVar('manu_id', XOBJ_DTYPE_INT, null, false); |
|
40
|
|
|
$this->initVar('manu_name', XOBJ_DTYPE_TXTBOX, null, false); |
|
41
|
|
|
$this->initVar('manu_commercialname', XOBJ_DTYPE_TXTBOX, null, false); |
|
42
|
|
|
$this->initVar('manu_email', XOBJ_DTYPE_TXTBOX, null, false); |
|
43
|
|
|
$this->initVar('manu_bio', XOBJ_DTYPE_TXTAREA, null, false); |
|
44
|
|
|
$this->initVar('manu_url', XOBJ_DTYPE_TXTBOX, null, false); |
|
45
|
|
|
$this->initVar('manu_photo1', XOBJ_DTYPE_TXTBOX, null, false); |
|
46
|
|
|
$this->initVar('manu_photo2', XOBJ_DTYPE_TXTBOX, null, false); |
|
47
|
|
|
$this->initVar('manu_photo3', XOBJ_DTYPE_TXTBOX, null, false); |
|
48
|
|
|
$this->initVar('manu_photo4', XOBJ_DTYPE_TXTBOX, null, false); |
|
49
|
|
|
$this->initVar('manu_photo5', XOBJ_DTYPE_TXTBOX, null, false); |
|
50
|
|
|
// Pour autoriser le html |
|
51
|
|
|
$this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Retourne l'URL d'une des 5 images du fabricant courant |
|
56
|
|
|
* |
|
57
|
|
|
* @param integer $pictureNumber Le numéro (de 1 à 5) de l'image que l'on souhaite récupérer |
|
58
|
|
|
* @return mixed L'URL Soit l'url de l'image soit False si l'indice passé en paramètre n'est pas correct |
|
59
|
|
|
*/ |
|
60
|
|
View Code Duplication |
public function getPictureUrl($pictureNumber) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
$pictureNumber = (int)$pictureNumber; |
|
63
|
|
|
if ($pictureNumber > 0 && $pictureNumber < 6) { |
|
64
|
|
|
return OLEDRION_PICTURES_URL . '/' . $this->getVar('manu_photo' . $pictureNumber); |
|
65
|
|
|
} else { |
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Retourne le chemin de l'une des 5 images du fabricant courant |
|
72
|
|
|
* |
|
73
|
|
|
* @param integer $pictureNumber Le numéro (de 1 à 5) de l'image que l'on souhaite récupérer |
|
74
|
|
|
* @return string Le chemin |
|
|
|
|
|
|
75
|
|
|
*/ |
|
76
|
|
View Code Duplication |
public function getPicturePath($pictureNumber) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
$pictureNumber = (int)$pictureNumber; |
|
79
|
|
|
if ($pictureNumber > 0 && $pictureNumber < 6) { |
|
80
|
|
|
return OLEDRION_PICTURES_PATH . '/' . $this->getVar('manu_photo' . $pictureNumber); |
|
81
|
|
|
} else { |
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Indique si une des 5 images du fabricant existe |
|
88
|
|
|
* |
|
89
|
|
|
* @param integer $pictureNumber Le numéro (de 1 à 5) de l'image que l'on souhaite récupérer |
|
90
|
|
|
* @return boolean Vrai si l'image existe sinon faux |
|
91
|
|
|
*/ |
|
92
|
|
|
public function pictureExists($pictureNumber) |
|
93
|
|
|
{ |
|
94
|
|
|
$pictureNumber = (int)$pictureNumber; |
|
95
|
|
|
$return = false; |
|
96
|
|
|
if ($pictureNumber > 0 && $pictureNumber < 6) { |
|
97
|
|
|
if (xoops_trim($this->getVar('manu_photo' . $pictureNumber)) != '' |
|
98
|
|
|
&& file_exists(OLEDRION_PICTURES_PATH . '/' . $this->getVar('manu_photo' . $pictureNumber)) |
|
99
|
|
|
) { |
|
100
|
|
|
$return = true; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $return; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Supprime une des 5 images du fabricant |
|
109
|
|
|
* |
|
110
|
|
|
* @param integer $pictureNumber Le numéro (de 1 à 5) de l'image que l'on souhaite récupérer |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
public function deletePicture($pictureNumber) |
|
114
|
|
|
{ |
|
115
|
|
|
$pictureNumber = (int)$pictureNumber; |
|
116
|
|
|
if ($pictureNumber > 0 && $pictureNumber < 6) { |
|
117
|
|
|
if ($this->pictureExists($pictureNumber)) { |
|
118
|
|
|
@unlink(OLEDRION_PICTURES_PATH . '/' . $this->getVar('manu_photo' . $pictureNumber)); |
|
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
$this->setVar('manu_photo' . $pictureNumber, ''); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Supprime toutes les images du fabricant (raccourcis) |
|
126
|
|
|
* @return void |
|
127
|
|
|
*/ |
|
128
|
|
|
public function deletePictures() |
|
129
|
|
|
{ |
|
130
|
|
|
for ($i = 1; $i <= 5; ++$i) { |
|
131
|
|
|
$this->deletePicture($i); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Retourne l'url à utiliser pour accéder à la page d'un fabricant |
|
137
|
|
|
* |
|
138
|
|
|
* @return string |
|
139
|
|
|
*/ |
|
140
|
|
View Code Duplication |
public function getLink() |
|
|
|
|
|
|
141
|
|
|
{ |
|
142
|
|
|
$url = ''; |
|
|
|
|
|
|
143
|
|
|
if (Oledrion_utils::getModuleOption('urlrewriting') == 1) { // On utilise l'url rewriting |
|
144
|
|
|
$url = OLEDRION_URL . 'manufacturer-' . $this->getVar('manu_id') . Oledrion_utils::makeSeoUrl($this->getVar('manu_commercialname', 'n') . ' ' . $this->getVar('manu_name')) . '.html'; |
|
145
|
|
|
} else { // Pas d'utilisation de l'url rewriting |
|
146
|
|
|
$url = OLEDRION_URL . 'manufacturer.php?manu_id=' . $this->getVar('manu_id'); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
return $url; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Rentourne la chaine à envoyer dans une balise <a> pour l'attribut href |
|
154
|
|
|
* |
|
155
|
|
|
* @return string |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getHrefTitle() |
|
158
|
|
|
{ |
|
159
|
|
|
return Oledrion_utils::makeHrefTitle($this->getVar('manu_commercialname') . ' ' . $this->getVar('manu_name')); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Retourne l'initiale du fabricant (à modifier selon le sens de l'écriture !) |
|
164
|
|
|
* @return string L'initiale |
|
165
|
|
|
*/ |
|
166
|
|
|
public function getInitial() |
|
167
|
|
|
{ |
|
168
|
|
|
return strtoupper(substr($this->getVar('manu_name'), 0, 1)); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Retourne les éléments du fabricant formatés pour affichage |
|
173
|
|
|
* |
|
174
|
|
|
* @param string $format Le format à utiliser |
|
175
|
|
|
* @return array Les informations formatées |
|
176
|
|
|
*/ |
|
177
|
|
|
public function toArray($format = 's') |
|
178
|
|
|
{ |
|
179
|
|
|
$ret = array(); |
|
|
|
|
|
|
180
|
|
|
$ret = parent::toArray($format); |
|
181
|
|
|
for ($i = 1; $i <= 5; ++$i) { |
|
182
|
|
|
$ret['manu_photo' . $i . '_url'] = $this->getPictureUrl($i); |
|
183
|
|
|
} |
|
184
|
|
|
$ret['manu_url_rewrited'] = $this->getLink(); |
|
185
|
|
|
$ret['manu_href_title'] = $this->getHrefTitle(); |
|
186
|
|
|
$ret['manu_initial'] = $this->getInitial(); |
|
187
|
|
|
|
|
188
|
|
|
return $ret; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Class OledrionOledrion_manufacturerHandler |
|
194
|
|
|
*/ |
|
195
|
|
|
class OledrionOledrion_manufacturerHandler extends Oledrion_XoopsPersistableObjectHandler |
|
|
|
|
|
|
196
|
|
|
{ |
|
197
|
|
|
/** |
|
198
|
|
|
* OledrionOledrion_manufacturerHandler constructor. |
|
199
|
|
|
* @param XoopsDatabase|null $db |
|
200
|
|
|
*/ |
|
201
|
|
|
public function __construct(XoopsDatabase $db) |
|
202
|
|
|
{ // Table Classe Id Identifiant |
|
203
|
|
|
parent::__construct($db, 'oledrion_manufacturer', 'oledrion_manufacturer', 'manu_id', 'manu_commercialname'); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Renvoie l'alphabet à partir de la première lettre du nom des fabricants |
|
208
|
|
|
* |
|
209
|
|
|
* @return array l'alphabet des lettres utilisées ! |
|
210
|
|
|
*/ |
|
211
|
|
View Code Duplication |
public function getAlphabet() |
|
|
|
|
|
|
212
|
|
|
{ |
|
213
|
|
|
global $myts; |
|
|
|
|
|
|
214
|
|
|
$ret = array(); |
|
215
|
|
|
$sql = 'SELECT DISTINCT (UPPER(SUBSTRING(manu_name, 1, 1))) as oneletter FROM ' . $this->table; |
|
216
|
|
|
$result = $this->db->query($sql); |
|
217
|
|
|
if (!$result) { |
|
218
|
|
|
return $ret; |
|
219
|
|
|
} |
|
220
|
|
|
while ($myrow = $this->db->fetchArray($result)) { |
|
221
|
|
|
$ret[] = $myts->htmlSpecialChars($myrow['oneletter']); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
return $ret; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Supprime un fabricant et tout ce qui est relatif |
|
229
|
|
|
* |
|
230
|
|
|
* @param oledrion_manufacturer $manufacturer |
|
231
|
|
|
* @return boolean Le résultat de la suppression |
|
232
|
|
|
*/ |
|
233
|
|
|
public function deleteManufacturer(Oledrion_manufacturer $manufacturer) |
|
234
|
|
|
{ |
|
235
|
|
|
$manufacturer->deletePictures(); |
|
236
|
|
|
|
|
237
|
|
|
return $this->delete($manufacturer, true); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Retourne le nombre de produits associés à un fabricant |
|
242
|
|
|
* |
|
243
|
|
|
* @param integer $manu_id L'identifiant du fabricant |
|
244
|
|
|
* @return integer Le nombre de produis associés à un fabricant |
|
245
|
|
|
*/ |
|
246
|
|
|
public function getManufacturerProductsCount($manu_id) |
|
247
|
|
|
{ |
|
248
|
|
|
global $h_oledrion_productsmanu; |
|
|
|
|
|
|
249
|
|
|
|
|
250
|
|
|
return $h_oledrion_productsmanu->getManufacturerProductsCount($manu_id); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Retourne des fabricants en fonction de leur IDs |
|
255
|
|
|
* |
|
256
|
|
|
* @param array $ids Les identifiants des produits |
|
257
|
|
|
* @return array Tableau d'objets de type oledrion_productsmanu |
|
258
|
|
|
*/ |
|
259
|
|
View Code Duplication |
public function getManufacturersFromIds($ids) |
|
|
|
|
|
|
260
|
|
|
{ |
|
261
|
|
|
$ret = array(); |
|
262
|
|
|
if (is_array($ids) && count($ids) > 0) { |
|
263
|
|
|
$criteria = new Criteria('manu_id', '(' . implode(',', $ids) . ')', 'IN'); |
|
264
|
|
|
$ret = $this->getObjects($criteria, true, true, '*', false); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
return $ret; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* Retourne les produits d'un fabricant (note, ce code serait mieux dans une facade) |
|
272
|
|
|
* |
|
273
|
|
|
* @param integer $manu_id Le fabricant dont on veut récupérer les produits |
|
274
|
|
|
* @param integer $start Position de départ |
|
275
|
|
|
* @param integer $limit Nombre maximum d'enregistrements à renvoyer |
|
276
|
|
|
* @return array Objects de type oledrion_products |
|
277
|
|
|
*/ |
|
278
|
|
|
public function getManufacturerProducts($manu_id, $start = 0, $limit = 0) |
|
279
|
|
|
{ |
|
280
|
|
|
$ret = $productsIds = array(); |
|
|
|
|
|
|
281
|
|
|
global $h_oledrion_productsmanu, $h_oledrion_products; |
|
|
|
|
|
|
282
|
|
|
// On commence par récupérer les ID des produits |
|
283
|
|
|
$productsIds = $h_oledrion_productsmanu->getProductsIdsFromManufacturer($manu_id, $start, $limit); |
|
284
|
|
|
// Puis les produits eux même |
|
285
|
|
|
$ret = $h_oledrion_products->getProductsFromIDs($productsIds); |
|
286
|
|
|
|
|
287
|
|
|
return $ret; |
|
288
|
|
|
} |
|
289
|
|
|
} |
|
290
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.