Completed
Push — rework-geocoder ( 0178a0...76010e )
by
unknown
08:47
created

FavoriteMapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 5
c 2
b 0
f 2
lcom 0
cbo 0
dl 0
loc 55
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A find() 0 5 1
A findByName() 0 7 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\IDBConnection;
6
7
class FavoriteMapper extends Mapper {
8
9
	public function __construct(IDBConnection $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
		//TODO add COLLATE SQL_Latin1_General_Cp437_CI_AS_KI_WI
31
		//TODO and replace ? by %?%
32
		$sql = 'SELECT * FROM `*PREFIX*maps_favorites` '.
33
			'WHERE `name` LIKE ?';
34
		return $this->findEntities($sql, [$name]);
35
	}
36
37
	/**
38
	 * @param string $userId
39
	 * @param string $from
40
	 * @param string $until
41
	 * @param int $limit
42
	 * @param int $offset
43
	 * @return Favorite[]
44
	 */
45
	public function findBetween($userId, $from, $until, $limit=null, $offset=null) {
46
		$sql = 'SELECT * FROM `*PREFIX*maps_favorites` '.
47
			'WHERE `userId` = ?'.
48
			'AND `timestamp` BETWEEN ? and ?';
49
		return $this->findEntities($sql, [$userId, $from, $until], $limit, $offset);
50
	}
51
52
	/**
53
	 * @param int $limit
54
	 * @param int $offset
55
	 * @return Favorite[]
56
	 */
57
	public function findAll($limit=null, $offset=null) {
58
		$sql = 'SELECT * FROM `*PREFIX*maps_favorites`';
59
		return $this->findEntities($sql, $limit, $offset);
60
	}
61
}
62