-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.php
87 lines (78 loc) · 2.71 KB
/
logs.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
<?php
class fi_openkeidas_diary_logs
{
public static function within(DateTime $from, DateTime $to, array $users, fi_openkeidas_diary_activity $activity = null)
{
if (empty($users))
{
return array();
}
$qb = new midgard_query_builder('fi_openkeidas_diary_log');
$qb->add_constraint('date', '>', $from);
$qb->add_constraint('date', '<', $to);
$qb->add_constraint('person', 'IN', $users);
if (!is_null($activity))
{
$qb->add_constraint('activity', '=', $activity->id);
}
return $qb->execute();
}
public static function duration_within(DateTime $from, DateTime $to, array $users, fi_openkeidas_diary_activity $activity = null)
{
return array_reduce
(
self::within($from, $to, $users, $activity),
function ($totals, fi_openkeidas_diary_log $entry)
{
return $totals + $entry->duration;
},
0
);
}
public static function average_duration_within(DateTime $from, DateTime $to, array $users, fi_openkeidas_diary_activity $activity = null)
{
return self::duration_within
(
$from,
$to,
$users,
$activity
) / count($users);
}
public static function group_duration_within(DateTime $from, DateTime $to, fi_openkeidas_groups_group $group, fi_openkeidas_diary_activity $activity = null)
{
midgardmvc_core::get_instance()->authorization->require_user();
$mc = new midgard_collector('fi_openkeidas_groups_group_member', 'grp', $group->id);
$mc->add_constraint('metadata.isapproved', '=', true);
$mc->set_key_property('person');
$mc->execute();
return self::average_duration_within
(
$from,
$to,
array_keys($mc->list_keys()),
$activity
);
}
public static function user_duration_this_week(fi_openkeidas_diary_activity $activity = null)
{
midgardmvc_core::get_instance()->authorization->require_user();
return self::duration_within
(
new midgard_datetime('-1 week'),
new midgard_datetime(),
array(midgardmvc_core::get_instance()->authentication->get_person()->id),
$activity
);
}
public static function group_duration_this_week(fi_openkeidas_groups_group $group, fi_openkeidas_diary_activity $activity = null)
{
return self::group_duration_within
(
new midgard_datetime('-1 week'),
new midgard_datetime(),
$group,
$activity
);
}
}