Completed
Push — master ( 00e474...9d3fbd )
by Michael
04:26
created

class/oledrion_packing.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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'));
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
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(
0 ignored issues
show
new \Oledrion_parameters...id', 'order' => 'ASC')) is of type object<Oledrion_parameters>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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