ShiftEmail::getSubject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
namespace Emails;
3
4
class ShiftEmail extends VolunteerEmail
5
{
6
    protected $shift;
7
    protected $text;
8
9
    public function __construct($shift, $emailTypeSource)
10
    {
11
        parent::__construct($shift->participantObj);
12
        $this->shift = $shift;
13
        $dataTable = \DataSetFactory::getDataTableByNames('fvs', 'longText');
14
        $entries = $dataTable->read(new \Data\Filter("id eq $emailTypeSource"));
15
        if(empty($entries))
16
        {
17
            throw new \Exception("Could not locate email with source type $emailTypeSource");
18
        }
19
        if(isset($entries['value']))
20
        {
21
            $this->text = $entries['value'];
22
        }
23
        else if(isset($entries[0]['value']))
24
        {
25
            $this->text = $entries[0]['value'];
26
        }
27
        $this->addToAddress($this->profile->email);
28
    }
29
30
    public function getSubject()
31
    {
32
        return 'Shift Change Notification - Burning Flipside Volunteer System';
33
    }
34
35
    protected function getBody($html = true)
36
    {
37
        $firstName = $this->profile->firstName;
38
        $lastName = $this->profile->lastName;
39
        $paperName = $this->profile->getDisplayName('paperName');
40
        $webName = $this->profile->getDisplayName('webName');
41
        $department = $this->shift->department->departmentName;
42
        $role = $this->shift->role->display_name;
43
        $event = $this->shift->event->name;
44
        $start = $this->shift->startTime->format('r');
45
        $end = $this->shift->endTime->format('r');
46
        $vars = array(
47
                '{$firstName}' => $firstName,
48
                '{$lastName}' => $lastName,
49
                '{$paperName}' => $paperName,
50
                '{$webName}' => $webName,
51
                '{$department}' => $department,
52
                '{$role}' => $role,
53
                '{$event}' => $event,
54
                '{$start}' => $start,
55
                '{$end}' => $end
56
                );
57
        if(strpos($this->text, '{$newStart}') !== false || strpos($this->text, '{$newEnd}') !== false)
58
        {
59
            $newShift = new \VolunteerShift($this->shift->{'_id'});
60
            $newStart = $newShift->startTime->format('r');
61
            $newEnd = $newShift->endTime->format('r');
62
            $vars['{$newStart}'] = $newStart;
63
            $vars['{$newEnd}'] = $newEnd;
64
        }
65
        if($html === true)
66
        {
67
            $text = strtr($this->text, $vars);
68
            return $text;
69
        }
70
        else
71
        {
72
            $rawText = $this->text;
73
            $index = strpos($rawText, "<script");
74
            if($index !== false)
75
            {
76
                $end = strpos($rawText, "</script>");
77
                if($index === 0)
78
                {
79
                    $rawText = substr($rawText, $end + 9);
80
                }
81
            }
82
            return strtr(strip_tags($rawText), $vars);
83
        }
84
    }
85
86
    public function getHTMLBody()
87
    {
88
        $body = $this->getBody();
89
        return $body;
90
    }
91
92
    public function getTextBody()
93
    {
94
        $body = $this->getBody(false);
95
        return $body;
96
    }
97
}
98
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
99