Skip to content

Commit

Permalink
Merge pull request #467 from jan-stanek/mail-zmena-poli
Browse files Browse the repository at this point in the history
upozorneni na zmenu vlastnich poli (#445)
  • Loading branch information
Jan Staněk authored Dec 28, 2017
2 parents 9e40676 + deea29c commit 2b31e90
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 5 deletions.
31 changes: 29 additions & 2 deletions app/AdminModule/forms/EditUserSeminarForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

use App\Model\ACL\Role;
use App\Model\ACL\RoleRepository;
use App\Model\Mailing\Template;
use App\Model\Mailing\TemplateVariable;
use App\Model\Program\ProgramRepository;
use App\Model\Settings\CustomInput\CustomFile;
use App\Model\Settings\CustomInput\CustomInput;
use App\Model\Settings\CustomInput\CustomInputRepository;
use App\Model\Settings\CustomInput\CustomText;
use App\Model\Settings\Settings;
use App\Model\Settings\SettingsRepository;
use App\Model\User\CustomInputValue\CustomCheckboxValue;
use App\Model\User\CustomInputValue\CustomInputValueRepository;
Expand All @@ -19,6 +22,7 @@
use App\Model\User\UserRepository;
use App\Services\ApplicationService;
use App\Services\FilesService;
use App\Services\MailService;
use App\Services\ProgramService;
use App\Utils\Validators;
use Nette;
Expand Down Expand Up @@ -65,6 +69,12 @@ class EditUserSeminarForm extends Nette\Object
/** @var FilesService*/
private $filesService;

/** @var MailService */
private $mailService;

/** @var SettingsRepository */
private $settingsRepository;


/**
* EditUserSeminarForm constructor.
Expand All @@ -81,7 +91,8 @@ public function __construct(BaseForm $baseFormFactory, UserRepository $userRepos
CustomInputRepository $customInputRepository,
CustomInputValueRepository $customInputValueRepository,
RoleRepository $roleRepository, ApplicationService $applicationService,
Validators $validators, FilesService $filesService)
Validators $validators, FilesService $filesService, MailService $mailService,
SettingsRepository $settingsRepository)
{
$this->baseFormFactory = $baseFormFactory;
$this->userRepository = $userRepository;
Expand All @@ -91,6 +102,8 @@ public function __construct(BaseForm $baseFormFactory, UserRepository $userRepos
$this->applicationService = $applicationService;
$this->validators = $validators;
$this->filesService = $filesService;
$this->mailService = $mailService;
$this->settingsRepository = $settingsRepository;
}

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

$customInputValueChanged = FALSE;

foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) {
$customInputValue = $this->user->getCustomInputValue($customInput);

$oldValue = $customInputValue ? $customInputValue->getValue() : NULL;

switch ($customInput->getType()) {
case CustomInput::TEXT:
$customInputValue = $customInputValue ?: new CustomTextValue();
Expand Down Expand Up @@ -229,6 +246,9 @@ public function processForm(Form $form, \stdClass $values)
$customInputValue->setUser($this->user);
$customInputValue->setInput($customInput);
$this->customInputValueRepository->save($customInputValue);

if ($oldValue !== $customInputValue->getValue())
$customInputValueChanged = TRUE;
}

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

$this->userRepository->save($this->user);

if ($customInputValueChanged) {
$this->mailService->sendMailFromTemplate($this->user, '', Template::CUSTOM_INPUT_VALUE_CHANGED, [
TemplateVariable::SEMINAR_NAME => $this->settingsRepository->getValue(Settings::SEMINAR_NAME),
TemplateVariable::USER => $this->user->getDisplayName()
]);
}
});
}
}
Expand Down Expand Up @@ -279,6 +306,6 @@ public function validateRolesCapacities($field, $args)
*/
private function generatePath($file, User $user, CustomFile $customInput): string
{
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '-' . time() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
}
}
32 changes: 30 additions & 2 deletions app/WebModule/forms/AdditionalInformationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace App\WebModule\Forms;

use App\Model\Mailing\Template;
use App\Model\Mailing\TemplateVariable;
use App\Model\Settings\CustomInput\CustomFile;
use App\Model\Settings\CustomInput\CustomInput;
use App\Model\Settings\CustomInput\CustomInputRepository;
use App\Model\Settings\Settings;
use App\Model\Settings\SettingsRepository;
use App\Model\User\CustomInputValue\CustomCheckboxValue;
use App\Model\User\CustomInputValue\CustomInputValueRepository;
use App\Model\User\CustomInputValue\CustomSelectValue;
Expand All @@ -14,6 +18,7 @@
use App\Model\User\UserRepository;
use App\Services\ApplicationService;
use App\Services\FilesService;
use App\Services\MailService;
use Nette;
use Nette\Application\UI\Form;

Expand Down Expand Up @@ -50,6 +55,12 @@ class AdditionalInformationForm extends Nette\Object
/** @var FilesService */
private $filesService;

/** @var MailService */
private $mailService;

/** @var SettingsRepository */
private $settingsRepository;


/**
* AdditionalInformationForm constructor.
Expand All @@ -61,14 +72,17 @@ class AdditionalInformationForm extends Nette\Object
*/
public function __construct(BaseForm $baseFormFactory, UserRepository $userRepository,
CustomInputRepository $customInputRepository, ApplicationService $applicationService,
CustomInputValueRepository $customInputValueRepository, FilesService $filesService)
CustomInputValueRepository $customInputValueRepository, FilesService $filesService,
MailService $mailService, SettingsRepository $settingsRepository)
{
$this->baseFormFactory = $baseFormFactory;
$this->userRepository = $userRepository;
$this->customInputRepository = $customInputRepository;
$this->applicationService = $applicationService;
$this->customInputValueRepository = $customInputValueRepository;
$this->filesService = $filesService;
$this->mailService = $mailService;
$this->settingsRepository = $settingsRepository;
}

/**
Expand Down Expand Up @@ -149,10 +163,14 @@ public function create($id)
public function processForm(Form $form, \stdClass $values)
{
$this->userRepository->getEntityManager()->transactional(function ($em) use ($values) {
$customInputValueChanged = FALSE;

if ($this->applicationService->isAllowedEditCustomInputs()) {
foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) {
$customInputValue = $this->user->getCustomInputValue($customInput);

$oldValue = $customInputValue ? $customInputValue->getValue() : NULL;

switch ($customInput->getType()) {
case CustomInput::TEXT:
$customInputValue = $customInputValue ?: new CustomTextValue();
Expand Down Expand Up @@ -183,6 +201,9 @@ public function processForm(Form $form, \stdClass $values)
$customInputValue->setUser($this->user);
$customInputValue->setInput($customInput);
$this->customInputValueRepository->save($customInputValue);

if ($oldValue !== $customInputValue->getValue())
$customInputValueChanged = TRUE;
}
}

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

$this->userRepository->save($this->user);

if ($customInputValueChanged) {
$this->mailService->sendMailFromTemplate($this->user, '', Template::CUSTOM_INPUT_VALUE_CHANGED, [
TemplateVariable::SEMINAR_NAME => $this->settingsRepository->getValue(Settings::SEMINAR_NAME),
TemplateVariable::USER => $this->user->getDisplayName()
]);
}
});
}

Expand All @@ -206,6 +234,6 @@ public function processForm(Form $form, \stdClass $values)
*/
private function generatePath($file, User $user, CustomFile $customInput): string
{
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '-' . time() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
}
}
2 changes: 1 addition & 1 deletion app/WebModule/forms/ApplicationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,6 @@ public static function toggleArrivalDeparture(IControl $control): bool
*/
private function generatePath($file, User $user, CustomFile $customInput): string
{
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
return CustomFile::PATH . '/' . $user->getId() . '-' . $customInput->getId() . '-' . time() . '.' . pathinfo($file->name, PATHINFO_EXTENSION);
}
}
5 changes: 5 additions & 0 deletions app/model/Mailing/TemplateVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class TemplateVariable
*/
const EMAIL_VERIFICATION_LINK = 'email_verification_link';

/**
* Jméno uživatele.
*/
const USER = 'user';


use Identifier;

Expand Down
26 changes: 26 additions & 0 deletions migrations/Version20171228185809.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types = 1);

namespace Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20171228185809 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('CREATE TABLE custom_file (id INT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$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');
$this->addSql('ALTER TABLE custom_file ADD CONSTRAINT FK_8DE9FEEDBF396750 FOREIGN KEY (id) REFERENCES custom_input (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE custom_file_value ADD CONSTRAINT FK_880BD4A9BF396750 FOREIGN KEY (id) REFERENCES custom_input_value (id) ON DELETE CASCADE');
}

public function down(Schema $schema)
{
}
}
23 changes: 23 additions & 0 deletions migrations/Version20171228213958.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types = 1);

namespace Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20171228213958 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE custom_file_value CHANGE value value VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema)
{
}
}

0 comments on commit 2b31e90

Please sign in to comment.