1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if (!defined('XOOPS_ROOT_PATH')) { |
4
|
|
|
exit(); |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
include_once(dirname(dirname(__FILE__)).'/include/songlist.object.php'); |
8
|
|
|
include_once(dirname(dirname(__FILE__)).'/include/songlist.form.php'); |
9
|
|
|
|
10
|
|
|
class SonglistAlbums extends XoopsObject |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
function SonglistAlbums($fid = null) |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
$this->initVar('abid', XOBJ_DTYPE_INT, 0, false); |
16
|
|
|
$this->initVar('cid', XOBJ_DTYPE_INT, 0, false); |
17
|
|
|
$this->initVar('aids', XOBJ_DTYPE_ARRAY, array(), false); |
18
|
|
|
$this->initVar('sids', XOBJ_DTYPE_ARRAY, array(), false); |
19
|
|
|
$this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false, 128); |
20
|
|
|
$this->initVar('image', XOBJ_DTYPE_TXTBOX, null, false, 255); |
21
|
|
|
$this->initVar('path', XOBJ_DTYPE_TXTBOX, null, false, 255); |
22
|
|
|
$this->initVar('artists', XOBJ_DTYPE_INT, 0, false); |
23
|
|
|
$this->initVar('songs', XOBJ_DTYPE_INT, 0, false); |
24
|
|
|
$this->initVar('hits', XOBJ_DTYPE_INT, 0, false); |
25
|
|
|
$this->initVar('rank', XOBJ_DTYPE_DECIMAL, 0, false); |
26
|
|
|
$this->initVar('votes', XOBJ_DTYPE_INT, 0, false); |
27
|
|
|
$this->initVar('created', XOBJ_DTYPE_INT, 0, false); |
28
|
|
|
$this->initVar('updated', XOBJ_DTYPE_INT, 0, false); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function getForm($as_array = false) { |
|
|
|
|
32
|
|
|
return songlist_albums_get_form($this, $as_array); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function toArray($extra = true) { |
|
|
|
|
36
|
|
|
$ret = parent::toArray(); |
37
|
|
|
$form = $this->getForm(true); |
38
|
|
|
foreach($form as $key => $element) { |
39
|
|
|
$ret['form'][$key] = $form[$key]->render(); |
40
|
|
|
} |
41
|
|
|
foreach(array('created', 'updated') as $key) { |
42
|
|
|
if ($this->getVar($key)>0) { |
43
|
|
|
$ret['form'][$key] = date(_DATESTRING, $this->getVar($key)); |
44
|
|
|
$ret[$key] = date(_DATESTRING, $this->getVar($key)); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
$ret['picture'] = $this->getImage('image', false); |
48
|
|
|
$ret['rank'] = number_format(($this->getVar('rank')>0&&$this->getVar('votes')>0?$this->getVar('rank')/$this->getVar('votes'):0),2)._MI_SONGLIST_OFTEN; |
49
|
|
|
$ret['url'] = $this->getURL(true); |
|
|
|
|
50
|
|
|
|
51
|
|
|
if ($extra==false) |
52
|
|
|
return $ret; |
53
|
|
|
|
54
|
|
|
if ($this->getVar('cid')!=0) { |
55
|
|
|
$category_handler = xoops_getmodulehandler('category', 'songlist'); |
56
|
|
|
$category = $category_handler->get($this->getVar('cid')); |
57
|
|
|
if (is_object($category)) |
58
|
|
|
$ret['category'] = $category->toArray(false); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
if (count($this->getVar('aids'))!=0) { |
|
|
|
|
63
|
|
|
$artists_handler = xoops_getmodulehandler('artists', 'songlist'); |
64
|
|
|
foreach($this->getVar('aids') as $aid) { |
65
|
|
|
$artist = $artists_handler->get($aid); |
66
|
|
|
if (is_object($artist)) |
67
|
|
|
$ret['artists_array'][$aid] = $artist->toArray(false); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
if (count($this->getVar('sids'))!=0) { |
73
|
|
|
$songs_handler = xoops_getmodulehandler('songs', 'songlist'); |
74
|
|
|
$criteria = new Criteria('sid', '('.implode(',', $this->getVar('sids')).')', 'IN'); |
|
|
|
|
75
|
|
|
$criteria->setSort('`traxid`'); |
76
|
|
|
$criteria->setOrder('ASC'); |
77
|
|
|
foreach($songs_handler->getObjects($criteria, true) as $sid=>$song) { |
|
|
|
|
78
|
|
|
if (is_object($song)) |
79
|
|
|
$ret['songs_array'][$sid] = $song->toArray(false); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $ret; |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
function getImage($field = 'image', $local = false) { |
|
|
|
|
88
|
|
|
if (strlen($this->getVar($field))==0) |
89
|
|
|
return false; |
90
|
|
|
if (!file_exists($GLOBALS['xoops']->path($this->getVar('path').$this->getVar($field)))) |
91
|
|
|
return false; |
92
|
|
|
if ($local==false) |
93
|
|
|
return XOOPS_URL.'/'.str_replace(DS, '/', $this->getVar('path')).$this->getVar($field); |
94
|
|
|
else |
95
|
|
|
return XOOPS_ROOT_PATH.DS.$this->getVar('path').$this->getVar($field); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
function getURL() { |
|
|
|
|
99
|
|
|
global $file, $op, $fct, $id, $value, $gid, $vid, $vcid, $cid, $start, $limit; |
100
|
|
|
if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
101
|
|
|
if ($id!=0) { |
102
|
|
|
$artist_handler = xoops_getmodulehandler('albums', 'songlist'); |
103
|
|
|
$artist = $artist_handler->get($id); |
104
|
|
|
if (is_object($artist)&&!$artist->isNew()) { |
105
|
|
|
return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/albums/'.urlencode(str_replace(array(' ', chr(9)), '-', $artist->getVar('title'))).'/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl']; |
106
|
|
|
} else { |
107
|
|
|
return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/albums/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl']; |
108
|
|
|
} |
109
|
|
|
} else { |
110
|
|
|
return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/albums/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl']; |
111
|
|
|
} |
112
|
|
|
} else { |
113
|
|
|
return XOOPS_URL.'/modules/songlist/albums.php?op='.$op.'&fct='.$fct.'&id='.$id.'&value='.urlencode($value).'&gid='.$gid.'&vid='.$vid.'&cid='.$cid.'&start='.$start; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
class SonglistAlbumsHandler extends XoopsPersistableObjectHandler |
121
|
|
|
{ |
122
|
|
|
function __construct(&$db) |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
parent::__construct($db, "songlist_albums", 'SonglistAlbums', "abid", "title"); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
function filterFields() { |
|
|
|
|
128
|
|
|
return array('abid', 'cid', 'aids', 'sids', 'title', 'image', 'path', 'artists', 'songs', 'hits', 'rank', 'votes', 'created', 'updated'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
function getFilterCriteria($filter) { |
|
|
|
|
132
|
|
|
$parts = explode('|', $filter); |
133
|
|
|
$criteria = new CriteriaCompo(); |
134
|
|
|
foreach($parts as $part) { |
135
|
|
|
$var = explode(',', $part); |
136
|
|
|
if (!empty($var[1])&&!is_numeric($var[0])) { |
137
|
|
|
$object = $this->create(); |
138
|
|
|
if ( $object->vars[$var[0]]['data_type']==XOBJ_DTYPE_TXTBOX || |
139
|
|
|
$object->vars[$var[0]]['data_type']==XOBJ_DTYPE_TXTAREA) { |
140
|
|
|
$criteria->add(new Criteria('`'.$var[0].'`', '%'.$var[1].'%', (isset($var[2])?$var[2]:'LIKE'))); |
141
|
|
|
} elseif ( $object->vars[$var[0]]['data_type']==XOBJ_DTYPE_INT || |
142
|
|
|
$object->vars[$var[0]]['data_type']==XOBJ_DTYPE_DECIMAL || |
143
|
|
|
$object->vars[$var[0]]['data_type']==XOBJ_DTYPE_FLOAT ) { |
144
|
|
|
$criteria->add(new Criteria('`'.$var[0].'`', $var[1], (isset($var[2])?$var[2]:'='))); |
145
|
|
|
} elseif ( $object->vars[$var[0]]['data_type']==XOBJ_DTYPE_ENUM ) { |
146
|
|
|
$criteria->add(new Criteria('`'.$var[0].'`', $var[1], (isset($var[2])?$var[2]:'='))); |
147
|
|
|
} elseif ( $object->vars[$var[0]]['data_type']==XOBJ_DTYPE_ARRAY ) { |
148
|
|
|
$criteria->add(new Criteria('`'.$var[0].'`', '%"'.$var[1].'";%', (isset($var[2])?$var[2]:'LIKE'))); |
149
|
|
|
} |
150
|
|
|
} elseif (!empty($var[1])&&is_numeric($var[0])) { |
151
|
|
|
$criteria->add(new Criteria($var[0], $var[1])); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
return $criteria; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
function getFilterForm($filter, $field, $sort='created', $op = 'dashboard', $fct='list') { |
|
|
|
|
158
|
|
|
$ele = songlist_getFilterElement($filter, $field, $sort, $op, $fct); |
159
|
|
|
if (is_object($ele)) |
160
|
|
|
return $ele->render(); |
161
|
|
|
else |
162
|
|
|
return ' '; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
function insert($obj, $force=true, $object = null) { |
|
|
|
|
166
|
|
|
if ($obj->isNew()) { |
167
|
|
|
$new = true; |
|
|
|
|
168
|
|
|
$old = $this->create(); |
169
|
|
|
$obj->setVar('created', time()); |
170
|
|
|
} else { |
171
|
|
|
$new = false; |
172
|
|
|
$old = $this->get($obj->getVar('abid')); |
173
|
|
|
$obj->setVar('updated', time()); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$artists_handler = xoops_getmodulehandler('artists', 'songlist'); |
177
|
|
|
$genre_handler = xoops_getmodulehandler('genre', 'songlist'); |
178
|
|
|
$voice_handler = xoops_getmodulehandler('voice', 'songlist'); |
179
|
|
|
$category_handler = xoops_getmodulehandler('category', 'songlist'); |
180
|
|
|
|
181
|
|
|
if (is_a($object, 'SonglistSongs')) { |
182
|
|
|
if ($obj->vars['cid']['changed']==true) { |
183
|
|
|
if ($obj->vars['cid']['value'] != $old->vars['cid']['value']) { |
184
|
|
|
$category = $category_handler->get($obj->vars['cid']['value']); |
185
|
|
|
if (is_object($category)) { |
186
|
|
|
$category->setVar('albums', $category->getVar('albums')+1); |
187
|
|
|
$category_handler->insert($category, true, $obj); |
|
|
|
|
188
|
|
|
if (!$old->isNew()&&$old->vars['cid']['value']>0) { |
189
|
|
|
$category = $category_handler->get($old->vars['cid']['value']); |
190
|
|
|
if (is_object($category)) { |
191
|
|
|
$category->setVar('albums', $category->getVar('albums')-1); |
192
|
|
|
$category_handler->insert($category, true, $obj); |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
if (count($obj->vars['aids']['value'])!=0&&$obj->vars['aids']['changed']==true) { |
200
|
|
|
foreach($obj->vars['aids']['value'] as $aid) { |
201
|
|
|
if (!is_array($aid, $old->getVar('aids'))&&$aid!=0) { |
|
|
|
|
202
|
|
|
$artists = $artists_handler->get($aid); |
203
|
|
|
if (is_object($artists)) { |
204
|
|
|
$artists->setVar('albums', $artists->getVar('albums')+1); |
205
|
|
|
$artists_handler->insert($artists, true, $obj); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
if (!$old->isNew()) { |
210
|
|
|
foreach($old->getVar('aids') as $aid) { |
211
|
|
|
if (!is_array($aid, $obj->vars['aids']['value'])&&$aid!=0) { |
212
|
|
|
$artists = $artists_handler->get($aid); |
213
|
|
|
if (is_object($artists)) { |
214
|
|
|
$artists->setVar('albums', $artists->getVar('albums')-1); |
215
|
|
|
$artists_handler->insert($artists, true, $obj); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
if ($object->vars['gid']['value']!=0&&$object->vars['gid']['changed']==true) { |
223
|
|
|
$genre = $genre_handler->get($object->vars['gid']['value']); |
224
|
|
|
if (is_object($genre)) { |
225
|
|
|
$genre->setVar('albums', $genre->getVar('albums')+1); |
226
|
|
|
$genre_handler->insert($genre, true, $obj); |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
if ($object->vars['vid']['value']!=0&&$object->vars['vid']['changed']==true) { |
230
|
|
|
$voice = $voice_handler->get($object->vars['vid']['value']); |
231
|
|
|
if (is_object($voice)) { |
232
|
|
|
$voice->setVar('albums', $voice->getVar('albums')+1); |
233
|
|
|
$voice_handler->insert($voice, true, $obj); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
} |
238
|
|
|
if (strlen($obj->getVar('title'))==0) |
239
|
|
|
return false; |
240
|
|
|
|
241
|
|
|
return parent::insert($obj, $force); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
var $_objects = array('object'=>array(), 'array'=>array()); |
245
|
|
|
|
246
|
|
|
function get($id, $fields = '*') { |
|
|
|
|
247
|
|
|
if (!isset($this->_objects['object'][$id])) { |
248
|
|
|
$this->_objects['object'][$id] = parent::get($id, $fields); |
249
|
|
|
if (!isset($GLOBALS['songlistAdmin'])&&is_object($this->_objects['object'][$id])) { |
250
|
|
|
$sql = 'UPDATE `'.$this->table.'` set hits=hits+1 where `'.$this->keyName.'` = '.$this->_objects['object'][$id]->getVar($this->keyName); |
251
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
return $this->_objects['object'][$id]; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
function getObjects($criteria = NULL, $id_as_key = false, $as_object = true) { |
|
|
|
|
258
|
|
|
$ret = parent::getObjects($criteria, $id_as_key, $as_object); |
259
|
|
|
/* if (!isset($GLOBALS['songlistAdmin'])) { |
260
|
|
|
$id = array(); |
261
|
|
|
foreach($ret as $data) { |
262
|
|
|
if ($as_object==true) { |
263
|
|
|
if (!in_array($data->getVar($this->keyName), array_keys($this->_objects['object']))) { |
264
|
|
|
$this->_objects['object'][$data->getVar($this->keyName)] = $data; |
265
|
|
|
$id[$data->getVar($this->keyName)] = $data->getVar($this->keyName); |
266
|
|
|
} |
267
|
|
|
} else { |
268
|
|
|
if (!in_array($data[$this->keyName], array_keys($this->_objects['array']))) { |
269
|
|
|
$this->_objects['array'][$data[$this->keyName]] = $data; |
270
|
|
|
$id[$data[$this->keyName]] = $data[$this->keyName];; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
if (!isset($GLOBALS['songlistAdmin'])&&count($id)>0) { |
276
|
|
|
$sql = 'UPDATE `'.$this->table.'` set hits=hits+1 where `'.$this->keyName.'` IN ('.implode(',', $id).')'; |
277
|
|
|
$GLOBALS['xoopsDB']->queryF($sql); |
278
|
|
|
}*/ |
279
|
|
|
return $ret; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
function getURL() { |
|
|
|
|
283
|
|
|
global $file, $op, $fct, $id, $value, $gid, $vid, $cid, $start, $limit; |
284
|
|
|
if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
285
|
|
|
if ($cid!=0) { |
286
|
|
|
$artist_handler = xoops_getmodulehandler('artists', 'songlist'); |
287
|
|
|
$artist = $artist_handler->get($cid); |
288
|
|
|
if (is_object($artist)&&!$artist->isNew()) { |
289
|
|
|
return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/'.$file.'/'.urlencode(str_replace(array(' ', chr(9)), '-', $artist->getVar('name'))).'/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl']; |
290
|
|
|
} else { |
291
|
|
|
return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/'.$file.'/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl']; |
292
|
|
|
} |
293
|
|
|
} else { |
294
|
|
|
return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/'.$file.'/'.$start.'-'.$id.'-'.$op.'-'.$fct.'-'.$gid.'-'.$cid.'/'.urlencode($value).$GLOBALS['songlistModuleConfig']['endofurl']; |
295
|
|
|
} |
296
|
|
|
} else { |
297
|
|
|
return XOOPS_URL.'/modules/songlist/'.$file.'.php?op='.$op.'&fct='.$fct.'&id='.$id.'&value='.urlencode($value).'&gid='.$gid.'&vid='.$vid.'&cid='.$cid.'&start='.$start; |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
function getTop($limit=1) { |
|
|
|
|
302
|
|
|
$sql = 'SELECT * FROM `'.$this->table.'` WHERE `rank`>=0 ORDER BY (`rank`/`votes`) DESC LIMIT '.$limit; |
303
|
|
|
$results = $GLOBALS['xoopsDB']->queryF($sql); |
304
|
|
|
$ret = array(); |
305
|
|
|
$i=0; |
306
|
|
|
while ($row = $GLOBALS['xoopsDB']->fetchArray($results)) { |
307
|
|
|
$ret[$i] = $this->create(); |
308
|
|
|
$ret[$i]->assignVars($row); |
309
|
|
|
$i++; |
310
|
|
|
} |
311
|
|
|
return $ret; |
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
?> |
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.