|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Class Store |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Roomify\Bat\Store; |
|
9
|
|
|
|
|
10
|
|
|
use Roomify\Bat\Event\Event; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* The basic Store class |
|
14
|
|
|
*/ |
|
15
|
|
|
abstract class Store implements StoreInterface { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Fill in hourly values from existing events when a day is being split. |
|
19
|
|
|
* |
|
20
|
|
|
* $existing_events must contain an existing event for the unit the same day. |
|
21
|
|
|
* This only needs to be called for hourly granularity. |
|
22
|
|
|
* |
|
23
|
|
|
* @param array $existing_events |
|
24
|
|
|
* Existing event data from ::getEventData(). |
|
25
|
|
|
* @param array $itemized |
|
26
|
|
|
* The new event itemized. Values from existing overlapping events will be |
|
27
|
|
|
* inserted into it. |
|
28
|
|
|
* @param int $value |
|
29
|
|
|
* The value of the event being added. |
|
30
|
|
|
* @param int $unit_id |
|
31
|
|
|
* The unit the event being added. |
|
32
|
|
|
* @param int $year |
|
33
|
|
|
* Year of the event. |
|
34
|
|
|
* @param int $month |
|
35
|
|
|
* A month of the event. |
|
36
|
|
|
* @param int $day |
|
37
|
|
|
* Day of the event. |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function itemizeSplitDay(array &$existing_events, array &$itemized, $value, $unit_id, $year, $month, $day) { |
|
40
|
|
|
$existing_value = $existing_events[$unit_id][EVENT::BAT_DAY][$year][$month][$day]; |
|
41
|
|
|
if ($value === -1 && $existing_value > 0) { |
|
42
|
|
|
$itemized_day = &$itemized[Event::BAT_HOUR][$year][$month][$day]; |
|
43
|
|
|
for ($hour = 0; $hour < 24; $hour++) { |
|
44
|
|
|
$hour_key = 'h' . $hour; |
|
45
|
|
|
$var = &$itemized_day[$hour_key]; |
|
46
|
|
|
$var = isset($var) && $var != 0 ? $var : $existing_value; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Fill in minute values from existing events when an hour is being split. |
|
53
|
|
|
* |
|
54
|
|
|
* $existing_events must contain an existing event for the unit during either |
|
55
|
|
|
* the same hour or day. |
|
56
|
|
|
* |
|
57
|
|
|
* @param array $existing_events |
|
58
|
|
|
* Existing event data from ::getEventData(). |
|
59
|
|
|
* @param array $itemized |
|
60
|
|
|
* The new event itemized. Values from existing overlapping events will be |
|
61
|
|
|
* inserted into it. |
|
62
|
|
|
* @param int $value |
|
63
|
|
|
* The value of the event being added. |
|
64
|
|
|
* @param int $unit_id |
|
65
|
|
|
* The unit the event being added. |
|
66
|
|
|
* @param int $year |
|
67
|
|
|
* Year of the event. |
|
68
|
|
|
* @param int $month |
|
69
|
|
|
* A month of the event. |
|
70
|
|
|
* @param int $day |
|
71
|
|
|
* A day of the event. |
|
72
|
|
|
* @param int $hour |
|
73
|
|
|
* An hour in which an existing event overlaps. |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function itemizeSplitHour(array $existing_events, array &$itemized, $value, $unit_id, $year, $month, $day, $hour) { |
|
76
|
|
|
if (isset($existing_events[$unit_id][EVENT::BAT_HOUR][$year][$month][$day][$hour])) { |
|
77
|
|
|
$existing_value = $existing_events[$unit_id][EVENT::BAT_HOUR][$year][$month][$day][$hour]; |
|
78
|
|
|
} |
|
79
|
|
|
else { |
|
80
|
|
|
$existing_value = $existing_events[$unit_id][EVENT::BAT_DAY][$year][$month][$day]; |
|
81
|
|
|
} |
|
82
|
|
|
if ($value === -1 && $existing_value > 0) { |
|
83
|
|
|
$itemized_hour = &$itemized[Event::BAT_MINUTE][$year][$month][$day][$hour]; |
|
84
|
|
|
for ($minute = 0; $minute < 60; $minute++) { |
|
85
|
|
|
$minute_key = 'm' . str_pad($minute, 2, '0', STR_PAD_LEFT); |
|
86
|
|
|
$var = &$itemized_hour[$minute_key]; |
|
87
|
|
|
$var = isset($var) && $var != 0 ? $var : $existing_value; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|