-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent-page-include.php
96 lines (87 loc) · 2.42 KB
/
event-page-include.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
<?php
require_once 'common-include.php';
class HoursLayout {
var $hours;
var $duration;
function __construct( $duration ) {
$this->duration = $duration;
$this->hours = array();
}
function anyAssigned( $starting, $ending ) {
for ( $h = $starting; $h < $ending; $h++ ) {
if ( array_key_exists( $h, $this->hours ) ) {
return true;
}
}
return false;
}
function assign( $assignment, $starting, $ending ) {
for ( $h = $starting; $h < $ending; $h++ ) {
$this->hours[$h] = $assignment;
}
return $this;
}
}
class ActivityLayout {
var $activity;
var $isActive;
var $hoursLayouts = array(); // of HoursLayout
function __construct( $activity, $duration ) {
$this->activity = $activity;
$this->hoursLayouts[] = new HoursLayout( $duration );
$this->isActive = false;
}
}
class DayLayout {
var $day;
var $activityLayouts = array();
function __construct( $day ) {
$this->day = $day;
}
}
class EventLayout {
var $event;
var $dayLayouts = array();
var $earliestStarting;
var $latestEnding;
var $duration;
var $hideActivitiesWithoutShifts = false;
function __construct( $event ) {
$this->event = $event;
$this->earliestStarting = Day::earliestStarting( $event->getDays() );
$this->latestEnding = Day::latestEnding( $event->getDays() );
$this->duration = $this->latestEnding - $this->earliestStarting;
$this->hideActivitiesWithoutShifts = strtobool( $event->getHint( "hide-activities-without-shifts" ) );
}
}
$eventLayout = new EventLayout($event);
foreach ( $event->getDays() as $day ) {
$dayLayout = new DayLayout($day);
foreach ( $event->getActivities() as $activity ) {
$activityLayout = new ActivityLayout($activity, $eventLayout->duration);
foreach ( $activity->getShifts() as $shift ) {
if ( $shift->getDay() !== $day ) {
continue;
}
$hoursLayout = null;
foreach ( $activityLayout->hoursLayouts as $hl ) {
if ( ! $hl->anyAssigned( $shift->getStarting(), $shift->getEnding() ) ) {
$hoursLayout = $hl;
break;
}
}
if ( is_null( $hoursLayout ) ) {
$hoursLayout = new HoursLayout( $eventLayout->duration );
$activityLayout->hoursLayouts[] = $hoursLayout;
}
$hoursLayout->assign( $shift, $shift->getStarting(), $shift->getEnding() );
$activityLayout->isActive = true;
}
$dayLayout->activityLayouts[] = $activityLayout;
}
$eventLayout->dayLayouts[] = $dayLayout;
}
if ( !isset($dayId) ) {
$dayId = $eventLayout->dayLayouts[0]->day->getId();
}
?>