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

DeviceMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 0
cbo 0
dl 0
loc 43
ccs 0
cts 18
cp 0
rs 10

4 Methods

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