Skip to content

Commit

Permalink
Merge pull request #324 from jan-stanek/podakce
Browse files Browse the repository at this point in the history
Podakce - 1. cast
  • Loading branch information
Jan Staněk authored Sep 13, 2017
2 parents 71f26ca + 7a5e09a commit a2a79ac
Show file tree
Hide file tree
Showing 80 changed files with 4,239 additions and 762 deletions.
2 changes: 1 addition & 1 deletion app/AdminModule/ConfigurationModule/forms/MailingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MailingForm extends Nette\Object
* MailingForm constructor.
* @param BaseForm $baseForm
* @param SettingsRepository $settingsRepository
*
* @param UserRepository $userRepository
* @param MailService $mailService
* @param LinkGenerator $linkGenerator
*/
Expand Down
48 changes: 47 additions & 1 deletion app/AdminModule/ConfigurationModule/forms/PaymentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\AdminModule\ConfigurationModule\Forms;

use App\AdminModule\Forms\BaseForm;
use App\Model\Enums\MaturityType;
use App\Model\Enums\VariableSymbolType;
use App\Model\Settings\Settings;
use App\Model\Settings\SettingsRepository;
Expand Down Expand Up @@ -64,12 +65,35 @@ public function create()

$form->addSelect('variableSymbolType', 'admin.configuration.variable_symbol_type', $this->prepareVariableSympolTypeOptions());

$maturityTypeSelect = $form->addSelect('maturityType', 'admin.configuration.maturity_type', $this->prepareMaturityTypeOptions());
$maturityTypeSelect->addCondition($form::EQUAL, MaturityType::DATE)->toggle('maturity-date');
$maturityTypeSelect->addCondition($form::EQUAL, MaturityType::DAYS)->toggle('maturity-days');
$maturityTypeSelect->addCondition($form::EQUAL, MaturityType::WORK_DAYS)->toggle('maturity-work-days');

$form->addDatePicker('maturityDate', 'admin.configuration.maturity_date')
->setOption('id', 'maturity-date');

$form->addText('maturityDays', 'admin.configuration.maturity_days')
->setOption('id', 'maturity-days')
->addCondition(Form::FILLED)
->addRule(Form::INTEGER, 'admin.configuration.maturity_days_format');

$form->addText('maturityWorkDays', 'admin.configuration.maturity_work_days')
->setOption('id', 'maturity-work-days')
->addCondition(Form::FILLED)
->addRule(Form::INTEGER, 'admin.configuration.maturity_work_days_format');


$form->addSubmit('submit', 'admin.common.save');

$form->setDefaults([
'accountNumber' => $this->settingsRepository->getValue(Settings::ACCOUNT_NUMBER),
'variableSymbolCode' => $this->settingsRepository->getValue(Settings::VARIABLE_SYMBOL_CODE),
'variableSymbolType' => $this->settingsRepository->getValue(Settings::VARIABLE_SYMBOL_TYPE)
'variableSymbolType' => $this->settingsRepository->getValue(Settings::VARIABLE_SYMBOL_TYPE),
'maturityType' => $this->settingsRepository->getValue(Settings::MATURITY_TYPE),
'maturityDate' => $this->settingsRepository->getValue(Settings::MATURITY_DATE),
'maturityDays' => $this->settingsRepository->getValue(Settings::MATURITY_DAYS),
'maturityWorkDays' => $this->settingsRepository->getValue(Settings::MATURITY_WORK_DAYS)
]);

$form->onSuccess[] = [$this, 'processForm'];
Expand All @@ -87,6 +111,16 @@ public function processForm(Form $form, \stdClass $values)
$this->settingsRepository->setValue(Settings::ACCOUNT_NUMBER, $values['accountNumber']);
$this->settingsRepository->setValue(Settings::VARIABLE_SYMBOL_CODE, $values['variableSymbolCode']);
$this->settingsRepository->setValue(Settings::VARIABLE_SYMBOL_TYPE, $values['variableSymbolType']);
$this->settingsRepository->setValue(Settings::MATURITY_TYPE, $values['maturityType']);

if (array_key_exists('maturityDate', $values))
$this->settingsRepository->setValue(Settings::MATURITY_DATE, $values['maturityDate']);

if (array_key_exists('maturityDays', $values))
$this->settingsRepository->setValue(Settings::MATURITY_DAYS, $values['maturityDays']);

if (array_key_exists('maturityWorkDays', $values))
$this->settingsRepository->setValue(Settings::MATURITY_WORK_DAYS, $values['maturityWorkDays']);
}

/**
Expand All @@ -100,4 +134,16 @@ private function prepareVariableSympolTypeOptions()
$options[$type] = 'common.variable_symbol_type.' . $type;
return $options;
}

/**
* Vrátí způsoby výpočtu splatnosti jako možnosti pro select.
* @return array
*/
private function prepareMaturityTypeOptions()
{
$options = [];
foreach (MaturityType::$types as $type)
$options[$type] = 'common.maturity_type.' . $type;
return $options;
}
}
19 changes: 17 additions & 2 deletions app/AdminModule/ConfigurationModule/forms/SeminarForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\AdminModule\Forms\BaseForm;
use App\Model\Settings\Settings;
use App\Model\Settings\SettingsRepository;
use App\Model\Structure\SubeventRepository;
use Nette;
use Nette\Application\UI\Form;

Expand All @@ -23,16 +24,22 @@ class SeminarForm extends Nette\Object
/** @var SettingsRepository */
private $settingsRepository;

/** @var SubeventRepository */
private $subeventRepository;


/**
* SeminarForm constructor.
* @param BaseForm $baseForm
* @param SettingsRepository $settingsRepository
* @param SubeventRepository $subeventRepository
*/
public function __construct(BaseForm $baseForm, SettingsRepository $settingsRepository)
public function __construct(BaseForm $baseForm, SettingsRepository $settingsRepository,
SubeventRepository $subeventRepository)
{
$this->baseForm = $baseForm;
$this->settingsRepository = $settingsRepository;
$this->subeventRepository = $subeventRepository;
}

/**
Expand All @@ -59,6 +66,8 @@ public function create()
$editRegistrationTo = $form->addDatePicker('editRegistrationTo', 'admin.configuration.edit_registration_to')
->addRule(Form::FILLED, 'admin.configuration.edit_registration_to_empty');

$form->addCheckbox('isAllowedAddSubeventsAfterPayment', 'admin.configuration.is_allowed_add_subevents_after_payment');

$seminarFromDate->addRule([$this, 'validateSeminarFromDate'], 'admin.configuration.seminar_from_date_after_to', [$seminarFromDate, $seminarToDate]);
$seminarToDate->addRule([$this, 'validateSeminarToDate'], 'admin.configuration.seminar_to_date_before_from', [$seminarToDate, $seminarFromDate]);
$editRegistrationTo->addRule([$this, 'validateEditRegistrationTo'], 'admin.configuration.edit_registration_to_after_from', [$editRegistrationTo, $seminarFromDate]);
Expand All @@ -69,7 +78,8 @@ public function create()
'seminarName' => $this->settingsRepository->getValue(Settings::SEMINAR_NAME),
'seminarFromDate' => $this->settingsRepository->getDateValue(Settings::SEMINAR_FROM_DATE),
'seminarToDate' => $this->settingsRepository->getDateValue(Settings::SEMINAR_TO_DATE),
'editRegistrationTo' => $this->settingsRepository->getDateValue(Settings::EDIT_REGISTRATION_TO)
'editRegistrationTo' => $this->settingsRepository->getDateValue(Settings::EDIT_REGISTRATION_TO),
'isAllowedAddSubeventsAfterPayment' => $this->settingsRepository->getValue(Settings::IS_ALLOWED_ADD_SUBEVENTS_AFTER_PAYMENT),
]);

$form->onSuccess[] = [$this, 'processForm'];
Expand All @@ -85,9 +95,14 @@ public function create()
public function processForm(Form $form, \stdClass $values)
{
$this->settingsRepository->setValue(Settings::SEMINAR_NAME, $values['seminarName']);
$implicitSubevent = $this->subeventRepository->findImplicit();
$implicitSubevent->setName($values['seminarName']);
$this->subeventRepository->save($implicitSubevent);

$this->settingsRepository->setDateValue(Settings::SEMINAR_FROM_DATE, $values['seminarFromDate']);
$this->settingsRepository->setDateValue(Settings::SEMINAR_TO_DATE, $values['seminarToDate']);
$this->settingsRepository->setDateValue(Settings::EDIT_REGISTRATION_TO, $values['editRegistrationTo']);
$this->settingsRepository->setValue(Settings::IS_ALLOWED_ADD_SUBEVENTS_AFTER_PAYMENT, $values['isAllowedAddSubeventsAfterPayment']);
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/AdminModule/MailingModule/forms/EditTemplateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct(BaseForm $baseFormFactory, TemplateRepository $templ

/**
* Vytvoří formulář.
* @param $id
* @return Form
*/
public function create($id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Model\ACL\Permission;
use App\Model\ACL\Resource;
use App\Model\Enums\ApplicationStates;
use App\Model\Mailing\Template;
use App\Model\Mailing\TemplateVariable;
use App\Model\Program\Program;
Expand Down Expand Up @@ -123,9 +124,14 @@ public function createComponentProgramAttendeesGrid($name)
->leftJoin('u.programs', 'p', 'WITH', 'p.id = :pid')
->innerJoin('u.roles', 'r')
->innerJoin('r.permissions', 'per')
->andWhere('per.name = :permission')
->setParameter('pid', $programId)
->innerJoin('u.applications', 'a')
->innerJoin('a.subevents', 's')
->where('per.name = :permission')
->andWhere('s.id = :sid')
->andWhere('(a.state = \'' . ApplicationStates::PAID . '\' OR a.state = \'' . ApplicationStates::WAITING_FOR_PAYMENT . '\')')
->setParameter('pid', $program->getId())
->setParameter('permission', Permission::CHOOSE_PROGRAMS)
->setParameter('sid', $program->getBlock()->getSubevent()->getId())
->orderBy('u.displayName');

if ($this->program->getBlock()->getCategory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Model\Program\ProgramRepository;
use App\Model\Settings\Settings;
use App\Model\Settings\SettingsRepository;
use App\Model\Structure\SubeventRepository;
use App\Model\User\UserRepository;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
Expand Down Expand Up @@ -40,6 +41,9 @@ class ProgramBlocksGridControl extends Control
/** @var ProgramRepository */
private $programRepository;

/** @var SubeventRepository */
private $subeventRepository;


/**
* ProgramBlocksGridControl constructor.
Expand All @@ -52,7 +56,8 @@ class ProgramBlocksGridControl extends Control
*/
public function __construct(Translator $translator, BlockRepository $blockRepository,
SettingsRepository $settingsRepository, UserRepository $userRepository,
CategoryRepository $categoryRepository, ProgramRepository $programRepository)
CategoryRepository $categoryRepository, ProgramRepository $programRepository,
SubeventRepository $subeventRepository)
{
parent::__construct();

Expand All @@ -62,6 +67,7 @@ public function __construct(Translator $translator, BlockRepository $blockReposi
$this->userRepository = $userRepository;
$this->categoryRepository = $categoryRepository;
$this->programRepository = $programRepository;
$this->subeventRepository = $subeventRepository;
}

/**
Expand All @@ -83,15 +89,21 @@ public function createComponentProgramBlocksGrid($name)
$grid->setDataSource($this->blockRepository->createQueryBuilder('b')
->addSelect('l')->leftJoin('b.lector', 'l')
->addSelect('c')->leftJoin('b.category', 'c')
->addSelect('s')->leftJoin('b.subevent', 's')
);
$grid->setDefaultSort(['name' => 'ASC']);
$grid->setPagination(FALSE);
$grid->setColumnsHideable();


$grid->addColumnText('name', 'admin.program.blocks_name')
->setSortable()
->setFilterText();

$grid->addColumnText('subevent', 'admin.program.blocks_subevent', 'subevent.name')
->setSortable('s.name')
->setFilterMultiSelect($this->subeventRepository->getSubeventsOptions(), 's.id');

$grid->addColumnText('category', 'admin.program.blocks_category', 'category.name')
->setSortable('c.name')
->setFilterMultiSelect($this->categoryRepository->getCategoriesOptions(), 'c.id');
Expand All @@ -100,7 +112,7 @@ public function createComponentProgramBlocksGrid($name)
->setSortable('l.displayName')
->setFilterMultiSelect($this->userRepository->getLectorsOptions(), 'l.id');

$grid->addColumnText('duration', 'admin.program.blocks_duration')
$grid->addColumnNumber('duration', 'admin.program.blocks_duration')
->setSortable()
->setFilterText();

Expand Down Expand Up @@ -136,7 +148,7 @@ public function createComponentProgramBlocksGrid($name)
])
->setTranslateOptions();

$grid->addColumnText('programsCount', 'admin.program.blocks_programs_count')
$grid->addColumnNumber('programsCount', 'admin.program.blocks_programs_count')
->setRenderer(function ($row) {
return $row->getProgramsCount();
});
Expand Down
43 changes: 40 additions & 3 deletions app/AdminModule/ProgramModule/forms/BlockForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Model\Program\ProgramRepository;
use App\Model\Settings\Settings;
use App\Model\Settings\SettingsRepository;
use App\Model\Structure\SubeventRepository;
use App\Model\User\User;
use App\Model\User\UserRepository;
use Nette;
Expand All @@ -37,6 +38,12 @@ class BlockForm extends Nette\Object
*/
private $block;

/**
* Počet vytvořených podakcí.
* @var int
*/
private $subeventsCount;

/** @var BaseForm */
private $baseFormFactory;

Expand All @@ -55,6 +62,9 @@ class BlockForm extends Nette\Object
/** @var ProgramRepository */
private $programRepository;

/** @var SubeventRepository */
private $subeventRepository;


/**
* BlockForm constructor.
Expand All @@ -67,14 +77,16 @@ class BlockForm extends Nette\Object
*/
public function __construct(BaseForm $baseFormFactory, BlockRepository $blockRepository,
UserRepository $userRepository, CategoryRepository $categoryRepository,
SettingsRepository $settingsRepository, ProgramRepository $programRepository)
SettingsRepository $settingsRepository, ProgramRepository $programRepository,
SubeventRepository $subeventRepository)
{
$this->baseFormFactory = $baseFormFactory;
$this->blockRepository = $blockRepository;
$this->userRepository = $userRepository;
$this->categoryRepository = $categoryRepository;
$this->settingsRepository = $settingsRepository;
$this->programRepository = $programRepository;
$this->subeventRepository = $subeventRepository;
}

/**
Expand All @@ -88,13 +100,21 @@ public function create($id, $userId)
$this->block = $this->blockRepository->findById($id);
$this->user = $this->userRepository->findById($userId);

$this->subeventsCount = $this->subeventRepository->countExplicitSubevents();

$form = $this->baseFormFactory->create();

$form->addHidden('id');

$form->addText('name', 'admin.program.blocks_name')
->addRule(Form::FILLED, 'admin.program.blocks_name_empty');

if ($this->subeventsCount > 0) {
$form->addSelect('subevent', 'admin.program.blocks_subevent', $this->subeventRepository->getSubeventsOptions())
->setPrompt('')
->addRule(Form::FILLED, 'admin.program.blocks_subevent_empty');
}

$form->addSelect('category', 'admin.program.blocks_category', $this->categoryRepository->getCategoriesOptions())
->setPrompt('');

Expand Down Expand Up @@ -162,6 +182,12 @@ public function create($id, $userId)
'description' => $this->block->getDescription(),
'tools' => $this->block->getTools()
]);

if ($this->subeventsCount > 0) {
$form->setDefaults([
'subevent' => $this->block->getSubevent() ? $this->block->getSubevent()->getId() : NULL
]);
}
} else {
$form['name']->addRule(Form::IS_NOT_IN, 'admin.program.blocks_name_exists', $this->blockRepository->findAllNames());
}
Expand Down Expand Up @@ -189,6 +215,7 @@ public function processForm(Form $form, \stdClass $values)

$oldMandatory = $this->block->getMandatory();
$oldCategory = $this->block->getCategory();
$oldSubevent = $this->block->getSubevent();

$category = $values['category'] != '' ? $this->categoryRepository->findById($values['category']) : NULL;
$lector = $values['lector'] != '' ? $this->userRepository->findById($values['lector']) : NULL;
Expand All @@ -204,6 +231,14 @@ public function processForm(Form $form, \stdClass $values)
$this->block->setDescription($values['description']);
$this->block->setTools($values['tools']);

if ($this->subeventsCount > 0) {
$subevent = $values['subevent'] != '' ? $this->subeventRepository->findById($values['subevent']) : NULL;
$this->block->setSubevent($subevent);
}
else {
$this->block->setSubevent($this->subeventRepository->findImplicit());
}

$this->blockRepository->save($this->block);

//odstraneni ucastniku, pokud se odstrani automaticke prihlasovani
Expand All @@ -220,8 +255,10 @@ public function processForm(Form $form, \stdClass $values)
}
}

//aktualizace ucastniku pri zmene kategorie
if ($oldMandatory == $this->block->getMandatory() && $this->block->getCategory() != $oldCategory) {
//aktualizace ucastniku pri zmene kategorie nebo podakce
if ($oldMandatory == $this->block->getMandatory() && (
$this->block->getCategory() !== $oldCategory) || ($this->block->getSubevent() !== $oldSubevent)
) {
$this->programRepository->updateUsersPrograms($this->userRepository->findAll());
}

Expand Down
Loading

0 comments on commit a2a79ac

Please sign in to comment.