|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LoginCidadao\CoreBundle\Model; |
|
12
|
|
|
|
|
13
|
|
|
use libphonenumber\PhoneNumber; |
|
14
|
|
|
use libphonenumber\PhoneNumberFormat; |
|
15
|
|
|
use libphonenumber\PhoneNumberUtil; |
|
16
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
|
17
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class SupportMessage represents a message sent by an user needing help. |
|
21
|
|
|
* @package LoginCidadao\CoreBundle\Model |
|
22
|
|
|
*/ |
|
23
|
|
|
class SupportMessage |
|
24
|
|
|
{ |
|
25
|
|
|
const EXTRA_ID = 'contact.form.extra.id'; |
|
26
|
|
|
const EXTRA_CREATED_AT = 'contact.form.extra.created_at'; |
|
27
|
|
|
const EXTRA_EMAIL_CONFIRMED_AT = 'contact.form.extra.email_confirmed_at'; |
|
28
|
|
|
const EXTRA_HAS_CPF = 'contact.form.extra.has_cpf.label'; |
|
29
|
|
|
const EXTRA_HAS_CPF_YES = 'contact.form.extra.has_cpf.yes'; |
|
30
|
|
|
const EXTRA_HAS_CPF_NO = 'contact.form.extra.has_cpf.no'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
* @Assert\NotBlank |
|
35
|
|
|
* @Assert\Length( |
|
36
|
|
|
* min=3, |
|
37
|
|
|
* max="255", |
|
38
|
|
|
* minMessage="person.validation.name.length.min", |
|
39
|
|
|
* maxMessage="person.validation.name.length.max" |
|
40
|
|
|
* ) |
|
41
|
|
|
*/ |
|
42
|
|
|
private $name; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string |
|
46
|
|
|
* |
|
47
|
|
|
* @Assert\NotBlank |
|
48
|
|
|
* @Assert\Email(strict=true) |
|
49
|
|
|
* @Assert\Length( |
|
50
|
|
|
* max="255", |
|
51
|
|
|
* maxMessage="person.validation.email.length.max" |
|
52
|
|
|
* ) |
|
53
|
|
|
*/ |
|
54
|
|
|
private $email; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var string |
|
58
|
|
|
* @Assert\NotBlank |
|
59
|
|
|
*/ |
|
60
|
|
|
private $message; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var array |
|
64
|
|
|
*/ |
|
65
|
|
|
private $extra = []; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* SupportMessage constructor. |
|
69
|
|
|
* @param PersonInterface|null $person |
|
70
|
|
|
*/ |
|
71
|
2 |
|
public function __construct(PersonInterface $person = null) |
|
72
|
|
|
{ |
|
73
|
2 |
|
$this->extra = []; |
|
74
|
|
|
|
|
75
|
2 |
|
if ($person instanceof PersonInterface) { |
|
76
|
|
|
$this |
|
77
|
1 |
|
->setName($person->getFullName()) |
|
78
|
1 |
|
->setEmail($person->getEmail()) |
|
79
|
1 |
|
->setExtra(self::EXTRA_ID, $person->getId()) |
|
80
|
1 |
|
->setExtra(self::EXTRA_CREATED_AT, $person->getCreatedAt()->format('Y-m-d H:i:s')) |
|
81
|
1 |
|
->setExtra(self::EXTRA_EMAIL_CONFIRMED_AT, $person->getEmailConfirmedAt()->format('Y-m-d H:i:s')) |
|
82
|
1 |
|
->setExtra(self::EXTRA_HAS_CPF, $person->getCpf() ? self::EXTRA_HAS_CPF_YES : self::EXTRA_HAS_CPF_NO); |
|
83
|
|
|
|
|
84
|
1 |
|
if ($person->getMobile() instanceof PhoneNumber) { |
|
85
|
1 |
|
$phoneUtil = PhoneNumberUtil::getInstance(); |
|
86
|
1 |
|
$format = PhoneNumberFormat::E164; |
|
87
|
1 |
|
$this->setExtra('Mobile', $phoneUtil->format($person->getMobile(), $format)); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
2 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return mixed |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function getName() |
|
96
|
|
|
{ |
|
97
|
1 |
|
return $this->name; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param mixed $name |
|
102
|
|
|
* @return SupportMessage |
|
103
|
|
|
*/ |
|
104
|
2 |
|
public function setName($name) |
|
105
|
|
|
{ |
|
106
|
2 |
|
$this->name = $name; |
|
107
|
|
|
|
|
108
|
2 |
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return mixed |
|
113
|
|
|
*/ |
|
114
|
1 |
|
public function getEmail() |
|
115
|
|
|
{ |
|
116
|
1 |
|
return $this->email; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param mixed $email |
|
121
|
|
|
* @return SupportMessage |
|
122
|
|
|
*/ |
|
123
|
2 |
|
public function setEmail($email) |
|
124
|
|
|
{ |
|
125
|
2 |
|
$this->email = $email; |
|
126
|
|
|
|
|
127
|
2 |
|
return $this; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return mixed |
|
132
|
|
|
*/ |
|
133
|
2 |
|
public function getMessage() |
|
134
|
|
|
{ |
|
135
|
2 |
|
return $this->message; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @param mixed $message |
|
140
|
|
|
* @return SupportMessage |
|
141
|
|
|
*/ |
|
142
|
2 |
|
public function setMessage($message) |
|
143
|
|
|
{ |
|
144
|
2 |
|
$this->message = $message; |
|
145
|
|
|
|
|
146
|
2 |
|
return $this; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @param string $key |
|
151
|
|
|
* @param mixed $value |
|
152
|
|
|
* @return SupportMessage |
|
153
|
|
|
*/ |
|
154
|
1 |
|
public function setExtra($key, $value) |
|
155
|
|
|
{ |
|
156
|
1 |
|
$this->extra[$key] = $value; |
|
157
|
|
|
|
|
158
|
1 |
|
return $this; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
1 |
|
public function getExtra() |
|
162
|
|
|
{ |
|
163
|
1 |
|
return $this->extra; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
1 |
|
public function getFormattedMessage(TranslatorInterface $translator) |
|
167
|
|
|
{ |
|
168
|
1 |
|
$extras = array_filter($this->getExtra()); |
|
169
|
1 |
|
$message = nl2br($this->getMessage()); |
|
170
|
1 |
|
if (count($extras) > 0) { |
|
171
|
1 |
|
$extraHtml = array_map(function ($value, $key) use ($translator) { |
|
172
|
1 |
|
return sprintf("<strong>%s</strong>: %s", $translator->trans($key), $translator->trans($value)); |
|
173
|
1 |
|
}, $extras, array_keys($extras)); |
|
174
|
|
|
|
|
175
|
1 |
|
$extra = implode("<br>", $extraHtml); |
|
176
|
1 |
|
$message = "<p>{$message}</p><p>{$extra}</p>"; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
1 |
|
return $message; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|