|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2015 SURFnet B.V. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace OpenConext\ProfileBundle\Service; |
|
20
|
|
|
|
|
21
|
|
|
use OpenConext\Profile\Value\EmailAddress; |
|
22
|
|
|
use Swift_Mailer as Mailer; |
|
23
|
|
|
use Swift_Message as Message; |
|
24
|
|
|
use Symfony\Component\Templating\EngineInterface; |
|
25
|
|
|
|
|
26
|
|
|
final class AttributeSupportMailService |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var EmailAddress |
|
30
|
|
|
*/ |
|
31
|
|
|
private $mailFrom; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var EmailAddress |
|
35
|
|
|
*/ |
|
36
|
|
|
private $mailTo; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var Mailer |
|
40
|
|
|
*/ |
|
41
|
|
|
private $mailer; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var EngineInterface |
|
45
|
|
|
*/ |
|
46
|
|
|
private $templateEngine; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var UserService |
|
50
|
|
|
*/ |
|
51
|
|
|
private $userService; |
|
52
|
|
|
|
|
53
|
|
|
public function __construct( |
|
54
|
|
|
EmailAddress $mailFrom, |
|
55
|
|
|
EmailAddress $mailTo, |
|
56
|
|
|
Mailer $mailer, |
|
57
|
|
|
EngineInterface $templateEngine, |
|
58
|
|
|
UserService $userService |
|
59
|
|
|
) { |
|
60
|
|
|
$this->mailFrom = $mailFrom; |
|
61
|
|
|
$this->mailTo = $mailTo; |
|
62
|
|
|
$this->mailer = $mailer; |
|
63
|
|
|
$this->templateEngine = $templateEngine; |
|
64
|
|
|
$this->userService = $userService; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function sendAttributeSupportMail() |
|
68
|
|
|
{ |
|
69
|
|
|
$user = $this->userService->getUser(); |
|
70
|
|
|
|
|
71
|
|
|
$body = $this->templateEngine->render( |
|
72
|
|
|
'OpenConextProfileBundle:AttributeSupport:email.html.twig', |
|
73
|
|
|
['attributes' => $user->getAttributes()] |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
/** @var Message $message */ |
|
77
|
|
|
$message = $this->mailer->createMessage(); |
|
78
|
|
|
$message |
|
79
|
|
|
->setFrom($this->mailFrom->getEmailAddress()) |
|
80
|
|
|
->setTo($this->mailTo->getEmailAddress()) |
|
81
|
|
|
->setSubject(sprintf('Personal debug info of %s', $user->getId())) |
|
82
|
|
|
->setBody($body, 'text/html', 'utf-8'); |
|
83
|
|
|
|
|
84
|
|
|
$this->mailer->send($message); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|