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

PlaylistMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 39
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A makeSelectQuery() 0 5 1
A findAll() 0 5 1
A findListsContainingTrack() 0 7 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