|
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
|
|
|
|