forked from loduis/teamwork.com-project-management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Time.php
118 lines (111 loc) · 3.49 KB
/
Time.php
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace TeamWorkPm;
class Time extends Model
{
protected function init()
{
$this->fields = array(
'description'=>true,
'person_id'=>true,
'date'=>array(
'required'=>true,
'type'=>'integer',
'length'=> 6
),
'hours'=>array(
'required'=>true,
'type'=>'integer',
'length' => 3
),
'minutes'=>array(
'required'=>false,
'type'=>'integer',
'length'=> 2
),
'time'=>true,
'isbillable'=>false
);
$this->parent = 'time-entry';
//$this->action = 'time_entries';
}
/**
* Inserta un time entry ya sea para
* un projecto o para un todo item
* @param array $data
* @return int
*/
public function insert(array $data)
{
$id = 0;
if (!empty($data['task_id'])) {
$id = (int) $data['task_id'];
$resource = 'todo_items';
} elseif (!empty($data['project_id'])) {
$id = (int) $data['project_id'];
$resource = 'projects';
}
if ($id <= 0) {
throw new Exception('Required field project_id or task_id');
}
return $this->rest->post("$resource/$id/$this->action", $data);
}
/**
* Optional Parameters
*
* PAGE : numeric - The page to start retrieving entries from
* ( e.g: page=1 gives records 1 - 50, page=2 gives records 51-99 etc)
* FROMDATE : string (YYYYMMDD) - The start date to retrieve from
* FROMTIME : string (HH:MM) - The start time only if FROMDATE is passed
* TODATE : string (YYYYMMDD) - The end date to retrieve to
* TOTIME : string (HH:MM) - The end time only if TODATE is passed
*
* @param string $id
* @param array $params
* @return TeamWorkPm\Response\Model
*/
public function getAll(array $params = array())
{
return $this->rest->get("$this->action", $params);
}
/**
* Optional Parameters
*
* PAGE : numeric - The page to start retrieving entries from
* ( e.g: page=1 gives records 1 - 50, page=2 gives records 51-99 etc)
* FROMDATE : string (YYYYMMDD) - The start date to retrieve from
* FROMTIME : string (HH:MM) - The start time only if FROMDATE is passed
* TODATE : string (YYYYMMDD) - The end date to retrieve to
* TOTIME : string (HH:MM) - The end time only if TODATE is passed
*
* @param int $id
* @param array $params
* @return TeamWorkPm\Response\Model
*/
public function getByProject($project_id, array $params = array())
{
$project_id = (int) $project_id;
if ($project_id <= 0) {
throw new Exception('Invalid param project_id');
}
return $this->rest->get("projects/$project_id/$this->action", $params);
}
/**
* Retrieve all To-do Item Times
*
* GET /todo_items/#{todo_item_id}/time_entries
*
* Retrieves all of the time entries from a submitted todo item.
*
* @param int $id
* @param array $params
* @return TeamWorkPm\Response\Model
*/
public function getByTask($task_id, array $params = array())
{
$task_id = (int) $task_id;
if ($task_id <= 0) {
throw new Exception('Invalid param task_id');
}
return $this->rest->get("todo_items/$task_id/$this->action", $params);
}
}