4
4
5
5
use App \Model \ACL \Role ;
6
6
use App \Model \ACL \RoleRepository ;
7
+ use App \Model \Mailing \Template ;
8
+ use App \Model \Mailing \TemplateVariable ;
7
9
use App \Model \Program \ProgramRepository ;
8
10
use App \Model \Settings \CustomInput \CustomFile ;
9
11
use App \Model \Settings \CustomInput \CustomInput ;
10
12
use App \Model \Settings \CustomInput \CustomInputRepository ;
11
13
use App \Model \Settings \CustomInput \CustomText ;
14
+ use App \Model \Settings \Settings ;
12
15
use App \Model \Settings \SettingsRepository ;
13
16
use App \Model \User \CustomInputValue \CustomCheckboxValue ;
14
17
use App \Model \User \CustomInputValue \CustomInputValueRepository ;
19
22
use App \Model \User \UserRepository ;
20
23
use App \Services \ApplicationService ;
21
24
use App \Services \FilesService ;
25
+ use App \Services \MailService ;
22
26
use App \Services \ProgramService ;
23
27
use App \Utils \Validators ;
24
28
use Nette ;
@@ -65,6 +69,12 @@ class EditUserSeminarForm extends Nette\Object
65
69
/** @var FilesService*/
66
70
private $ filesService ;
67
71
72
+ /** @var MailService */
73
+ private $ mailService ;
74
+
75
+ /** @var SettingsRepository */
76
+ private $ settingsRepository ;
77
+
68
78
69
79
/**
70
80
* EditUserSeminarForm constructor.
@@ -81,7 +91,8 @@ public function __construct(BaseForm $baseFormFactory, UserRepository $userRepos
81
91
CustomInputRepository $ customInputRepository ,
82
92
CustomInputValueRepository $ customInputValueRepository ,
83
93
RoleRepository $ roleRepository , ApplicationService $ applicationService ,
84
- Validators $ validators , FilesService $ filesService )
94
+ Validators $ validators , FilesService $ filesService , MailService $ mailService ,
95
+ SettingsRepository $ settingsRepository )
85
96
{
86
97
$ this ->baseFormFactory = $ baseFormFactory ;
87
98
$ this ->userRepository = $ userRepository ;
@@ -91,6 +102,8 @@ public function __construct(BaseForm $baseFormFactory, UserRepository $userRepos
91
102
$ this ->applicationService = $ applicationService ;
92
103
$ this ->validators = $ validators ;
93
104
$ this ->filesService = $ filesService ;
105
+ $ this ->mailService = $ mailService ;
106
+ $ this ->settingsRepository = $ settingsRepository ;
94
107
}
95
108
96
109
/**
@@ -196,9 +209,13 @@ public function processForm(Form $form, \stdClass $values)
196
209
$ this ->user ->setApproved ($ values ['approved ' ]);
197
210
$ this ->user ->setAttended ($ values ['attended ' ]);
198
211
212
+ $ customInputValueChanged = FALSE ;
213
+
199
214
foreach ($ this ->customInputRepository ->findAllOrderedByPosition () as $ customInput ) {
200
215
$ customInputValue = $ this ->user ->getCustomInputValue ($ customInput );
201
216
217
+ $ oldValue = $ customInputValue ? $ customInputValue ->getValue () : NULL ;
218
+
202
219
switch ($ customInput ->getType ()) {
203
220
case CustomInput::TEXT :
204
221
$ customInputValue = $ customInputValue ?: new CustomTextValue ();
@@ -229,6 +246,9 @@ public function processForm(Form $form, \stdClass $values)
229
246
$ customInputValue ->setUser ($ this ->user );
230
247
$ customInputValue ->setInput ($ customInput );
231
248
$ this ->customInputValueRepository ->save ($ customInputValue );
249
+
250
+ if ($ oldValue !== $ customInputValue ->getValue ())
251
+ $ customInputValueChanged = TRUE ;
232
252
}
233
253
234
254
if (array_key_exists ('arrival ' , $ values ))
@@ -242,6 +262,13 @@ public function processForm(Form $form, \stdClass $values)
242
262
$ this ->user ->setNote ($ values ['privateNote ' ]);
243
263
244
264
$ this ->userRepository ->save ($ this ->user );
265
+
266
+ if ($ customInputValueChanged ) {
267
+ $ this ->mailService ->sendMailFromTemplate ($ this ->user , '' , Template::CUSTOM_INPUT_VALUE_CHANGED , [
268
+ TemplateVariable::SEMINAR_NAME => $ this ->settingsRepository ->getValue (Settings::SEMINAR_NAME ),
269
+ TemplateVariable::USER => $ this ->user ->getDisplayName ()
270
+ ]);
271
+ }
245
272
});
246
273
}
247
274
}
@@ -279,6 +306,6 @@ public function validateRolesCapacities($field, $args)
279
306
*/
280
307
private function generatePath ($ file , User $ user , CustomFile $ customInput ): string
281
308
{
282
- return CustomFile::PATH . '/ ' . $ user ->getId () . '- ' . $ customInput ->getId () . '. ' . pathinfo ($ file ->name , PATHINFO_EXTENSION );
309
+ return CustomFile::PATH . '/ ' . $ user ->getId () . '- ' . $ customInput ->getId () . '- ' . time () . ' . ' . pathinfo ($ file ->name , PATHINFO_EXTENSION );
283
310
}
284
311
}
0 commit comments