1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use Ups\NodeInterface; |
8
|
|
|
|
9
|
|
|
class EmailMessage implements NodeInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
private $emailAddresses = []; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $undeliverableEmailAddress; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $fromEmailAddress; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $fromName; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $memo; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $subject; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $subjectCode; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Subject codes. |
48
|
|
|
*/ |
49
|
|
|
const SUBJECT_CODE_SHIPMENT_REFERENCE_NR1 = '01'; |
50
|
|
|
const SUBJECT_CODE_SHIPMENT_REFERENCE_NR2 = '02'; |
51
|
|
|
const SUBJECT_CODE_SHIPMENT_PACKAGE_NR1 = '03'; |
52
|
|
|
const SUBJECT_CODE_SHIPMENT_PACKAGE_NR2 = '04'; |
53
|
|
|
const SUBJECT_CODE_SUBJECT_TEXT = '08'; // Return only |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param null|DOMDocument $document |
57
|
|
|
* |
58
|
|
|
* @return DOMElement |
59
|
|
|
*/ |
60
|
|
|
public function toNode(DOMDocument $document = null) |
61
|
|
|
{ |
62
|
|
|
if (null === $document) { |
63
|
|
|
$document = new DOMDocument(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$node = $document->createElement('EMailMessage'); |
67
|
|
|
|
68
|
|
|
foreach ($this->getEmailAddresses() as $email) { |
69
|
|
|
$node->appendChild($document->createElement('EMailAddress', $email)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if ($this->getUndeliverableEmailAddress() !== null) { |
73
|
|
|
$node->appendChild($document->createElement('UndeliverableEMailAddress', $this->getUndeliverableEmailAddress())); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
if ($this->getFromEmailAddress() !== null) { |
77
|
|
|
$node->appendChild($document->createElement('FromEMailAddress', $this->getFromEmailAddress())); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ($this->getFromName() !== null) { |
81
|
|
|
$node->appendChild($document->createElement('FromName', $this->getFromName())); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ($this->getMemo() !== null) { |
85
|
|
|
$node->appendChild($document->createElement('Memo', $this->getMemo())); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($this->getSubject() !== null) { |
89
|
|
|
$node->appendChild($document->createElement('Subject', $this->getSubject())); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ($this->getSubjectCode() !== null) { |
93
|
|
|
$node->appendChild($document->createElement('SubjectCode', $this->getSubjectCode())); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $node; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
|
public function getEmailAddresses() |
103
|
|
|
{ |
104
|
|
|
return $this->emailAddresses; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param array $emailAddresses |
109
|
|
|
*/ |
110
|
|
|
public function setEmailAddresses(array $emailAddresses) |
111
|
|
|
{ |
112
|
|
|
if (count($emailAddresses) > 5) { |
113
|
|
|
throw new \Exception('Maximum of 5 emailaddresses allowed'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$this->emailAddresses = $emailAddresses; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return mixed |
121
|
|
|
*/ |
122
|
|
|
public function getUndeliverableEmailAddress() |
123
|
|
|
{ |
124
|
|
|
return $this->undeliverableEmailAddress; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param mixed $undeliverableEmailAddress |
129
|
|
|
*/ |
130
|
|
|
public function setUndeliverableEmailAddress($undeliverableEmailAddress) |
131
|
|
|
{ |
132
|
|
|
$this->undeliverableEmailAddress = $undeliverableEmailAddress; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return mixed |
137
|
|
|
*/ |
138
|
|
|
public function getFromEmailAddress() |
139
|
|
|
{ |
140
|
|
|
return $this->fromEmailAddress; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param mixed $fromEmailAddress |
145
|
|
|
*/ |
146
|
|
|
public function setFromEmailAddress($fromEmailAddress) |
147
|
|
|
{ |
148
|
|
|
$this->fromEmailAddress = $fromEmailAddress; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return mixed |
153
|
|
|
*/ |
154
|
|
|
public function getFromName() |
155
|
|
|
{ |
156
|
|
|
return $this->fromName; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param mixed $fromName |
161
|
|
|
*/ |
162
|
|
|
public function setFromName($fromName) |
163
|
|
|
{ |
164
|
|
|
$this->fromName = $fromName; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return mixed |
169
|
|
|
*/ |
170
|
|
|
public function getMemo() |
171
|
|
|
{ |
172
|
|
|
return $this->memo; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param mixed $memo |
177
|
|
|
*/ |
178
|
|
|
public function setMemo($memo) |
179
|
|
|
{ |
180
|
|
|
if (strlen($memo) > 50) { |
181
|
|
|
throw new \Exception('Memo should maximum be 50 chars'); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
$this->memo = $memo; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return mixed |
189
|
|
|
*/ |
190
|
|
|
public function getSubject() |
191
|
|
|
{ |
192
|
|
|
return $this->subject; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param mixed $subject |
197
|
|
|
*/ |
198
|
|
|
public function setSubject($subject) |
199
|
|
|
{ |
200
|
|
|
if (strlen($subject) > 50) { |
201
|
|
|
throw new \Exception('Subject should maximum be 50 chars'); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
$this->subject = $subject; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return mixed |
209
|
|
|
*/ |
210
|
|
|
public function getSubjectCode() |
211
|
|
|
{ |
212
|
|
|
return $this->subjectCode; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param mixed $subjectCode |
217
|
|
|
*/ |
218
|
|
|
public function setSubjectCode($subjectCode) |
219
|
|
|
{ |
220
|
|
|
$this->subjectCode = $subjectCode; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|