forked from mtierltd/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoalMapper.php
More file actions
46 lines (33 loc) · 1.33 KB
/
GoalMapper.php
File metadata and controls
46 lines (33 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
// db/authormapper.php
namespace OCA\TimeTracker\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
class GoalMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'timetracker_goal');
}
public function findByUserProject($userUid, $projectId) {
$sql = 'SELECT * FROM `*PREFIX*timetracker_goal` ' .
'WHERE `user_uid` = ? and `project_id` = ?';
try {
$e = $this->findEntity($sql, [$userUid, $projectId]);
return $e;
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
return null;
}
}
/**
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
*/
public function find($id) {
$sql = 'SELECT * FROM `*PREFIX*timetracker_goal` ' .
'WHERE `id` = ?';
return $this->findEntity($sql, [$id]);
}
public function findAll($user){
$sql = 'SELECT tg.*,p.name as projectName FROM `*PREFIX*timetracker_goal` tg join `*PREFIX*timetracker_project` p on p.id = tg.project_id where tg.user_uid = ? order by tg.created_at desc';
return $this->findEntities($sql, [$user]);
}
}