Repository navigation
Expand file tree
/
Copy pathTimeTrackAPI.class.php
More file actions
91 lines (68 loc) · 1.86 KB
/
Copy pathTimeTrackAPI.class.php
File metadata and controls
91 lines (68 loc) · 1.86 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?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->parseData();
$res = $this->_timetrack->getLastDay();
return $res;
}
public function system_listMethods() {
$methods = array(
'getLastDay',
'getMonth',
'login',
'log',
'updateTimestamp',
);
return $methods;
}
}