Skip to content

Commit

Permalink
Group registration 20231218 (#1140)
Browse files Browse the repository at this point in the history
* cumulative commit

* afetr phpcbf app

* cumulative commit

* afetr phpcbf app

* phpstan correction

---------

Co-authored-by: Jan Havelka <[email protected]>
  • Loading branch information
GitHubJanHave and Jan Havelka authored Dec 18, 2023
1 parent aef8698 commit cfc412d
Show file tree
Hide file tree
Showing 33 changed files with 3,443 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
public function create(): Form
{
$form = $this->baseFormFactory->create();

$renderer = $form->getRenderer();
assert($renderer instanceof Bs4FormRenderer);
$renderer->wrappers['control']['container'] = 'div class="col-7"';
Expand All @@ -60,8 +60,6 @@ public function create(): Form
$groupFillTerm->addRule(Form::FILLED, 'admin.configuration.group_fill_term_empty');
$form->addComponent($groupFillTerm, 'groupFillTerm');



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

$form->setDefaults([
Expand Down
43 changes: 27 additions & 16 deletions app/AdminModule/GroupsModule/Components/GroupsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@

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\Model\Group\Repositories\GroupRepository;
use App\Model\User\Repositories\UserRepository;
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;
Expand All @@ -30,14 +27,11 @@
*/
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,
private readonly UserRepository $userRepository,
) {
$this->sessionSection = $session->getSection('srs');

Check failure on line 36 in app/AdminModule/GroupsModule/Components/GroupsGridControl.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis

Access to an undefined property App\AdminModule\GroupsModule\Components\GroupsGridControl::$sessionSection.

Check failure on line 36 in app/AdminModule/GroupsModule/Components/GroupsGridControl.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis

Undefined variable: $session

Check failure on line 36 in app/AdminModule/GroupsModule/Components/GroupsGridControl.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis

Access to an undefined property App\AdminModule\GroupsModule\Components\GroupsGridControl::$sessionSection.

Check failure on line 36 in app/AdminModule/GroupsModule/Components/GroupsGridControl.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis

Undefined variable: $session
}
Expand All @@ -64,12 +58,31 @@ public function createComponentGroupsGrid(string $name): void
$grid->setDefaultSort(['name' => 'ASC']);
$grid->setPagination(false);

$grid->addColumnText('name', 'admin.groups.group.column.name');

$grid->addColumnText('group_status', 'admin.groups.group.column.group_status');

$grid->addColumnText('name', 'admin.program.groups.column.name');
$grid->addColumnText('leader_id', 'admin.groups.group.column.leader_name')
->setRenderer(function (Group $row) {
$user = $this->userRepository->findById($row->getLeaderId());

$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');
return $user->getFirstName() . ' ' . $user->getLastName();
})
/*
->setRenderer(static fn (Group $row) => Html::el('span')
->setText(
$user = $this->userRepository->findById((int) $id);
$this->userService->setApproved($user, (bool) $approved);
$row->getEmail();
)
)
*/
->setFilterText();

$grid->addColumnText('leader_email', 'admin.groups.group.column.leader_email');
$grid->addColumnText('places', 'admin.groups.group.column.places');

$grid->addColumnText('price', 'admin.groups.group.column.price');

$grid->addInlineAdd()->setPositionTop()->onControlAdd[] = function (Container $container): void {
$container->addText('name', '')
Expand All @@ -93,7 +106,7 @@ public function createComponentGroupsGrid(string $name): void
$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()));
$nameText->addRule(Form::IS_NOT_IN, 'admin.program.groups.column.name_exists', $this->groupRepository->findAll());

$container->setDefaults([
'name' => $item->getName(),
Expand Down Expand Up @@ -161,6 +174,4 @@ public function handleDelete(int $id): void
$p->flashMessage('admin.program.groups.message.delete_success', 'success');
$p->redirect('this');
}


}
18 changes: 5 additions & 13 deletions app/AdminModule/GroupsModule/Components/StatusGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
namespace App\AdminModule\GroupsModule\Components;

use App\Model\Acl\Repositories\RoleRepository;
use App\Model\Acl\Role;
use App\Model\Group\Status;
use App\Model\Group\Commands\RemoveStatus;
use App\Model\Group\Commands\SaveStatus;
use App\Model\Group\Repositories\StatusRepository;
use App\Model\Group\Status;
use App\Services\AclService;
use App\Services\CommandBus;
use Nette\Application\AbortException;
Expand All @@ -30,7 +29,7 @@
*/
class StatusGridControl extends Control
{
public function __construct(private CommandBus $commandBus, private Translator $translator, private StatusRepository $statusRepository, private RoleRepository $roleRepository, private AclService $aclService)
public function __construct(private CommandBus $commandBus, private Translator $translator, private StatusRepository $statusRepository)
{
}

Expand Down Expand Up @@ -62,14 +61,12 @@ public function createComponentStatusGrid(string $name): void
$container->addText('name', '')
->addRule(Form::FILLED, 'admin.groups.status.column.name_empty')
->addRule(Form::IS_NOT_IN, 'admin.groups.status.column.name_exists', $this->statusRepository->findAllNames());

};
$grid->getInlineAdd()->onSubmit[] = [$this, 'add'];

$grid->addInlineEdit()->onControlAdd[] = static function (Container $container): void {
$container->addText('name', '')
->addRule(Form::FILLED, 'admin.groups.status.column.name_empty');

};
$grid->getInlineEdit()->onSetDefaults[] = function (Container $container, Status $item): void {
$nameText = $container['name'];
Expand Down Expand Up @@ -97,8 +94,7 @@ public function createComponentStatusGrid(string $name): void
*/
public function add(stdClass $values): void
{
$status = new Status($values->name);

$status = new Status();

$this->commandBus->handle(new SaveStatus($status));

Expand Down Expand Up @@ -136,12 +132,8 @@ public function handleDelete(int $id): void

$p = $this->getPresenter();

if ($status->getBlocks()->isEmpty()) {
$this->commandBus->handle(new RemoveStatus($status));
$p->flashMessage('admin.groups.status.message.delete_success', 'success');
} else {
$p->flashMessage('admin.groups.status.message.delete_failed', 'danger');
}
$this->commandBus->handle(new RemoveStatus($status));
$p->flashMessage('admin.groups.status.message.delete_success', 'success');

$p->redirect('this');
}
Expand Down
3 changes: 1 addition & 2 deletions app/AdminModule/GroupsModule/Presenters/GroupsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace App\AdminModule\GroupsModule\Presenters;

use App\AdminModule\GroupsModule\Components\IGroupsGridControlFactory;
use App\AdminModule\GroupsModule\Components\GroupsGridControl;
use App\AdminModule\GroupsModule\Components\IGroupsGridControlFactory;
use App\Model\Acl\Permission;
use App\Model\Group\Repositories\GroupRepository;
use Nette\Application\AbortException;
Expand All @@ -22,7 +22,6 @@ class GroupsPresenter extends GroupsBasePresenter
#[Inject]
public IGroupsGridControlFactory $groupsGridControlFactory;


/** @throws AbortException */
public function startup(): void
{
Expand Down
5 changes: 5 additions & 0 deletions app/AdminModule/Presenters/templates/Dashboard/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@
<span class="fa fa-2x fa-rotate"></span><br>{_admin.configuration.menu.skautis}
</a>
</div>
<div class="col-2 mb-3">
<a href="{plink Configuration:Group:default}" class="btn btn-secondary btn-sm btn-block">
<span class="fa fa-2x fa-rotate"></span><br>{_admin.configuration.menu.group}
</a>
</div>
<div class="col-2 mb-3">
<a href="{plink Configuration:Web:default}" class="btn btn-secondary btn-sm btn-block">
<span class="fa fa-2x fa-file-code"></span><br>{_admin.configuration.menu.web}
Expand Down
18 changes: 18 additions & 0 deletions app/Model/Acl/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ class Role
*/
public const ADMIN = 'admin';

/**
* Role uživatele nepřihlášeného na seminář.
*/
public const GROUP_NONREGISTERED = 'group_nonregistered';

/**
* Role organizátora.
*/
public const GROUP_LEADER = 'group_leader';

/**
* Role administrátora.
*/
public const GROUP_MEMBER = 'group_member';

/**
* Role, která je uživateli nastavena při testování jiné role.
*/
Expand All @@ -77,6 +92,9 @@ class Role
self::LECTOR,
self::ORGANIZER,
self::ADMIN,
self::GROUP_LEADER,
self::GROUP_MEMBER,
self::GROUP_NONREGISTERED,
];
#[ORM\Id]
#[ORM\GeneratedValue]
Expand Down
17 changes: 17 additions & 0 deletions app/Model/Cms/ApplicationGroupContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Model\Cms;

use Doctrine\ORM\Mapping as ORM;

/**
* Entita obsahu s přihláškou.
*/
#[ORM\Entity]
#[ORM\Table(name: 'application_group_content')]
class ApplicationGroupContent extends Content implements IContent
{
protected string $type = Content::APPLICATION_GROUP;
}
14 changes: 14 additions & 0 deletions app/Model/Cms/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
'text_content' => TextContent::class,
'document_content' => DocumentContent::class,
'application_content' => ApplicationContent::class,
'application_group_content' => ApplicationGroupContent::class,
'manage_group_content' => ManageGroupContent::class,
'html_content' => HtmlContent::class,
'faq_content' => FaqContent::class,
'news_content' => NewsContent::class,
Expand Down Expand Up @@ -62,6 +64,16 @@ abstract class Content implements IContent
*/
public const APPLICATION = 'application';

/**
* ApplicationContent.
*/
public const APPLICATION_GROUP = 'application_group';

/**
* ApplicationContent.
*/
public const MANAGE_GROUP = 'manage_group';

/**
* HtmlContent.
*/
Expand Down Expand Up @@ -156,6 +168,8 @@ abstract class Content implements IContent
self::BLOCKS,
self::CAPACITIES,
self::ORGANIZER,
self::APPLICATION_GROUP,
self::MANAGE_GROUP,
];

/** @var string[] */
Expand Down
17 changes: 17 additions & 0 deletions app/Model/Cms/ManageGroupContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Model\Cms;

use Doctrine\ORM\Mapping as ORM;

/**
* Entita obsahu s přihláškou.
*/
#[ORM\Entity]
#[ORM\Table(name: 'manage_group_content')]
class ManageGroupContent extends Content implements IContent
{
protected string $type = Content::MANAGE_GROUP;
}
5 changes: 5 additions & 0 deletions app/Model/Enums/ApplicationState.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ class ApplicationState
* Zaplaceno (zdarma).
*/
public const PAID_FREE = 'paid_free';

/**
* Ceka na naplneni.
*/
public const WAITING_FOR_FILLING = 'waiting_for_filling';
}
1 change: 0 additions & 1 deletion app/Model/Group/Commands/Handlers/RemoveGroupHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Model\Group\Commands\Handlers;

use App\Model\Group\Commands\RemoveGroup;
use App\Model\Group\Commands\SaveGroup;
use App\Model\Group\Repositories\GroupRepository;
use App\Services\CommandBus;
use Doctrine\ORM\EntityManager;
Expand Down
1 change: 0 additions & 1 deletion app/Model/Group/Commands/Handlers/RemoveStatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function __invoke(RemoveStatus $command): void
$this->em->wrapInTransaction(function () use ($command): void {
$status = $command->getStatus();


$this->statusRepository->remove($status);
});
}
Expand Down
1 change: 0 additions & 1 deletion app/Model/Group/Commands/SaveStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ public function getStatus(): Status
{
return $this->status;
}

}
Loading

0 comments on commit cfc412d

Please sign in to comment.