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 Artists |
11
|
|
|
*/ |
12
|
|
|
class Artists extends \XoopsObject |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Artists constructor. |
16
|
|
|
* @param null $fid |
|
|
|
|
17
|
|
|
*/ |
18
|
|
|
public function __construct($fid = null) |
19
|
|
|
{ |
20
|
|
|
$this->initVar('aid', \XOBJ_DTYPE_INT, 0, false); |
21
|
|
|
$this->initVar('cids', \XOBJ_DTYPE_ARRAY, [], false); |
22
|
|
|
$this->initVar('sids', \XOBJ_DTYPE_ARRAY, [], false); |
23
|
|
|
$this->initVar('name', \XOBJ_DTYPE_TXTBOX, null, false, 128); |
24
|
|
|
$this->initVar('albums', \XOBJ_DTYPE_INT, 0, false); |
25
|
|
|
$this->initVar('songs', \XOBJ_DTYPE_INT, 0, false); |
26
|
|
|
$this->initVar('hits', \XOBJ_DTYPE_INT, 0, false); |
27
|
|
|
$this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false); |
28
|
|
|
$this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
29
|
|
|
$this->initVar('created', \XOBJ_DTYPE_INT, 0, false); |
30
|
|
|
$this->initVar('updated', \XOBJ_DTYPE_INT, 0, false); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param bool $as_array |
35
|
|
|
* @return array|string |
36
|
|
|
*/ |
37
|
|
|
public function getForm($as_array = false) |
38
|
|
|
{ |
39
|
|
|
return FormController::getFormArtists($this, $as_array); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param bool $extra |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function toArray($extra = false): 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
|
|
|
|
60
|
|
|
$ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
61
|
|
|
$ret['url'] = $this->getURL(true); |
|
|
|
|
62
|
|
|
|
63
|
|
|
\xoops_loadLanguage('enum', 'songlist'); |
64
|
|
|
if (!empty($ret['singer'])) { |
65
|
|
|
$ret['singer'] = \constant($ret['singer']); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if (!$extra) { |
69
|
|
|
return $ret; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (0 != \count($this->getVar('cids'))) { |
|
|
|
|
73
|
|
|
$categoriesHandler = Helper::getInstance()->getHandler('Category'); |
74
|
|
|
foreach ($this->getVar('cids') as $aid) { |
75
|
|
|
$category = $categoriesHandler->get($aid); |
76
|
|
|
if (\is_object($category)) { |
77
|
|
|
$ret['categories_array'][$aid] = $category->toArray(false); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (\is_array($this->getVar('aids')) && 0 != \count($this->getVar('aids'))) { |
83
|
|
|
$artistsHandler = Helper::getInstance()->getHandler('Artists'); |
84
|
|
|
foreach ($this->getVar('aids') as $aid) { |
85
|
|
|
$artist = $artistsHandler->get($aid); |
86
|
|
|
if (\is_object($artist)) { |
87
|
|
|
$ret['artists_array'][$aid] = $artist->toArray(false); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if (0 != \count($this->getVar('sids'))) { |
93
|
|
|
$songsHandler = Helper::getInstance()->getHandler('Songs'); |
94
|
|
|
$criteria = new \Criteria('aids', '%"' . $this->getVar('aid') . '"%', 'LIKE'); |
95
|
|
|
$criteria->setSort('songid'); |
96
|
|
|
$criteria->setOrder('ASC'); |
97
|
|
|
foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) { |
98
|
|
|
if (\is_object($song)) { |
99
|
|
|
$ret['songs_array'][$sid] = $song->toArray(false); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $ret; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public function getURL(): string |
111
|
|
|
{ |
112
|
|
|
global $file, $op, $fct, $id, $value, $gid, $vid, $vcid, $cid, $start, $limit; |
113
|
|
|
if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
114
|
|
|
if (0 != $id) { |
115
|
|
|
$artistHandler = Helper::getInstance()->getHandler('Artists'); |
116
|
|
|
$artist = $artistHandler->get($id); |
117
|
|
|
if (\is_object($artist) && !$artist->isNew()) { |
118
|
|
|
return XOOPS_URL |
119
|
|
|
. '/' |
120
|
|
|
. $GLOBALS['songlistModuleConfig']['baseofurl'] |
121
|
|
|
. '/artists/' |
122
|
|
|
. \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('name'))) |
123
|
|
|
. '/' |
124
|
|
|
. $start |
125
|
|
|
. '-' |
126
|
|
|
. $id |
127
|
|
|
. '-' |
128
|
|
|
. $op |
129
|
|
|
. '-' |
130
|
|
|
. $fct |
131
|
|
|
. '-' |
132
|
|
|
. $gid |
133
|
|
|
. '-' |
134
|
|
|
. $cid |
135
|
|
|
. '/' |
136
|
|
|
. \urlencode($value) |
137
|
|
|
. $GLOBALS['songlistModuleConfig']['endofurl']; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/artists/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '-' . $vcid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/artists/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '-' . $vcid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return XOOPS_URL . '/modules/songlist/artists.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|