forked from mtierltd/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkIntervalMapper.php
More file actions
77 lines (60 loc) · 2.79 KB
/
WorkIntervalMapper.php
File metadata and controls
77 lines (60 loc) · 2.79 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
// db/authormapper.php
namespace OCA\TimeTracker\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper;
class WorkIntervalMapper extends Mapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'timetracker_work_interval');
}
public function findByName($name) {
$sql = 'SELECT * FROM `*PREFIX*timetracker_work_interval` ' .
'WHERE `name` = ?';
try {
$e = $this->findEntity($sql, [$name]);
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_work_interval` ' .
'WHERE `id` = ?';
return $this->findEntity($sql, [$id]);
}
public function findAllForWorkItem($workItemId, $limit=null, $offset=null) {
$sql = 'SELECT * FROM `*PREFIX*timetracker_work_interval` where `work_item_id` = ?';
return $this->findEntities($sql, [$workItemId],$limit, $offset);
}
public function findLatest($user, $limit = 10, $offset = 0){
$sql = 'SELECT * FROM `*PREFIX*timetracker_work_interval` where user_uid = ? order by id desc';
return $this->findEntities($sql, [$user],$limit, $offset);
}
public function findLatestByName($user, $name){
$sql = 'SELECT * FROM `*PREFIX*timetracker_work_interval` where user_uid = ? and name = ? order by id desc';
try {
return $this->findEntity($sql, [$user, $name], 1, 0);
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
return null;
}
}
public function findLatestDays($user, $limitDays = 10, $startDay = 0, $limit = 100, $offset = 0){
$sql = 'SELECT * FROM `oc_timetracker_work_interval` where user_uid = ? and
start > unix_timestamp(curdate() + interval 1 day - interval ? day) and
start < unix_timestamp(curdate() + interval 1 day - interval ? day)
order by id desc';
return $this->findEntities($sql, [$user,$limitDays,$startDay],$limit, $offset);
}
public function findAllRunning($user){
$sql = 'SELECT * FROM `*PREFIX*timetracker_work_interval` where user_uid = ? and running = 1 order by id desc';
return $this->findEntities($sql, [$user],$limit, $offset);
}
public function stopAllRunning($user){
$sql = 'update wi FROM `*PREFIX*timetracker_work_interval` wi set wi.running = 0 where user_uid = ? and running = 1';
return $this->findEntities($sql, [$user],$limit, $offset);
}
}