|
1
|
|
|
<?php |
|
2
|
|
|
namespace Emails; |
|
3
|
|
|
|
|
4
|
|
|
class CertificationEmail extends VolunteerEmail |
|
5
|
|
|
{ |
|
6
|
|
|
protected $text; |
|
7
|
|
|
protected $additionalProps; |
|
8
|
|
|
|
|
9
|
|
|
public function __construct($profile, $emailTypeSource, $certType, $other = array()) |
|
10
|
|
|
{ |
|
11
|
|
|
parent::__construct($profile); |
|
12
|
|
|
$dataTable = \DataSetFactory::getDataTableByNames('fvs', 'longText'); |
|
13
|
|
|
$entries = $dataTable->read(new \Data\Filter("id eq $emailTypeSource")); |
|
14
|
|
|
if(empty($entries)) |
|
15
|
|
|
{ |
|
16
|
|
|
throw new \Exception("Could not locate email with source type $emailTypeSource"); |
|
17
|
|
|
} |
|
18
|
|
View Code Duplication |
if(isset($entries['value'])) |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
$this->text = $entries['value']; |
|
21
|
|
|
} |
|
22
|
|
|
else if(isset($entries[0]['value'])) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->text = $entries[0]['value']; |
|
25
|
|
|
} |
|
26
|
|
|
$this->addToAddress($this->profile->email); |
|
27
|
|
|
$this->additionalProps = $other; |
|
28
|
|
|
$dataTable = \DataSetFactory::getDataTableByNames('fvs', 'certifications'); |
|
29
|
|
|
$entries = $dataTable->read(new \Data\Filter("certID eq $certType")); |
|
30
|
|
|
if(empty($entries)) |
|
31
|
|
|
{ |
|
32
|
|
|
throw new \Exception("Could not locate certification with type $certType"); |
|
33
|
|
|
} |
|
34
|
|
|
$this->additionalProps['certType'] = $entries[0]['name']; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getSubject() |
|
38
|
|
|
{ |
|
39
|
|
|
return 'Certification Notification - Burning Flipside Volunteer System'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function getBody($html = true) |
|
43
|
|
|
{ |
|
44
|
|
|
$firstName = $this->profile->firstName; |
|
45
|
|
|
$lastName = $this->profile->lastName; |
|
46
|
|
|
$paperName = $this->profile->getDisplayName('paperName'); |
|
47
|
|
|
$webName = $this->profile->getDisplayName('webName'); |
|
48
|
|
|
$certType = $this->additionalProps['certType']; |
|
49
|
|
|
$rejectReason = $this->additionalProps['reason']; |
|
50
|
|
|
$vars = array( |
|
51
|
|
|
'{$firstName}' => $firstName, |
|
52
|
|
|
'{$lastName}' => $lastName, |
|
53
|
|
|
'{$paperName}' => $paperName, |
|
54
|
|
|
'{$webName}' => $webName, |
|
55
|
|
|
'{$certType}' => $certType, |
|
56
|
|
|
'{$rejectReason}' => $rejectReason |
|
57
|
|
|
); |
|
58
|
|
View Code Duplication |
if($html === true) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
$text = strtr($this->text, $vars); |
|
61
|
|
|
return $text; |
|
62
|
|
|
} |
|
63
|
|
|
else |
|
64
|
|
|
{ |
|
65
|
|
|
$rawText = $this->text; |
|
66
|
|
|
$index = strpos($rawText, "<script"); |
|
67
|
|
|
if($index !== false) |
|
68
|
|
|
{ |
|
69
|
|
|
$end = strpos($rawText, "</script>"); |
|
70
|
|
|
if($index === 0) |
|
71
|
|
|
{ |
|
72
|
|
|
$rawText = substr($rawText, $end+9); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
return strtr(strip_tags($rawText), $vars); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getHTMLBody() |
|
80
|
|
|
{ |
|
81
|
|
|
$body = $this->getBody(); |
|
82
|
|
|
return $body; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getTextBody() |
|
86
|
|
|
{ |
|
87
|
|
|
$body = $this->getBody(false); |
|
88
|
|
|
return $body; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.