|
1
|
|
|
<?php |
|
2
|
|
|
namespace Schedules; |
|
3
|
|
|
|
|
4
|
|
|
class SimplePDF extends \PDF\PDF |
|
5
|
|
|
{ |
|
6
|
|
|
use ShiftSchedule; |
|
7
|
|
|
|
|
8
|
|
|
protected $department; |
|
9
|
|
|
protected $deptName; |
|
10
|
|
|
protected $shifts; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct($department, $shifts) |
|
13
|
|
|
{ |
|
14
|
|
|
parent::__construct(); |
|
15
|
|
|
if(is_string($department)) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->deptName = $department; |
|
18
|
|
|
$this->department = false; |
|
19
|
|
|
} |
|
20
|
|
|
else |
|
21
|
|
|
{ |
|
22
|
|
|
$this->department = $department; |
|
23
|
|
|
$this->deptName = $this->department['departmentName']; |
|
24
|
|
|
} |
|
25
|
|
|
$this->shifts = $shifts; |
|
26
|
|
|
$this->createPDFBody(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function createPDFBody() |
|
30
|
|
|
{ |
|
31
|
|
|
$html = '<body>'; |
|
32
|
|
|
$html .= '<style type="text/css">table {border-collapse: collapse;} table, th, td {border: 1px solid black;}</style>'; |
|
33
|
|
|
$html .= '<h1 style="text-align: center;">'.$this->deptName.' Shift Schedule</h1>'; |
|
34
|
|
|
//Group shifts by day... |
|
35
|
|
|
$days = array(); |
|
36
|
|
|
$shifts = $this->shifts; |
|
37
|
|
|
$count = count($shifts); |
|
38
|
|
|
for($i = 0; $i < $count; $i++) |
|
39
|
|
|
{ |
|
40
|
|
|
$start = new \DateTime($shifts[$i]['startTime']); |
|
41
|
|
|
$end = new \DateTime($shifts[$i]['endTime']); |
|
42
|
|
|
$shifts[$i]['startTime'] = $start; |
|
43
|
|
|
$shifts[$i]['endTime'] = $end; |
|
44
|
|
|
$dateStr = $start->format('l (n/j/Y)'); |
|
45
|
|
|
$timeStr = $start->format('g:i A').' till '.$end->format('g:i A'); |
|
46
|
|
|
if(strlen($shifts[$i]['name']) > 0) |
|
47
|
|
|
{ |
|
48
|
|
|
$timeStr .= ' - <i>'.$shifts[$i]['name'].'</i>'; |
|
49
|
|
|
} |
|
50
|
|
|
if(!isset($days[$dateStr])) |
|
51
|
|
|
{ |
|
52
|
|
|
$days[$dateStr] = array(); |
|
53
|
|
|
} |
|
54
|
|
|
if(!isset($days[$dateStr][$timeStr])) |
|
55
|
|
|
{ |
|
56
|
|
|
$days[$dateStr][$timeStr] = array(); |
|
57
|
|
|
} |
|
58
|
|
|
array_push($days[$dateStr][$timeStr], $shifts[$i]); |
|
59
|
|
|
} |
|
60
|
|
|
uksort($days, array($this, 'daySort')); |
|
61
|
|
|
foreach($days as $dateStr=>$day) |
|
62
|
|
|
{ |
|
63
|
|
|
$html .= '<h2>'.$dateStr.'</h2>'; |
|
64
|
|
|
uksort($day, array($this, 'groupSort')); |
|
65
|
|
|
foreach($day as $shiftStr=>$shifts) |
|
66
|
|
|
{ |
|
67
|
|
|
usort($shifts, array($this, 'shiftSort')); |
|
68
|
|
|
$html .= '<h3>'.$shiftStr.'</h3>'; |
|
69
|
|
|
$html .= '<table width="100%"><tr><th style="width: 20%">Role</th><th>Volunteer Name</th><th>Volunteer Camp</th></tr>'; |
|
70
|
|
|
foreach($shifts as $shift) |
|
71
|
|
|
{ |
|
72
|
|
|
$shift = new \VolunteerShift(false, $shift); |
|
73
|
|
|
$participant = $shift->participantObj; |
|
74
|
|
|
if($participant !== false) |
|
75
|
|
|
{ |
|
76
|
|
|
$html .= '<tr><td>'.$this->getRoleNameFromID($shift->roleID).'</td><td>'.$participant->getDisplayName('paperName').'</td><td>'.$participant->campName.'</td></tr>'; |
|
77
|
|
|
} |
|
78
|
|
|
else |
|
79
|
|
|
{ |
|
80
|
|
|
$html .= '<tr><td>'.$this->getRoleNameFromID($shift->roleID).'</td><td></td><td></td></tr>'; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
$html .= '</table>'; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
$html .= '</body>'; |
|
87
|
|
|
$this->setPDFFromHTML($html); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|