1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Songlist; |
4
|
|
|
|
5
|
|
|
use XoopsObject; |
6
|
|
|
|
7
|
|
|
require_once \dirname(__DIR__) . '/include/songlist.object.php'; |
8
|
|
|
// require_once \dirname(__DIR__) . '/include/songlist.form.php'; |
9
|
|
|
use XoopsModules\Songlist\Form\FormController; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Voice |
13
|
|
|
*/ |
14
|
|
|
class Voice extends XoopsObject |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Voice constructor. |
18
|
|
|
* @param null $fid |
|
|
|
|
19
|
|
|
*/ |
20
|
|
|
public function __construct($fid = null) |
21
|
|
|
{ |
22
|
|
|
$this->initVar('vcid', \XOBJ_DTYPE_INT, 0, false); |
23
|
|
|
$this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128); |
24
|
|
|
$this->initVar('artists', \XOBJ_DTYPE_INT, 0, false); |
25
|
|
|
$this->initVar('albums', \XOBJ_DTYPE_INT, 0, false); |
26
|
|
|
$this->initVar('songs', \XOBJ_DTYPE_INT, 0, false); |
27
|
|
|
$this->initVar('hits', \XOBJ_DTYPE_INT, 0, false); |
28
|
|
|
$this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false); |
29
|
|
|
$this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
30
|
|
|
$this->initVar('created', \XOBJ_DTYPE_INT, 0, false); |
31
|
|
|
$this->initVar('updated', \XOBJ_DTYPE_INT, 0, false); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param bool $as_array |
36
|
|
|
* @return array|string |
37
|
|
|
*/ |
38
|
|
|
public function getForm($as_array = false) |
39
|
|
|
{ |
40
|
|
|
return FormController::getFormVoice($this, $as_array); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function toArray(): array |
47
|
|
|
{ |
48
|
|
|
$ret = parent::toArray(); |
49
|
|
|
$form = $this->getForm(true); |
50
|
|
|
foreach ($form as $key => $element) { |
51
|
|
|
$ret['form'][$key] = $element->render(); |
52
|
|
|
} |
53
|
|
|
foreach (['created', 'updated'] as $key) { |
54
|
|
|
if ($this->getVar($key) > 0) { |
55
|
|
|
$ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
56
|
|
|
$ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
$ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
60
|
|
|
|
61
|
|
|
return $ret; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getURL(): string |
68
|
|
|
{ |
69
|
|
|
global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit; |
70
|
|
|
if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
71
|
|
|
return XOOPS_URL |
72
|
|
|
. '/' |
73
|
|
|
. $GLOBALS['songlistModuleConfig']['baseurl'] |
74
|
|
|
. '/' |
75
|
|
|
. $file |
76
|
|
|
. '/' |
77
|
|
|
. \urlencode(\str_replace([' ', \chr(9)], '-', $this->getVar('name'))) |
78
|
|
|
. '/' |
79
|
|
|
. $op |
80
|
|
|
. '-' |
81
|
|
|
. $fct |
82
|
|
|
. '-' |
83
|
|
|
. $this->getVar('gid') |
84
|
|
|
. '-' |
85
|
|
|
. \urlencode($value) |
86
|
|
|
. '-' |
87
|
|
|
. $gid |
88
|
|
|
. '-' |
89
|
|
|
. $vid |
90
|
|
|
. '-' |
91
|
|
|
. $cid |
92
|
|
|
. $GLOBALS['songlistModuleConfig']['endofurl']; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return XOOPS_URL . '/modules/songlist/' . $file . '.php?op=' . $op . '&fct=' . $fct . '&id=' . $this->getVar('gid') . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|