|
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 Albums |
|
11
|
|
|
*/ |
|
12
|
|
|
class Albums extends \XoopsObject |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Albums constructor. |
|
16
|
|
|
* @param null $fid |
|
|
|
|
|
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct($fid = null) |
|
19
|
|
|
{ |
|
20
|
|
|
$this->initVar('abid', \XOBJ_DTYPE_INT, 0, false); |
|
21
|
|
|
$this->initVar('cid', \XOBJ_DTYPE_INT, 0, false); |
|
22
|
|
|
$this->initVar('aids', \XOBJ_DTYPE_ARRAY, [], false); |
|
23
|
|
|
$this->initVar('sids', \XOBJ_DTYPE_ARRAY, [], false); |
|
24
|
|
|
$this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false, 128); |
|
25
|
|
|
$this->initVar('image', \XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
26
|
|
|
$this->initVar('path', \XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
27
|
|
|
$this->initVar('artists', \XOBJ_DTYPE_INT, 0, false); |
|
28
|
|
|
$this->initVar('songs', \XOBJ_DTYPE_INT, 0, false); |
|
29
|
|
|
$this->initVar('hits', \XOBJ_DTYPE_INT, 0, false); |
|
30
|
|
|
$this->initVar('rank', \XOBJ_DTYPE_DECIMAL, 0, false); |
|
31
|
|
|
$this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
|
32
|
|
|
$this->initVar('created', \XOBJ_DTYPE_INT, 0, false); |
|
33
|
|
|
$this->initVar('updated', \XOBJ_DTYPE_INT, 0, false); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param bool $as_array |
|
38
|
|
|
* @return array|string |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getForm($as_array = false) |
|
41
|
|
|
{ |
|
42
|
|
|
return FormController::getFormAlbums($this, $as_array); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param bool $extra |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
|
|
public function toArray($extra = true): array |
|
50
|
|
|
{ |
|
51
|
|
|
$ret = parent::toArray(); |
|
52
|
|
|
$form = $this->getForm(true); |
|
53
|
|
|
foreach ($form as $key => $element) { |
|
54
|
|
|
$ret['form'][$key] = $element->render(); |
|
55
|
|
|
} |
|
56
|
|
|
foreach (['created', 'updated'] as $key) { |
|
57
|
|
|
if ($this->getVar($key) > 0) { |
|
58
|
|
|
$ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
|
59
|
|
|
$ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
$ret['picture'] = $this->getImage('image', false); |
|
63
|
|
|
$ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
|
64
|
|
|
$ret['url'] = $this->getURL(true); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
if (!$extra) { |
|
67
|
|
|
return $ret; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (0 != $this->getVar('cid')) { |
|
71
|
|
|
$categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category'); |
|
72
|
|
|
$category = $categoryHandler->get($this->getVar('cid')); |
|
73
|
|
|
if (\is_object($category)) { |
|
74
|
|
|
$ret['category'] = $category->toArray(false); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (0 != \count($this->getVar('aids'))) { |
|
|
|
|
|
|
79
|
|
|
$artistsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists'); |
|
80
|
|
|
foreach ($this->getVar('aids') as $aid) { |
|
81
|
|
|
$artist = $artistsHandler->get($aid); |
|
82
|
|
|
if (\is_object($artist)) { |
|
83
|
|
|
$ret['artists_array'][$aid] = $artist->toArray(false); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if (0 != \count($this->getVar('sids'))) { |
|
89
|
|
|
$songsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs'); |
|
90
|
|
|
$criteria = new \Criteria('sid', '(' . \implode(',', $this->getVar('sids')) . ')', 'IN'); |
|
|
|
|
|
|
91
|
|
|
$criteria->setSort('traxid'); |
|
92
|
|
|
$criteria->setOrder('ASC'); |
|
93
|
|
|
foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) { |
|
94
|
|
|
if (\is_object($song)) { |
|
95
|
|
|
$ret['songs_array'][$sid] = $song->toArray(false); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return $ret; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string $field |
|
105
|
|
|
* @param bool $local |
|
106
|
|
|
* @return bool|string |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getImage($field = 'image', $local = false) |
|
109
|
|
|
{ |
|
110
|
|
|
if ('' == $this->getVar($field)) { |
|
111
|
|
|
return false; |
|
112
|
|
|
} |
|
113
|
|
|
if (!\file_exists($GLOBALS['xoops']->path($this->getVar('path') . $this->getVar($field)))) { |
|
114
|
|
|
return false; |
|
115
|
|
|
} |
|
116
|
|
|
if (!$local) { |
|
117
|
|
|
return XOOPS_URL . '/' . \str_replace(DS, '/', $this->getVar('path')) . $this->getVar($field); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return XOOPS_ROOT_PATH . DS . $this->getVar('path') . $this->getVar($field); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getURL(): string |
|
127
|
|
|
{ |
|
128
|
|
|
global $file, $op, $fct, $id, $value, $gid, $vid, $vcid, $cid, $start, $limit; |
|
129
|
|
|
if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
|
130
|
|
|
if (0 != $id) { |
|
131
|
|
|
$artistHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums'); |
|
132
|
|
|
$artist = $artistHandler->get($id); |
|
133
|
|
|
if (\is_object($artist) && !$artist->isNew()) { |
|
134
|
|
|
return XOOPS_URL |
|
135
|
|
|
. '/' |
|
136
|
|
|
. $GLOBALS['songlistModuleConfig']['baseofurl'] |
|
137
|
|
|
. '/albums/' |
|
138
|
|
|
. \urlencode(\str_replace([' ', \chr(9)], '-', $artist->getVar('title'))) |
|
139
|
|
|
. '/' |
|
140
|
|
|
. $start |
|
141
|
|
|
. '-' |
|
142
|
|
|
. $id |
|
143
|
|
|
. '-' |
|
144
|
|
|
. $op |
|
145
|
|
|
. '-' |
|
146
|
|
|
. $fct |
|
147
|
|
|
. '-' |
|
148
|
|
|
. $gid |
|
149
|
|
|
. '-' |
|
150
|
|
|
. $cid |
|
151
|
|
|
. '/' |
|
152
|
|
|
. \urlencode($value) |
|
153
|
|
|
. $GLOBALS['songlistModuleConfig']['endofurl']; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/albums/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
return XOOPS_URL . '/' . $GLOBALS['songlistModuleConfig']['baseofurl'] . '/albums/' . $start . '-' . $id . '-' . $op . '-' . $fct . '-' . $gid . '-' . $cid . '/' . \urlencode($value) . $GLOBALS['songlistModuleConfig']['endofurl']; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return XOOPS_URL . '/modules/songlist/albums.php?op=' . $op . '&fct=' . $fct . '&id=' . $id . '&value=' . \urlencode($value ?? '') . '&gid=' . $gid . '&vid=' . $vid . '&cid=' . $cid . '&start=' . $start; |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|