Completed
Push — scanner_improvements ( 4bed41 )
by Pauli
10:32
created

PlaylistMapper::findListsContainingTrack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
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\IDBConnection;
18
19
class PlaylistMapper extends BaseMapper {
20
21
	public function __construct(IDBConnection $db){
22
		parent::__construct($db, 'music_playlists', '\OCA\Music\Db\Playlist');
23
	}
24
25
	/**
26
	 * @param string $condition
27
	 */
28
	private function makeSelectQuery($condition=null){
29
		return 'SELECT `name`, `id`, `track_ids` ' .
30
			'FROM `*PREFIX*music_playlists` ' .
31
			'WHERE `user_id` = ? ' . $condition;
32
	}
33
34
	/**
35
	 * @param string $userId
36
	 * @param integer $limit
37
	 * @param integer $offset
38
	 * @return Playlist[]
39
	 */
40
	public function findAll($userId, $limit=null, $offset=null){
41
		$sql = $this->makeSelectQuery();
42
		$params = array($userId);
43
		return $this->findEntities($sql, $params, $limit, $offset);
44
	}
45
46
	/**
47
	 * @param int $trackId
48
	 * @return Playlist[]
49
	 */
50
	 public function findListsContainingTrack($trackId) {
51
		$sql = 'SELECT * ' .
52
			'FROM `*PREFIX*music_playlists` ' .
53
			'WHERE `track_ids` LIKE ?';
54
		$params = array('%|' . $trackId . '|%');
55
		return $this->findEntities($sql, $params);
56
	}
57
}
58