-
Notifications
You must be signed in to change notification settings - Fork 0
/
freeAgent_timeslips.class.php
45 lines (38 loc) · 1.19 KB
/
freeAgent_timeslips.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
<?php
class freeAgent_timeslips
{
protected $timeslips;
public function __construct($timeslips)
{
$this->timeslips = $timeslips;
}
public function report()
{
$data = '';
foreach($this->timeslips as $entry)
{
$data .= sprintf("%d\t%d\t%s %.2f %s\n", basename($entry->project), basename($entry->task), $entry->dated_on, $entry->hours, $entry->comment);
}
return $data;
}
public function reportByProject()
{
$projects = array();
$sort = array();
$data = '';
foreach($this->timeslips as $entry)
{
$project_id = basename($entry->project);
if(!isset($projects[ $project_id ])) {
$projects[ $project_id ] = array('hours' => 0, 'tasks' => array());
$sort[ $project_id ] = 0;
}
$sort[ $project_id ] += $entry->hours;
$projects[ $project_id ]['id'] = $project_id;
$projects[ $project_id ]['hours'] += $entry->hours;
$projects[ $project_id ]['tasks'][] = $entry;
}
array_multisort($sort, SORT_DESC, $projects);
return $projects;
}
}