Genre::getForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Songlist;
4
5
require_once \dirname(__DIR__) . '/include/songlist.object.php';
6
// require_once \dirname(__DIR__) . '/include/songlist.form.php';
7
use  XoopsModules\Songlist\Form\FormController;
8
9
/**
10
 * Class Genre
11
 */
12
class Genre extends \XoopsObject
13
{
14
    /**
15
     * Genre constructor.
16
     * @param null $fid
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fid is correct as it would always require null to be passed?
Loading history...
17
     */
18
    public function __construct($fid = null)
19
    {
20
        $this->initVar('gid', \XOBJ_DTYPE_INT, 0, false);
21
        $this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128);
22
        $this->initVar('artists', \XOBJ_DTYPE_INT, 0, false);
23
        $this->initVar('albums', \XOBJ_DTYPE_INT, 0, false);
24
        $this->initVar('songs', \XOBJ_DTYPE_INT, 0, false);
25
        $this->initVar('hits', \XOBJ_DTYPE_INT, 0, false);
26
        $this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false);
27
        $this->initVar('votes', \XOBJ_DTYPE_INT, 0, false);
28
        $this->initVar('created', \XOBJ_DTYPE_INT, 0, false);
29
        $this->initVar('updated', \XOBJ_DTYPE_INT, 0, false);
30
    }
31
32
    /**
33
     * @param bool $as_array
34
     * @return array|string
35
     */
36
    public function getForm($as_array = false)
37
    {
38
        return FormController::getFormGenre($this, $as_array);
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function toArray(): array
45
    {
46
        $ret  = parent::toArray();
47
        $form = $this->getForm(true);
48
        foreach ($form as $key => $element) {
49
            $ret['form'][$key] = $element->render();
50
        }
51
        foreach (['created', 'updated'] as $key) {
52
            if ($this->getVar($key) > 0) {
53
                $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key));
54
                $ret[$key]         = \date(_DATESTRING, $this->getVar($key));
55
            }
56
        }
57
        $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN;
58
59
        return $ret;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getURL(): string
66
    {
67
        global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit;
68
        if ($GLOBALS['songlistModuleConfig']['htaccess']) {
69
            return XOOPS_URL
70
                   . '/'
71
                   . $GLOBALS['songlistModuleConfig']['baseurl']
72
                   . '/'
73
                   . $file
74
                   . '/'
75
                   . \urlencode(\str_replace([' ', \chr(9)], '-', $this->getVar('name')))
76
                   . '/'
77
                   . $op
78
                   . '-'
79
                   . $fct
80
                   . '-'
81
                   . $this->getVar('gid')
82
                   . '-'
83
                   . \urlencode($value)
84
                   . '-'
85
                   . $gid
86
                   . '-'
87
                   . $cid
88
                   . $GLOBALS['songlistModuleConfig']['endofurl'];
89
        }
90
91
        return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $this->getVar('gid') . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&cid=' . $cid;
92
    }
93
}
94