1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ownCloud - Music app |
5
|
|
|
* |
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
7
|
|
|
* later. See the COPYING file. |
8
|
|
|
* |
9
|
|
|
* @author Morris Jobke <[email protected]> |
10
|
|
|
* @author Volkan Gezer <[email protected]> |
11
|
|
|
* @copyright Morris Jobke 2014 |
12
|
|
|
* @copyright Volkan Gezer 2014 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace OCA\Music\Db; |
16
|
|
|
|
17
|
|
|
use OCP\AppFramework\Db\Entity; |
18
|
|
|
use OCP\IDBConnection; |
19
|
|
|
|
20
|
|
|
class PlaylistMapper extends BaseMapper { |
21
|
|
|
|
22
|
|
|
public function __construct(IDBConnection $db){ |
23
|
|
|
parent::__construct($db, 'music_playlists', '\OCA\Music\Db\Playlist'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $condition |
28
|
|
|
*/ |
29
|
|
|
private function makeSelectQuery($condition=null){ |
30
|
|
|
return 'SELECT `name`, `id`, `track_ids` ' . |
31
|
|
|
'FROM `*PREFIX*music_playlists` ' . |
32
|
|
|
'WHERE `user_id` = ? ' . $condition; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $userId |
37
|
|
|
* @param integer $limit |
38
|
|
|
* @param integer $offset |
39
|
|
|
* @return Playlist[] |
40
|
|
|
*/ |
41
|
|
|
public function findAll($userId, $limit=null, $offset=null){ |
42
|
|
|
$sql = $this->makeSelectQuery(); |
43
|
|
|
$params = array($userId); |
44
|
|
|
return $this->findEntities($sql, $params, $limit, $offset); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param integer $id |
49
|
|
|
* @param string $userId |
50
|
|
|
* @return Playlist |
51
|
|
|
*/ |
52
|
|
|
public function find($id, $userId){ |
53
|
|
|
$sql = $this->makeSelectQuery('AND `id` = ?'); |
54
|
|
|
$params = array($userId, $id); |
55
|
|
|
return $this->findEntity($sql, $params); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param int $trackId |
60
|
|
|
* @return Playlist[] |
61
|
|
|
*/ |
62
|
|
|
public function findListsContainingTrack($trackId) { |
63
|
|
|
$sql = 'SELECT * ' . |
64
|
|
|
'FROM `*PREFIX*music_playlists` ' . |
65
|
|
|
'WHERE `track_ids` LIKE ?'; |
66
|
|
|
$params = array('%|' . $trackId . '|%'); |
67
|
|
|
return $this->findEntities($sql, $params); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|