-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jan Havelka <[email protected]>
- Loading branch information
1 parent
757dfa0
commit ae693f8
Showing
42 changed files
with
1,676 additions
and
0 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
app/AdminModule/ConfigurationModule/Forms/GroupFormFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\AdminModule\ConfigurationModule\Forms; | ||
|
||
use App\AdminModule\Forms\BaseFormFactory; | ||
use App\Model\Settings\Commands\SetSettingDateValue; | ||
use App\Model\Settings\Commands\SetSettingStringValue; | ||
use App\Model\Settings\Queries\SettingDateValueQuery; | ||
use App\Model\Settings\Queries\SettingStringValueQuery; | ||
use App\Model\Settings\Settings; | ||
use App\Services\CommandBus; | ||
use App\Services\QueryBus; | ||
use Nette; | ||
use Nette\Application\UI\Form; | ||
use Nette\Utils\DateTime; | ||
use Nextras\FormComponents\Controls\DateControl; | ||
use Nextras\FormsRendering\Renderers\Bs4FormRenderer; | ||
use stdClass; | ||
use Throwable; | ||
|
||
use function assert; | ||
|
||
/** | ||
* Formulář pro nastavení semináře. | ||
*/ | ||
class GroupFormFactory | ||
{ | ||
use Nette\SmartObject; | ||
|
||
public function __construct( | ||
private BaseFormFactory $baseFormFactory, | ||
private CommandBus $commandBus, | ||
private QueryBus $queryBus, | ||
) { | ||
} | ||
|
||
/** | ||
* Vytvoří formulář. | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function create(): Form | ||
{ | ||
$form = $this->baseFormFactory->create(); | ||
|
||
$renderer = $form->getRenderer(); | ||
assert($renderer instanceof Bs4FormRenderer); | ||
$renderer->wrappers['control']['container'] = 'div class="col-7"'; | ||
$renderer->wrappers['label']['container'] = 'div class="col-5 col-form-label"'; | ||
|
||
$form->addText('groupMinMembers', 'admin.configuration.group_min_members') | ||
->addRule(Form::FILLED, 'admin.configuration.group_min_members_empty'); | ||
|
||
$form->addText('groupMaxMembers', 'admin.configuration.group_max_members') | ||
->addRule(Form::FILLED, 'admin.configuration.group_max_members_empty'); | ||
|
||
$groupFillTerm = new DateControl('admin.configuration.group_fill_term'); | ||
$groupFillTerm->addRule(Form::FILLED, 'admin.configuration.group_fill_term_empty'); | ||
$form->addComponent($groupFillTerm, 'groupFillTerm'); | ||
|
||
|
||
|
||
$form->addSubmit('submit', 'admin.common.save'); | ||
|
||
$form->setDefaults([ | ||
'groupMinMembers' => $this->queryBus->handle(new SettingStringValueQuery(Settings::GROUP_MIN_MEMBERS)), | ||
'groupMaxMembers' => $this->queryBus->handle(new SettingStringValueQuery(Settings::GROUP_MAX_MEMBERS)), | ||
'groupFillTerm' => $this->queryBus->handle(new SettingDateValueQuery(Settings::GROUP_FILL_TERM)), | ||
]); | ||
|
||
$form->onSuccess[] = [$this, 'processForm']; | ||
|
||
return $form; | ||
} | ||
|
||
/** | ||
* Zpracuje formulář. | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function processForm(Form $form, stdClass $values): void | ||
{ | ||
$this->commandBus->handle(new SetSettingStringValue(Settings::GROUP_MIN_MEMBERS, $values->groupMinMembers)); | ||
$this->commandBus->handle(new SetSettingStringValue(Settings::GROUP_MAX_MEMBERS, $values->groupMaxMembers)); | ||
$this->commandBus->handle(new SetSettingDateValue(Settings::GROUP_FILL_TERM, $values->groupFillTerm)); | ||
} | ||
|
||
/** | ||
* Ověří, že datum začátku semináře je dříve než konce. | ||
* | ||
* @param DateTime[] $args | ||
*/ | ||
public function validateSeminarFromDate(DateControl $field, array $args): bool | ||
{ | ||
return $args[0] <= $args[1]; | ||
} | ||
|
||
/** | ||
* Ověří, že datum konce semináře je později než začátku. | ||
* | ||
* @param DateTime[] $args | ||
*/ | ||
public function validateSeminarToDate(DateControl $field, array $args): bool | ||
{ | ||
return $args[0] >= $args[1]; | ||
} | ||
|
||
/** | ||
* Ověří, že datum uzavření registrace je dříve než začátek semináře. | ||
* | ||
* @param DateTime[] $args | ||
*/ | ||
public function validateEditRegistrationTo(DateControl $field, array $args): bool | ||
{ | ||
return $args[0] < $args[1]; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/AdminModule/ConfigurationModule/Presenters/GroupPresenter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\AdminModule\ConfigurationModule\Presenters; | ||
|
||
use App\AdminModule\ConfigurationModule\Forms\GroupFormFactory; | ||
use App\Model\Settings\Exceptions\SettingsItemNotFoundException; | ||
use Nette\Application\UI\Form; | ||
use Nette\DI\Attributes\Inject; | ||
use stdClass; | ||
use Throwable; | ||
|
||
/** | ||
* Presenter obsluhující nastavení skupin. | ||
*/ | ||
class GroupPresenter extends ConfigurationBasePresenter | ||
{ | ||
#[Inject] | ||
public GroupFormFactory $groupFormFactory; | ||
|
||
/** | ||
* @throws SettingsItemNotFoundException | ||
* @throws Throwable | ||
*/ | ||
protected function createComponentGroupForm(): Form | ||
{ | ||
$form = $this->groupFormFactory->create(); | ||
|
||
$form->onSuccess[] = function (Form $form, stdClass $values): void { | ||
$this->flashMessage('admin.configuration.configuration_saved', 'success'); | ||
$this->redirect('this'); | ||
}; | ||
|
||
return $form; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/AdminModule/ConfigurationModule/Presenters/templates/Group/default.latte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{block main} | ||
<h2>{_admin.configuration.group_heading}</h2> | ||
<div class="card card-body bg-light pb-1 mb-3"> | ||
{control groupForm} | ||
</div> | ||
{/block} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
app/AdminModule/GroupsModule/Components/GroupsGridControl.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\AdminModule\GroupsModule\Components; | ||
|
||
use App\Model\Group\Commands\RemoveGroup; | ||
use App\Model\Group\Commands\SaveGroup; | ||
use App\Model\Group\Repositories\GroupRepository; | ||
use App\Model\Group\Group; | ||
use App\Services\CommandBus; | ||
use App\Services\ExcelExportService; | ||
use Exception; | ||
use Nette\Application\AbortException; | ||
use Nette\Application\UI\Control; | ||
use Nette\Application\UI\Form; | ||
use Nette\Forms\Container; | ||
use Nette\Forms\Controls\TextInput; | ||
use Nette\Http\Session; | ||
use Nette\Http\SessionSection; | ||
use Nette\Localization\Translator; | ||
use stdClass; | ||
use Ublaboo\DataGrid\DataGrid; | ||
use Ublaboo\DataGrid\Exception\DataGridException; | ||
|
||
use function assert; | ||
|
||
/** | ||
* Komponenta pro správu místností. | ||
*/ | ||
class GroupsGridControl extends Control | ||
{ | ||
private SessionSection $sessionSection; | ||
|
||
public function __construct( | ||
private CommandBus $commandBus, | ||
private Translator $translator, | ||
private GroupRepository $groupRepository, | ||
private ExcelExportService $excelExportService, | ||
private Session $session, | ||
) { | ||
$this->sessionSection = $session->getSection('srs'); | ||
} | ||
|
||
/** | ||
* Vykreslí komponentu. | ||
*/ | ||
public function render(): void | ||
{ | ||
$this->template->setFile(__DIR__ . '/templates/groups_grid.latte'); | ||
$this->template->render(); | ||
} | ||
|
||
/** | ||
* Vytvoří komponentu. | ||
* | ||
* @throws DataGridException | ||
*/ | ||
public function createComponentGroupsGrid(string $name): void | ||
{ | ||
$grid = new DataGrid($this, $name); | ||
$grid->setTranslator($this->translator); | ||
$grid->setDataSource($this->groupRepository->createQueryBuilder('g')); | ||
$grid->setDefaultSort(['name' => 'ASC']); | ||
$grid->setPagination(false); | ||
|
||
|
||
$grid->addColumnText('name', 'admin.program.groups.column.name'); | ||
|
||
$grid->addColumnText('leader_email', 'admin.program.groups.column.name'); | ||
$grid->addColumnText('places', 'admin.program.groups.column.name'); | ||
$grid->addColumnText('price', 'admin.program.groups.column.name'); | ||
|
||
$grid->addInlineAdd()->setPositionTop()->onControlAdd[] = function (Container $container): void { | ||
$container->addText('name', '') | ||
->addRule(Form::FILLED, 'admin.program.groups.column.name_empty') | ||
->addRule(Form::IS_NOT_IN, 'admin.program.groups.column.name_exists', $this->groupRepository->findAll()); | ||
|
||
$container->addText('places', '') | ||
->addCondition(Form::FILLED) | ||
->addRule(Form::INTEGER, 'admin.program.groups.column.capacity_format'); | ||
}; | ||
$grid->getInlineAdd()->onSubmit[] = [$this, 'add']; | ||
|
||
$grid->addInlineEdit()->onControlAdd[] = static function (Container $container): void { | ||
$container->addText('name', '') | ||
->addRule(Form::FILLED, 'admin.program.groups.column.name_empty'); | ||
|
||
$container->addText('places', '') | ||
->addCondition(Form::FILLED) | ||
->addRule(Form::INTEGER, 'admin.program.groups.column.capacity_format'); | ||
}; | ||
$grid->getInlineEdit()->onSetDefaults[] = function (Container $container, Group $item): void { | ||
$nameText = $container['name']; | ||
assert($nameText instanceof TextInput); | ||
$nameText->addRule(Form::IS_NOT_IN, 'admin.program.groups.column.name_exists', $this->groupRepository->findOthersNames($item->getId())); | ||
|
||
$container->setDefaults([ | ||
'name' => $item->getName(), | ||
'places' => $item->getPlaces(), | ||
]); | ||
}; | ||
$grid->getInlineEdit()->onSubmit[] = [$this, 'edit']; | ||
|
||
$grid->addAction('detail', 'admin.common.detail', 'Groups:detail') | ||
->setClass('btn btn-xs btn-primary'); | ||
|
||
$grid->addAction('delete', '', 'delete!') | ||
->setIcon('trash') | ||
->setTitle('admin.common.delete') | ||
->setClass('btn btn-xs btn-danger') | ||
->addAttributes([ | ||
'data-toggle' => 'confirmation', | ||
'data-content' => $this->translator->translate('admin.program.groups.action.delete_confirm'), | ||
]); | ||
} | ||
|
||
/** | ||
* Zpracuje přidání místnosti. | ||
*/ | ||
public function add(stdClass $values): void | ||
{ | ||
$group = new Group($values->name, $values->capacity !== '' ? $values->capacity : null); | ||
|
||
$this->commandBus->handle(new SaveGroup($group)); | ||
|
||
$p = $this->getPresenter(); | ||
$p->flashMessage('admin.program.groups.message.save_success', 'success'); | ||
$p->redrawControl('flashes'); | ||
} | ||
|
||
/** | ||
* Zpracuje úpravu místnosti. | ||
*/ | ||
public function edit(string $id, stdClass $values): void | ||
{ | ||
$group = $this->groupRepository->findById((int) $id); | ||
|
||
$group->setName($values->name); | ||
$group->setCapacity($values->capacity !== '' ? $values->capacity : null); | ||
|
||
$this->commandBus->handle(new SaveGroup($group)); | ||
|
||
$p = $this->getPresenter(); | ||
$p->flashMessage('admin.program.groups.message.save_success', 'success'); | ||
$p->redrawControl('flashes'); | ||
} | ||
|
||
/** | ||
* Odstraní místnost. | ||
* | ||
* @throws AbortException | ||
*/ | ||
public function handleDelete(int $id): void | ||
{ | ||
$group = $this->groupRepository->findById($id); | ||
|
||
$this->commandBus->handle(new RemoveGroup($group)); | ||
|
||
$p = $this->getPresenter(); | ||
$p->flashMessage('admin.program.groups.message.delete_success', 'success'); | ||
$p->redirect('this'); | ||
} | ||
|
||
|
||
} |
16 changes: 16 additions & 0 deletions
16
app/AdminModule/GroupsModule/Components/IGroupsGridControlFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\AdminModule\GroupsModule\Components; | ||
|
||
/** | ||
* Factory komponenty pro správu místností. | ||
*/ | ||
interface IGroupsGridControlFactory | ||
{ | ||
/** | ||
* Vytvoří komponentu. | ||
*/ | ||
public function create(): GroupsGridControl; | ||
} |
16 changes: 16 additions & 0 deletions
16
app/AdminModule/GroupsModule/Components/IStatusGridControlFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\AdminModule\GroupsModule\Components; | ||
|
||
/** | ||
* Factory komponenty pro správu kategorií. | ||
*/ | ||
interface IStatusGridControlFactory | ||
{ | ||
/** | ||
* Vytvoří komponentu. | ||
*/ | ||
public function create(): StatusGridControl; | ||
} |
Oops, something went wrong.