|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright https://yawik.org/COPYRIGHT.php |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** Forward.php */ |
|
11
|
|
|
|
|
12
|
|
|
namespace Applications\Mail; |
|
13
|
|
|
|
|
14
|
|
|
use Applications\Entity\Application; |
|
15
|
|
|
use Core\Mail\TranslatorAwareMessage; |
|
16
|
|
|
use Doctrine\ODM\MongoDB\Repository\DocumentRepository; |
|
17
|
|
|
use Laminas\Mime; |
|
18
|
|
|
use Laminas\View\HelperPluginManager; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Sends an e-mail containing an applications |
|
22
|
|
|
*/ |
|
23
|
|
|
class Forward extends TranslatorAwareMessage |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var Application |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $application; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var bool |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $isInitialized = false; |
|
34
|
|
|
|
|
35
|
|
|
protected $viewManager; |
|
36
|
|
|
|
|
37
|
|
|
protected $fileRepository; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
public function __construct(HelperPluginManager $viewHelperManager, DocumentRepository $attachmentRepository, array $options = []) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->viewManager = $viewHelperManager; |
|
43
|
|
|
$this->fileRepository = $attachmentRepository; |
|
44
|
|
|
parent::__construct($options); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param $application |
|
49
|
|
|
* @return $this |
|
50
|
|
|
*/ |
|
51
|
|
|
public function setApplication(Application $application) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->application = $application; |
|
54
|
|
|
if ($this->isInitialized) { |
|
55
|
|
|
$this->generateBody(); |
|
56
|
|
|
} |
|
57
|
|
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function init() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->isInitialized = true; |
|
63
|
|
|
if (!$this->application) { |
|
64
|
|
|
return; |
|
65
|
|
|
} |
|
66
|
|
|
$this->setEncoding('UTF-8'); |
|
67
|
|
|
$subject = /* @translate */ 'Fwd: Application to "%s" dated %s'; |
|
68
|
|
|
if ($this->isTranslatorEnabled()) { |
|
69
|
|
|
$subject = $this->getTranslator()->translate($subject); |
|
70
|
|
|
} |
|
71
|
|
|
$this->setSubject( |
|
72
|
|
|
sprintf( |
|
73
|
|
|
$subject, |
|
74
|
|
|
$this->application->getJob()->getTitle(), |
|
75
|
|
|
strftime('%x', $this->application->getDateCreated()->getTimestamp()) |
|
76
|
|
|
) |
|
77
|
|
|
); |
|
78
|
|
|
$this->generateBody(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Generates the Mail Body |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function generateBody() |
|
85
|
|
|
{ |
|
86
|
|
|
$message = new Mime\Message(); |
|
87
|
|
|
|
|
88
|
|
|
$text = $this->generateHtml(); |
|
89
|
|
|
$textPart = new Mime\Part($text); |
|
90
|
|
|
$textPart->type = 'text/html'; |
|
91
|
|
|
$textPart->charset = 'UTF-8'; |
|
92
|
|
|
$textPart->disposition = Mime\Mime::DISPOSITION_INLINE; |
|
93
|
|
|
$message->addPart($textPart); |
|
94
|
|
|
|
|
95
|
|
|
if (is_object($this->application->getContact()->getImage()) && |
|
96
|
|
|
$this->application->getContact()->getImage()->getId()) { |
|
97
|
|
|
/* @var $image \Auth\Entity\UserImage */ |
|
98
|
|
|
$image = $this->application->getContact()->getImage(); |
|
99
|
|
|
$part = new Mime\Part($image->getResource()); |
|
|
|
|
|
|
100
|
|
|
$part->setType($image->getType()); |
|
|
|
|
|
|
101
|
|
|
$part->setEncoding(Mime\Mime::ENCODING_BASE64); |
|
102
|
|
|
$part->setFileName($image->getName()); |
|
103
|
|
|
$part->setDisposition(Mime\Mime::DISPOSITION_ATTACHMENT); |
|
104
|
|
|
$message->addPart($part); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
foreach ($this->application->getAttachments() as $attachment) { |
|
108
|
|
|
/** @var \Applications\Entity\Attachment $attachment */ |
|
109
|
|
|
$stream = $this->fileRepository->openDownloadStream($attachment->getId()); |
|
|
|
|
|
|
110
|
|
|
$part = new Mime\Part($stream); |
|
111
|
|
|
$part->setType($attachment->getMetadata()->getContentType()); |
|
112
|
|
|
$part->encoding = Mime\Mime::ENCODING_BASE64; |
|
113
|
|
|
$part->filename = $attachment->getMetadata()->getName(); |
|
114
|
|
|
$part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT; |
|
115
|
|
|
$message->addPart($part); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$this->setBody($message); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Generates a mail containing an Application. |
|
123
|
|
|
* |
|
124
|
|
|
* @return mixed |
|
125
|
|
|
*/ |
|
126
|
|
|
protected function generateHtml() |
|
127
|
|
|
{ |
|
128
|
|
|
/* |
|
129
|
|
|
* "ViewHelperManager" defined by ZF2 |
|
130
|
|
|
* see http://framework.zend.com/manual/2.0/en/modules/zend.mvc.services.html#viewmanager |
|
131
|
|
|
*/ |
|
132
|
|
|
$viewManager = $this->viewManager; |
|
133
|
|
|
|
|
134
|
|
|
return $viewManager->get("partial")->__invoke('applications/mail/forward', array("application"=>$this->application)); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.