Completed
Pull Request — master (#115)
by Thomas
05:40
created

DeviceMapper::findAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4286
cc 1
eloc 4
nc 1
nop 3
crap 2
1
<?php
2
namespace OCA\Maps\Db;
3
4
use OCP\AppFramework\Db\Mapper;
5
use OCP\IDb;
6
7
class DeviceMapper extends Mapper {
8
9
	public function __construct(IDB $db) {
10
		parent::__construct($db, 'maps_location_track_users', '\OCA\Maps\Db\Device');
11
	}
12
13
	/**
14
	 * @param string $hash
15
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
16
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
17
	 * @return Device
18
	 */
19
	public function findByHash($hash) {
20
		$sql = 'SELECT * FROM `*PREFIX*maps_location_track_users` '.
21
			'WHERE `hash` = ?';
22
		return $this->findEntity($sql, [$hash]);
23
	}
24
25
	/**
26
	 * @param int $id
27
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
28
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
29
	 * @return Device
30
	 */
31
	public function findById($id) {
32
		$sql = 'SELECT * FROM `*PREFIX*maps_location_track_users` '.
33
			'WHERE `id` = ?';
34
		return $this->findEntity($sql, [$id]);
35
	}
36
37
	/**
38
	 * @param string $userId
39
	 * @param int $limit
40
	 * @param int $offset
41
	 * @return Device[]
42
	 */
43
	public function findAll($userId, $limit=null, $offset=null) {
44
		$sql = 'SELECT * FROM `*PREFIX*maps_location_track_users`'.
45
			'WHERE `user_id` = ?';
46
		return $this->findEntities($sql, [$userId], $limit, $offset);
47
	}
48
49
}
50