Delivery::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 Delivery
27
 */
28
class Delivery 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('delivery_id', XOBJ_DTYPE_INT, null, false);
38
        $this->initVar('delivery_title', XOBJ_DTYPE_TXTBOX, null, false);
39
        $this->initVar('delivery_description', XOBJ_DTYPE_OTHER, null, false);
40
        $this->initVar('delivery_online', XOBJ_DTYPE_INT, null, false);
41
        $this->initVar('delivery_image', XOBJ_DTYPE_TXTBOX, null, false);
42
43
        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false);
44
    }
45
46
    /**
47
     * Retourne l'URL de l'image de la catégorie courante
48
     * @return string L'URL
49
     */
50
    public function getPictureUrl()
51
    {
52
        if ('' !== xoops_trim($this->getVar('product_image_url'))) {
53
            return OLEDRION_PICTURES_URL . '/' . $this->getVar('delivery_image');
54
        }
55
56
        return '';
57
    }
58
59
    /**
60
     * Indique si l'image de la catégorie existe
61
     *
62
     * @return bool Vrai si l'image existe sinon faux
63
     */
64
    public function pictureExists()
65
    {
66
        $return = false;
67
        if ('' !== xoops_trim($this->getVar('delivery_image')) && file_exists(OLEDRION_PICTURES_PATH . '/' . $this->getVar('delivery_image'))) {
68
            $return = true;
69
        }
70
71
        return $return;
72
    }
73
74
    /**
75
     * Supprime l'image associée à une catégorie
76
     */
77
    public function deletePicture()
78
    {
79
        if ($this->pictureExists()) {
80
            if (false === @unlink(OLEDRION_PICTURES_PATH . '/' . $this->getVar('delivery_image'))) {
81
                throw new \RuntimeException('The picture ' . OLEDRION_PICTURES_PATH . '/' . $this->getVar('delivery_image') . ' could not be deleted.');
82
            }
83
        }
84
        $this->setVar('delivery_image', '');
85
    }
86
87
    /**
88
     * Retourne les éléments du produits formatés pour affichage
89
     *
90
     * @param  string $format
91
     * @return array
92
     */
93
    public function toArray($format = 's')
94
    {
95
        global $locationDeliveryHandler;
96
        $ret                       = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
97
        $ret                       = parent::toArray($format);
98
        $ret['delivery_image_url'] = $this->getPictureUrl();
99
100
        return $ret;
101
    }
102
}
103