Payment::getPictureUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
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 Payment
27
 */
28
class Payment 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('payment_id', XOBJ_DTYPE_INT, null, false);
38
        $this->initVar('payment_title', XOBJ_DTYPE_TXTBOX, null, false);
39
        $this->initVar('payment_description', XOBJ_DTYPE_OTHER, null, false);
40
        $this->initVar('payment_online', XOBJ_DTYPE_INT, null, false);
41
        $this->initVar('payment_type', XOBJ_DTYPE_TXTBOX, null, false);
42
        $this->initVar('payment_gateway', XOBJ_DTYPE_TXTBOX, null, false);
43
        $this->initVar('payment_image', XOBJ_DTYPE_TXTBOX, null, 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('payment_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('payment_image')) && file_exists(OLEDRION_PICTURES_PATH . '/' . $this->getVar('payment_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('payment_image'))) {
81
                throw new \RuntimeException('The picture ' . OLEDRION_PICTURES_PATH . '/' . $this->getVar('payment_image') . ' could not be deleted.');
82
            }
83
        }
84
        $this->setVar('payment_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
        $ret                      = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
96
        $ret                      = parent::toArray($format);
97
        $ret['payment_image_url'] = $this->getPictureUrl();
98
99
        return $ret;
100
    }
101
}
102