Skip to content

Commit 2b31e90

Browse files
author
Jan Staněk
authored
Merge pull request #467 from jan-stanek/mail-zmena-poli
upozorneni na zmenu vlastnich poli (#445)
2 parents 9e40676 + deea29c commit 2b31e90

File tree

6 files changed

+114
-5
lines changed

6 files changed

+114
-5
lines changed

app/AdminModule/forms/EditUserSeminarForm.php

+29-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
use App\Model\ACL\Role;
66
use App\Model\ACL\RoleRepository;
7+
use App\Model\Mailing\Template;
8+
use App\Model\Mailing\TemplateVariable;
79
use App\Model\Program\ProgramRepository;
810
use App\Model\Settings\CustomInput\CustomFile;
911
use App\Model\Settings\CustomInput\CustomInput;
1012
use App\Model\Settings\CustomInput\CustomInputRepository;
1113
use App\Model\Settings\CustomInput\CustomText;
14+
use App\Model\Settings\Settings;
1215
use App\Model\Settings\SettingsRepository;
1316
use App\Model\User\CustomInputValue\CustomCheckboxValue;
1417
use App\Model\User\CustomInputValue\CustomInputValueRepository;
@@ -19,6 +22,7 @@
1922
use App\Model\User\UserRepository;
2023
use App\Services\ApplicationService;
2124
use App\Services\FilesService;
25+
use App\Services\MailService;
2226
use App\Services\ProgramService;
2327
use App\Utils\Validators;
2428
use Nette;
@@ -65,6 +69,12 @@ class EditUserSeminarForm extends Nette\Object
6569
/** @var FilesService*/
6670
private $filesService;
6771

72+
/** @var MailService */
73+
private $mailService;
74+
75+
/** @var SettingsRepository */
76+
private $settingsRepository;
77+
6878

6979
/**
7080
* EditUserSeminarForm constructor.
@@ -81,7 +91,8 @@ public function __construct(BaseForm $baseFormFactory, UserRepository $userRepos
8191
CustomInputRepository $customInputRepository,
8292
CustomInputValueRepository $customInputValueRepository,
8393
RoleRepository $roleRepository, ApplicationService $applicationService,
84-
Validators $validators, FilesService $filesService)
94+
Validators $validators, FilesService $filesService, MailService $mailService,
95+
SettingsRepository $settingsRepository)
8596
{
8697
$this->baseFormFactory = $baseFormFactory;
8798
$this->userRepository = $userRepository;
@@ -91,6 +102,8 @@ public function __construct(BaseForm $baseFormFactory, UserRepository $userRepos
91102
$this->applicationService = $applicationService;
92103
$this->validators = $validators;
93104
$this->filesService = $filesService;
105+
$this->mailService = $mailService;
106+
$this->settingsRepository = $settingsRepository;
94107
}
95108

96109
/**
@@ -196,9 +209,13 @@ public function processForm(Form $form, \stdClass $values)
196209
$this->user->setApproved($values['approved']);
197210
$this->user->setAttended($values['attended']);
198211

212+
$customInputValueChanged = FALSE;
213+
199214
foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) {
200215
$customInputValue = $this->user->getCustomInputValue($customInput);
201216

217+
$oldValue = $customInputValue ? $customInputValue->getValue() : NULL;
218+
202219
switch ($customInput->getType()) {
203220
case CustomInput::TEXT:
204221
$customInputValue = $customInputValue ?: new CustomTextValue();
@@ -229,6 +246,9 @@ public function processForm(Form $form, \stdClass $values)
229246
$customInputValue->setUser($this->user);
230247
$customInputValue->setInput($customInput);
231248
$this->customInputValueRepository->save($customInputValue);
249+
250+
if ($oldValue !== $customInputValue->getValue())
251+
$customInputValueChanged = TRUE;
232252
}
233253

234254
if (array_key_exists('arrival', $values))
@@ -242,6 +262,13 @@ public function processForm(Form $form, \stdClass $values)
242262
$this->user->setNote($values['privateNote']);
243263

244264
$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+
}
245272
});
246273
}
247274
}
@@ -279,6 +306,6 @@ public function validateRolesCapacities($field, $args)
279306
*/
280307
private function generatePath($file, User $user, CustomFile $customInput): string
281308
{
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);
283310
}
284311
}

app/WebModule/forms/AdditionalInformationForm.php

+30-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace App\WebModule\Forms;
44

5+
use App\Model\Mailing\Template;
6+
use App\Model\Mailing\TemplateVariable;
57
use App\Model\Settings\CustomInput\CustomFile;
68
use App\Model\Settings\CustomInput\CustomInput;
79
use App\Model\Settings\CustomInput\CustomInputRepository;
10+
use App\Model\Settings\Settings;
11+
use App\Model\Settings\SettingsRepository;
812
use App\Model\User\CustomInputValue\CustomCheckboxValue;
913
use App\Model\User\CustomInputValue\CustomInputValueRepository;
1014
use App\Model\User\CustomInputValue\CustomSelectValue;
@@ -14,6 +18,7 @@
1418
use App\Model\User\UserRepository;
1519
use App\Services\ApplicationService;
1620
use App\Services\FilesService;
21+
use App\Services\MailService;
1722
use Nette;
1823
use Nette\Application\UI\Form;
1924

@@ -50,6 +55,12 @@ class AdditionalInformationForm extends Nette\Object
5055
/** @var FilesService */
5156
private $filesService;
5257

58+
/** @var MailService */
59+
private $mailService;
60+
61+
/** @var SettingsRepository */
62+
private $settingsRepository;
63+
5364

5465
/**
5566
* AdditionalInformationForm constructor.
@@ -61,14 +72,17 @@ class AdditionalInformationForm extends Nette\Object
6172
*/
6273
public function __construct(BaseForm $baseFormFactory, UserRepository $userRepository,
6374
CustomInputRepository $customInputRepository, ApplicationService $applicationService,
64-
CustomInputValueRepository $customInputValueRepository, FilesService $filesService)
75+
CustomInputValueRepository $customInputValueRepository, FilesService $filesService,
76+
MailService $mailService, SettingsRepository $settingsRepository)
6577
{
6678
$this->baseFormFactory = $baseFormFactory;
6779
$this->userRepository = $userRepository;
6880
$this->customInputRepository = $customInputRepository;
6981
$this->applicationService = $applicationService;
7082
$this->customInputValueRepository = $customInputValueRepository;
7183
$this->filesService = $filesService;
84+
$this->mailService = $mailService;
85+
$this->settingsRepository = $settingsRepository;
7286
}
7387

7488
/**
@@ -149,10 +163,14 @@ public function create($id)
149163
public function processForm(Form $form, \stdClass $values)
150164
{
151165
$this->userRepository->getEntityManager()->transactional(function ($em) use ($values) {
166+
$customInputValueChanged = FALSE;
167+
152168
if ($this->applicationService->isAllowedEditCustomInputs()) {
153169
foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) {
154170
$customInputValue = $this->user->getCustomInputValue($customInput);
155171

172+
$oldValue = $customInputValue ? $customInputValue->getValue() : NULL;
173+
156174
switch ($customInput->getType()) {
157175
case CustomInput::TEXT:
158176
$customInputValue = $customInputValue ?: new CustomTextValue();
@@ -183,6 +201,9 @@ public function processForm(Form $form, \stdClass $values)
183201
$customInputValue->setUser($this->user);
184202
$customInputValue->setInput($customInput);
185203
$this->customInputValueRepository->save($customInputValue);
204+
205+
if ($oldValue !== $customInputValue->getValue())
206+
$customInputValueChanged = TRUE;
186207
}
187208
}
188209

@@ -194,6 +215,13 @@ public function processForm(Form $form, \stdClass $values)
194215
$this->user->setDeparture($values['departure']);
195216

196217
$this->userRepository->save($this->user);
218+
219+
if ($customInputValueChanged) {
220+
$this->mailService->sendMailFromTemplate($this->user, '', Template::CUSTOM_INPUT_VALUE_CHANGED, [
221+
TemplateVariable::SEMINAR_NAME => $this->settingsRepository->getValue(Settings::SEMINAR_NAME),
222+
TemplateVariable::USER => $this->user->getDisplayName()
223+
]);
224+
}
197225
});
198226
}
199227

@@ -206,6 +234,6 @@ public function processForm(Form $form, \stdClass $values)
206234
*/
207235
private function generatePath($file, User $user, CustomFile $customInput): string
208236
{
209-
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
237+
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '-' . time() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
210238
}
211239
}

app/WebModule/forms/ApplicationForm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,6 @@ public static function toggleArrivalDeparture(IControl $control): bool
600600
*/
601601
private function generatePath($file, User $user, CustomFile $customInput): string
602602
{
603-
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
603+
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '-' . time() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
604604
}
605605
}

app/model/Mailing/TemplateVariable.php

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class TemplateVariable
7070
*/
7171
const EMAIL_VERIFICATION_LINK = 'email_verification_link';
7272

73+
/**
74+
* Jméno uživatele.
75+
*/
76+
const USER = 'user';
77+
7378

7479
use Identifier;
7580

migrations/Version20171228185809.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Migrations;
4+
5+
use Doctrine\DBAL\Migrations\AbstractMigration;
6+
use Doctrine\DBAL\Schema\Schema;
7+
8+
/**
9+
* Auto-generated Migration: Please modify to your needs!
10+
*/
11+
class Version20171228185809 extends AbstractMigration
12+
{
13+
public function up(Schema $schema)
14+
{
15+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
16+
17+
$this->addSql('CREATE TABLE custom_file (id INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
18+
$this->addSql('CREATE TABLE custom_file_value (id INT NOT NULL, value VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
19+
$this->addSql('ALTER TABLE custom_file ADD CONSTRAINT FK_8DE9FEEDBF396750 FOREIGN KEY (id) REFERENCES custom_input (id) ON DELETE CASCADE');
20+
$this->addSql('ALTER TABLE custom_file_value ADD CONSTRAINT FK_880BD4A9BF396750 FOREIGN KEY (id) REFERENCES custom_input_value (id) ON DELETE CASCADE');
21+
}
22+
23+
public function down(Schema $schema)
24+
{
25+
}
26+
}

migrations/Version20171228213958.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Migrations;
4+
5+
use Doctrine\DBAL\Migrations\AbstractMigration;
6+
use Doctrine\DBAL\Schema\Schema;
7+
8+
/**
9+
* Auto-generated Migration: Please modify to your needs!
10+
*/
11+
class Version20171228213958 extends AbstractMigration
12+
{
13+
public function up(Schema $schema)
14+
{
15+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
16+
17+
$this->addSql('ALTER TABLE custom_file_value CHANGE value value VARCHAR(255) DEFAULT NULL');
18+
}
19+
20+
public function down(Schema $schema)
21+
{
22+
}
23+
}

0 commit comments

Comments
 (0)