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
78
79
80
|
<?php
namespace Model;
/**
* Subtask timesheet
*
* @package model
* @author Frederic Guillot
*/
class SubtaskTimeTracking extends Base
{
/**
* SQL table name
*
* @var string
*/
const TABLE = 'subtask_time_tracking';
/**
* Get query for user timesheet (pagination)
*
* @access public
* @param integer $user_id User id
* @return \PicoDb\Table
*/
public function getUserQuery($user_id)
{
return $this->db
->table(self::TABLE)
->columns(
self::TABLE.'.id',
self::TABLE.'.subtask_id',
self::TABLE.'.end',
self::TABLE.'.start',
Subtask::TABLE.'.task_id',
Subtask::TABLE.'.title AS subtask_title',
Task::TABLE.'.title AS task_title',
Task::TABLE.'.project_id'
)
->join(Subtask::TABLE, 'id', 'subtask_id')
->join(Task::TABLE, 'id', 'task_id', Subtask::TABLE)
->eq(self::TABLE.'.user_id', $user_id);
}
/**
* Log start time
*
* @access public
* @param integer $subtask_id
* @param integer $user_id
* @return boolean
*/
public function logStartTime($subtask_id, $user_id)
{
return $this->db
->table(self::TABLE)
->insert(array('subtask_id' => $subtask_id, 'user_id' => $user_id, 'start' => time()));
}
/**
* Log end time
*
* @access public
* @param integer $subtask_id
* @param integer $user_id
* @return boolean
*/
public function logEndTime($subtask_id, $user_id)
{
return $this->db
->table(self::TABLE)
->eq('subtask_id', $subtask_id)
->eq('user_id', $user_id)
->eq('end', 0)
->update(array(
'end' => time()
));
}
}
|