Completed
Push — FVSv2 ( 1cad04...78f5f9 )
by Patrick
01:35
created

SimplePDF   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B createPDFBody() 0 52 8
1
<?php
2
namespace Schedules;
3
4
class SimplePDF extends \PDF\PDF
5
{
6
    use ShiftSchedule;
7
8
    protected $department;
9
    protected $shifts;
10
11
    function __construct($department, $shifts)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
    {
13
        parent::__construct();
14
        $this->department = $department;
15
        $this->shifts = $shifts;
16
        $this->createPDFBody();
17
    }
18
19
    protected function createPDFBody()
20
    {
21
        $html = '<body>';
22
        $html .= '<style type="text/css">table {border-collapse: collapse;} table, th, td {border: 1px solid black;}</style>';
23
        $html .= '<h1 style="text-align: center;">'.$this->department['departmentName'].' Shift Schedule</h1>';
24
        //Group shifts by day...
25
        $days = array();
26
        $shifts = $this->shifts;
27
        $count = count($shifts);
28
        for($i = 0; $i < $count; $i++)
29
        {
30
            $start = new \DateTime($shifts[$i]['startTime']);
31
            $end = new \DateTime($shifts[$i]['endTime']);
32
            $shifts[$i]['startTime'] = $start;
33
            $shifts[$i]['endTime'] = $end;
34
            $dateStr = $start->format('l (n/j/Y)');
35
            $timeStr = $start->format('g:i A').' till '.$end->format('g:i A');
36
            if(strlen($shifts[$i]['name']) > 0)
37
            {
38
                $timeStr .=' - <i>'.$shifts[$i]['name'].'</i>';
39
            }
40
            if(!isset($days[$dateStr]))
41
            {
42
                $days[$dateStr] = array();
43
            }
44
            if(!isset($days[$dateStr][$timeStr]))
45
            {
46
                $days[$dateStr][$timeStr] = array();
47
            }
48
            array_push($days[$dateStr][$timeStr], $shifts[$i]);
49
        }
50
        ksort($days);
51
        foreach($days as $dateStr=>$day)
52
        {
53
            $html .='<h2>'.$dateStr.'</h2>';
54
            uksort($day, array($this, 'groupSort'));
55
            foreach($day as $shiftStr=>$shifts)
56
            {
57
                usort($shifts, array($this, 'shiftSort'));
58
                $html .='<h3>'.$shiftStr.'</h3>';
59
                $html .='<table width="100%"><tr><th style="width: 20%">Role</th><th>Volunteer Name</th><th>Volunteer Camp</th></tr>';
60
                foreach($shifts as $shift)
61
                {
62
                    //TODO Volunteer info for shift...
63
                    $html .='<tr><td>'.$this->getRoleNameFromID($shift['roleID']).'</td><td></td><td></td></tr>';
64
                }
65
                $html .='</table>';
66
            }
67
        }
68
        $html .='</body>';
69
        $this->setPDFFromHTML($html);
70
    }
71
} 
72