|
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 Hossein Azizabadi ([email protected]) |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
use XoopsModules\Oledrion; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class Packing |
|
27
|
|
|
*/ |
|
28
|
|
|
class Packing extends OledrionObject |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* constructor |
|
32
|
|
|
* |
|
33
|
|
|
* normally, this is called from child classes only |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->initVar('packing_id', XOBJ_DTYPE_INT, null, false); |
|
38
|
|
|
$this->initVar('packing_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
39
|
|
|
$this->initVar('packing_width', XOBJ_DTYPE_TXTBOX, null, false); |
|
40
|
|
|
$this->initVar('packing_length', XOBJ_DTYPE_TXTBOX, null, false); |
|
41
|
|
|
$this->initVar('packing_weight', XOBJ_DTYPE_TXTBOX, null, false); |
|
42
|
|
|
$this->initVar('packing_image', XOBJ_DTYPE_TXTBOX, null, false); |
|
43
|
|
|
$this->initVar('packing_description', XOBJ_DTYPE_OTHER, null, false); |
|
44
|
|
|
$this->initVar('packing_price', XOBJ_DTYPE_INT, null, false); |
|
45
|
|
|
$this->initVar('packing_online', XOBJ_DTYPE_INT, null, false); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Retourne l'URL de l'image de la catégorie courante |
|
50
|
|
|
* @return string L'URL |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getPictureUrl() |
|
53
|
|
|
{ |
|
54
|
|
|
if ('' !== xoops_trim($this->getVar('product_image_url'))) { |
|
55
|
|
|
return OLEDRION_PICTURES_URL . '/' . $this->getVar('packing_image'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return ''; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Indique si l'image de la catégorie existe |
|
63
|
|
|
* |
|
64
|
|
|
* @return bool Vrai si l'image existe sinon faux |
|
65
|
|
|
*/ |
|
66
|
|
|
public function pictureExists() |
|
67
|
|
|
{ |
|
68
|
|
|
$return = false; |
|
69
|
|
|
if ('' !== xoops_trim($this->getVar('packing_image')) && file_exists(OLEDRION_PICTURES_PATH . '/' . $this->getVar('packing_image'))) { |
|
70
|
|
|
$return = true; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $return; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Supprime l'image associée à une catégorie |
|
78
|
|
|
*/ |
|
79
|
|
|
public function deletePicture() |
|
80
|
|
|
{ |
|
81
|
|
|
if ($this->pictureExists()) { |
|
82
|
|
|
if (false === @unlink(OLEDRION_PICTURES_PATH . '/' . $this->getVar('packing_image'))) { |
|
83
|
|
|
throw new \RuntimeException('The picture ' . OLEDRION_PICTURES_PATH . '/' . $this->getVar('packing_image') . ' could not be deleted.'); |
|
84
|
|
|
} |
|
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
|
|
|
public function toArray($format = 's') |
|
96
|
|
|
{ |
|
97
|
|
|
$oledrionCurrency = Oledrion\Currency::getInstance(); |
|
98
|
|
|
$ret = []; |
|
|
|
|
|
|
99
|
|
|
$ret = parent::toArray($format); |
|
100
|
|
|
$ret['packing_price_fordisplay'] = $oledrionCurrency->amountForDisplay($this->getVar('packing_price')); |
|
101
|
|
|
$ret['packing_image_url'] = $this->getPictureUrl(); |
|
102
|
|
|
|
|
103
|
|
|
return $ret; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|