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

FavoriteMapper::findByName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 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