-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTimeTrackAPI.class.php
171 lines (125 loc) · 3.81 KB
/
TimeTrackAPI.class.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
require_once "TimeTrack.class.php";
class TimeTrackAPI {
private $_timetrack;
function __construct() {
$this->_timetrack = new TimeTrack();
}
public function login($params) {
$hash = $params['hash'];
if(!isset($hash)) throw new Exception('No hash given.');
$login_success = $this->_timetrack->login(null, null, $hash);
if(!$login_success) throw new Exception('Wrong hash.');
return $login_success;
}
public function log($params) {
$hash = $params['hash'];
$direction = $params['direction'];
$logtime = $params['logtime'];
$message = $params['message'];
$this->login(array('hash' => $hash));
$res = $this->_timetrack->logFile($direction, $logtime, $message);
return $res;
}
public function updateTimestamp($params) {
$hash = $params['hash'];
$old = $params['oldTimestamp'];
$new = $params['newTimestamp'];
if(!isset($old, $new)) {
throw new Exception('Timestamp/s is missing.');
}
$this->login(array('hash' => $hash));
$res = $this->_timetrack->updateFile($old, $new);
return $res;
}
public function getMonth($params) {
$hash = $params['hash'];
$month = $params['month'];
$year = $params['year'];
$this->login(array('hash' => $hash));
if(!isset($month)) $month = date('m');
if(!isset($year)) $year = date('Y');
$needle = $year.'-'.$month;
$res = $this->_timetrack->parseData();
foreach($res['days'] as $day => $day_data) {
if(strpos($day, $needle) === false) {
unset($res['days'][$day]);
}
}
return $res['days'];
}
public function getLastDay($params) {
$hash = $params['hash'];
$this->login(array('hash' => $hash));
$this->_timetrack->setMonth(date('Ym'));
$this->_timetrack->parseData();
$res = $this->_timetrack->getLastDay();
$res['earliestend'] = $this->_timetrack->getEarliestDayEnd();
return $res;
}
public function generateGraphUrls($params) {
$hash = $params['hash'];
$this->login(array('hash' => $hash));
$this->_timetrack->setMonth(date('Ym'));
$this->_timetrack->parseData();
$res = array(
'presence' => $this->_timetrack->generatePresenceGraphUrl(date('Ym'), 'Anwesenheit in Stunden'),
'difference' => $this->_timetrack->generateDifferenceGraphUrl(date('Ym'), 'Differenz zum Soll')
);
return $res;
}
public function system_listMethods() {
$methods = array(
'getLastDay',
'getMonth',
'login',
'log',
'updateTimestamp',
);
return $methods;
}
public function updateNotification($params) {
$hash = $params['hash'];
$this->login(array('hash' => $hash));
$possibleOptions = array(
'enabled' => array(true, false),
'when' => array('5', '10', '15', '20', '25', '30'),
'what' => array('earliest', 'normal'),
'how' => array('mail', 'sms', 'iphone'),
);
// check for right values
if(!isset($params['option'], $params['value'])
|| !in_array($params['option'], array_keys($possibleOptions))
|| !in_array($params['value'], $possibleOptions[$params['option']])
) {
return array("save" => "fail");
}
$options = $this->_timetrack->getOptions();
$options['notifications'][$params['option']] = $params['value'];
if(isset($params['target'])) {
$options['notifications']['target'] = $params['target'];
}
$this->_timetrack->setOptions($options);
return array("save" => "ok");
}
public function changeDaySubject($params) {
$hash = $params['hash'];
$this->login(array('hash' => $hash));
$res = $this->_timetrack->changeDaySubject($params['date'], $params['subject']);
if(!$res)
{
return array("save" => "fail");
}
return array("save" => "ok");
}
public function removeDaySubject($params) {
$hash = $params['hash'];
$this->login(array('hash' => $hash));
$res = $this->_timetrack->removeDaySubject($params['date']);
if(!$res)
{
return array("save" => "fail");
}
return array("save" => "ok");
}
}