|
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 Hossein Azizabadi ([email protected]) |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
require __DIR__ . '/classheader.php'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class Oledrion_packing |
|
24
|
|
|
*/ |
|
25
|
|
|
class Oledrion_packing extends Oledrion_Object |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* constructor |
|
29
|
|
|
* |
|
30
|
|
|
* normally, this is called from child classes only |
|
31
|
|
|
* |
|
32
|
|
|
* @access public |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->initVar('packing_id', XOBJ_DTYPE_INT, null, false); |
|
37
|
|
|
$this->initVar('packing_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
38
|
|
|
$this->initVar('packing_width', XOBJ_DTYPE_TXTBOX, null, false); |
|
39
|
|
|
$this->initVar('packing_length', XOBJ_DTYPE_TXTBOX, null, false); |
|
40
|
|
|
$this->initVar('packing_weight', XOBJ_DTYPE_TXTBOX, null, false); |
|
41
|
|
|
$this->initVar('packing_image', XOBJ_DTYPE_TXTBOX, null, false); |
|
42
|
|
|
$this->initVar('packing_description', XOBJ_DTYPE_TXTAREA, null, false); |
|
43
|
|
|
$this->initVar('packing_price', XOBJ_DTYPE_INT, null, false); |
|
44
|
|
|
$this->initVar('packing_online', XOBJ_DTYPE_INT, null, false); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Retourne l'URL de l'image de la catégorie courante |
|
49
|
|
|
* @return string L'URL |
|
50
|
|
|
*/ |
|
51
|
|
View Code Duplication |
public function getPictureUrl() |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
if (xoops_trim($this->getVar('product_image_url')) != '') { |
|
54
|
|
|
return OLEDRION_PICTURES_URL . '/' . $this->getVar('packing_image'); |
|
55
|
|
|
} else { |
|
56
|
|
|
return ''; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Indique si l'image de la catégorie existe |
|
62
|
|
|
* |
|
63
|
|
|
* @return boolean Vrai si l'image existe sinon faux |
|
64
|
|
|
*/ |
|
65
|
|
View Code Duplication |
public function pictureExists() |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
$return = false; |
|
68
|
|
|
if (xoops_trim($this->getVar('packing_image')) != '' |
|
69
|
|
|
&& file_exists(OLEDRION_PICTURES_PATH . '/' . $this->getVar('packing_image')) |
|
70
|
|
|
) { |
|
71
|
|
|
$return = true; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $return; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Supprime l'image associée à une catégorie |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
View Code Duplication |
public function deletePicture() |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
if ($this->pictureExists()) { |
|
84
|
|
|
@unlink(OLEDRION_PICTURES_PATH . '/' . $this->getVar('packing_image')); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
$this->setVar('packing_image', ''); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Retourne les éléments du produits formatés pour affichage |
|
91
|
|
|
* |
|
92
|
|
|
* @param string $format |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
|
View Code Duplication |
public function toArray($format = 's') |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
$oledrion_Currency = Oledrion_Currency::getInstance(); |
|
98
|
|
|
$ret = array(); |
|
|
|
|
|
|
99
|
|
|
$ret = parent::toArray($format); |
|
100
|
|
|
$ret['packing_price_fordisplay'] = $oledrion_Currency->amountForDisplay($this->getVar('packing_price')); |
|
101
|
|
|
$ret['packing_image_url'] = $this->getPictureUrl(); |
|
102
|
|
|
|
|
103
|
|
|
return $ret; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Class OledrionOledrion_packingHandler |
|
109
|
|
|
*/ |
|
110
|
|
|
class OledrionOledrion_packingHandler extends Oledrion_XoopsPersistableObjectHandler |
|
|
|
|
|
|
111
|
|
|
{ |
|
112
|
|
|
/** |
|
113
|
|
|
* OledrionOledrion_packingHandler constructor. |
|
114
|
|
|
* @param XoopsDatabase|null $db |
|
115
|
|
|
*/ |
|
116
|
|
|
public function __construct(XoopsDatabase $db) |
|
117
|
|
|
{ // Table Classe Id |
|
118
|
|
|
parent::__construct($db, 'oledrion_packing', 'oledrion_packing', 'packing_id'); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param Oledrion_parameters $parameters |
|
123
|
|
|
* @return array |
|
124
|
|
|
*/ |
|
125
|
|
View Code Duplication |
public function getAllPacking(Oledrion_parameters $parameters) |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
$parameters = $parameters->extend(new Oledrion_parameters(array( |
|
|
|
|
|
|
128
|
|
|
'start' => 0, |
|
129
|
|
|
'limit' => 0, |
|
130
|
|
|
'sort' => 'packing_id', |
|
131
|
|
|
'order' => 'ASC' |
|
132
|
|
|
))); |
|
133
|
|
|
$critere = new Criteria('packing_id', 0, '<>'); |
|
134
|
|
|
$critere->setLimit($parameters['limit']); |
|
135
|
|
|
$critere->setStart($parameters['start']); |
|
136
|
|
|
$critere->setSort($parameters['sort']); |
|
137
|
|
|
$critere->setOrder($parameters['order']); |
|
138
|
|
|
$packings = array(); |
|
|
|
|
|
|
139
|
|
|
$packings = $this->getObjects($critere); |
|
140
|
|
|
|
|
141
|
|
|
return $packings; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @return array |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getPacking() |
|
148
|
|
|
{ |
|
149
|
|
|
$ret = array(); |
|
150
|
|
|
$critere = new CriteriaCompo(); |
|
151
|
|
|
$critere->add(new Criteria('packing_online', '1')); |
|
152
|
|
|
$packings = $this->getObjects($critere); |
|
153
|
|
|
foreach ($packings as $root) { |
|
154
|
|
|
$tab = array(); |
|
|
|
|
|
|
155
|
|
|
$tab = $root->toArray(); |
|
156
|
|
|
$ret[] = $tab; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
return $ret; |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
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.