FavoriteMapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 53
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A find() 0 5 1
A findByName() 0 5 1
A findBetween() 0 6 1
A findAll() 0 4 1
1
<?php
2
namespace OCA\Maps\Db;
3
4
use OCP\AppFramework\Db\Mapper;
5
use OCP\IDb;
6
7
class FavoriteMapper extends Mapper {
8
9
	public function __construct(IDB $db) {
10
		parent::__construct($db, 'maps_favorites', '\OCA\Maps\Db\Favorite');
11
	}
12
13
	/**
14
	 * @param int $id
15
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
16
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
17
	 * @return Favorite
18
	 */
19
	public function find($id) {
20
		$sql = 'SELECT * FROM `*PREFIX*maps_favorites` '.
21
			'WHERE `id` = ?';
22
		return $this->findEntity($sql, [$id]);
23
	}
24
25
	/**
26
	 * @param string $name
27
	 * @return Favorite[]
28
	 */
29
	public function findByName($name) {
30
		$sql = 'SELECT * FROM `*PREFIX*maps_favorites` '.
31
			'WHERE `name` ILIKE ?';
32
		return $this->findEntities($sql, ['%' . addcslashes($name, '\\_%') . '%']);
33
	}
34
35
	/**
36
	 * @param string $userId
37
	 * @param string $from
38
	 * @param string $until
39
	 * @param int $limit
40
	 * @param int $offset
41
	 * @return Favorite[]
42
	 */
43
	public function findBetween($userId, $from, $until, $limit=null, $offset=null) {
44
		$sql = 'SELECT * FROM `*PREFIX*maps_favorites` '.
45
			'WHERE `userId` = ?'.
46
			'AND `timestamp` BETWEEN ? and ?';
47
		return $this->findEntities($sql, [$userId, $from, $until], $limit, $offset);
48
	}
49
50
	/**
51
	 * @param int $limit
52
	 * @param int $offset
53
	 * @return Favorite[]
54
	 */
55
	public function findAll($limit=null, $offset=null) {
56
		$sql = 'SELECT * FROM `*PREFIX*maps_favorites`';
57
		return $this->findEntities($sql, $limit, $offset);
58
	}
59
}
60