Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin prehledy mazani #938

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions app/AdminModule/Components/GroupsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace App\AdminModule\Components;

use App\Model\Acl\Role;
use App\Model\User\Commands\DeleteTroop;
use App\Model\User\Repositories\TroopRepository;
use App\Model\User\Troop;
use App\Services\CommandBus;
use App\Services\ExcelExportService;
use App\Utils\Helpers;
use Doctrine\Common\Collections\ArrayCollection;
Expand Down Expand Up @@ -35,6 +37,7 @@ class GroupsGridControl extends Control
public function __construct(
private Translator $translator,
private TroopRepository $repository,
private CommandBus $commandBus,
private ExcelExportService $excelExportService,
private Session $session
) {
Expand All @@ -57,7 +60,7 @@ public function render(): void
* @throws DataGridColumnStatusException
* @throws DataGridException
*/
public function createComponentPatrolsGrid(string $name): DataGrid
public function createComponentGroupsGrid(string $name): DataGrid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nechal bych pojmenování Patrol a Troop, ať to odpovídá našim db objektům

{
$grid = new DataGrid($this, $name);
$grid->setTranslator($this->translator);
Expand Down Expand Up @@ -163,33 +166,31 @@ public function createComponentPatrolsGrid(string $name): DataGrid
// $grid->addAction('detail', 'admin.common.detail', 'Users:groupDetail') // destinace ,todo group_detail.latte
// ->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.users.users_delete_confirm'),
// ]);
$grid->addAction('delete', '', 'delete!')
->setIcon('trash')
->setTitle('admin.common.delete')
->setClass('btn btn-xs btn-danger')
->addAttributes([
'data-toggle' => 'confirmation',
'data-content' => 'Smazat přihlášku skupiny?',
]);

return $grid;
}

// /**
// * Zpracuje odstranění externí skupiny.
// *
// * @throws AbortException
// */
// public function handleDelete(int $id): void
// {
// $rec = $this->repository->findById($id);
//
// $this->repository->remove($rec);
//
// $p = $this->getPresenter();
// $p->flashMessage('Skupina smazána.', 'success');
// $p->redirect('this');
// }
/**
* Zpracuje odstranění skupiny.
*
* @throws AbortException
*/
public function handleDelete(int $id): void
{
$this->commandBus->handle(new DeleteTroop($id));

$p = $this->getPresenter();
$p->flashMessage('Skupina smazána.', 'success');
$p->redirect('this');
}

/**
* Vygeneruje potvrzení o přijetí platby.
Expand Down
46 changes: 23 additions & 23 deletions app/AdminModule/Components/PatrolsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace App\AdminModule\Components;

use App\Model\User\Commands\DeletePatrol;
use App\Model\User\Patrol;
use App\Model\User\Repositories\PatrolRepository;
use App\Services\CommandBus;
use App\Services\ExcelExportService;
use App\Utils\Helpers;
use Doctrine\Common\Collections\ArrayCollection;
Expand Down Expand Up @@ -33,6 +35,7 @@ class PatrolsGridControl extends Control

public function __construct(
private Translator $translator,
private CommandBus $commandBus,
private PatrolRepository $repository,
private ExcelExportService $excelExportService,
private Session $session
Expand Down Expand Up @@ -118,33 +121,30 @@ public function createComponentPatrolsGrid(string $name): DataGrid
$grid->addAction('detail', 'admin.common.detail', 'Users:detail') // destinace
->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.users.users_delete_confirm'),
// ]);
$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('Smazat družinu?'),
]);

return $grid;
}

// /**
// * Zpracuje odstranění externího uživatele.
// *
// * @throws AbortException
// */
// public function handleDelete(int $id): void
// {
// $patrol = $this->repository->findById($id);
//
// $this->repository->remove($patrol);
//
// $p = $this->getPresenter();
// $p->flashMessage('Družina smazána', 'success');
// $p->redirect('this');
// }
/**
* Zpracuje odstranění družiny
*
* @throws AbortException
*/
public function handleDelete(int $id): void
{
$this->commandBus->handle(new DeletePatrol($id));
$p = $this->getPresenter();
$p->flashMessage('Družina smazána', 'success');
$p->redirect('this');
}

/**
* Hromadně vyexportuje seznam družin.
Expand Down
2 changes: 1 addition & 1 deletion app/AdminModule/Components/templates/groups_grid.latte
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{control patrolsGrid}
{control groupsGrid}
4 changes: 2 additions & 2 deletions app/AdminModule/Presenters/UsersPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UsersPresenter extends AdminBasePresenter
public IPatrolsGridControlFactory $patrolsGridControlFactory;

#[Inject]
public IGroupsGridControlFactory $GroupsGridControlFactory;
public IGroupsGridControlFactory $groupsGridControlFactory;

#[Inject]
public AddLectorFormFactory $addLectorFormFactory;
Expand Down Expand Up @@ -196,7 +196,7 @@ protected function createComponentPatrolsGrid(): PatrolsGridControl

protected function createComponentGroupsGrid(): GroupsGridControl
{
return $this->GroupsGridControlFactory->create();
return $this->groupsGridControlFactory->create();
}

protected function createComponentAddLectorForm(): Form
Expand Down
13 changes: 13 additions & 0 deletions app/Model/User/Commands/DeletePatrol.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Model\User\Commands;

class DeletePatrol
{
public function __construct(
public int $id,
) {
}
}
13 changes: 13 additions & 0 deletions app/Model/User/Commands/DeleteTroop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Model\User\Commands;

class DeleteTroop
{
public function __construct(
public int $id,
) {
}
}
43 changes: 43 additions & 0 deletions app/Model/User/Commands/Handlers/DeletePatrolHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace App\Model\User\Commands\Handlers;

use App\Model\User\Commands\DeletePatrol;
use App\Model\User\Queries\PatrolByIdQuery;
use App\Model\User\Repositories\PatrolRepository;
use App\Model\User\Repositories\UserGroupRoleRepository;
use App\Model\User\Repositories\UserRepository;
use App\Services\QueryBus;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

class DeletePatrolHandler implements MessageHandlerInterface
{
public function __construct(
private QueryBus $queryBus,
private EntityManagerInterface $em,
private PatrolRepository $patrolRepository,
private UserGroupRoleRepository $userGroupRoleRepository,
private UserRepository $userRepository
) {
}

public function __invoke(DeletePatrol $command): void
{
$this->em->wrapInTransaction(function () use ($command): void {
$patrol = $this->queryBus->handle(new PatrolByIdQuery($command->id));
foreach ($patrol->getUsersRoles() as $usersRole) {
$this->userGroupRoleRepository->remove($usersRole);
$u = $usersRole->getUser();
// $r = $u->getRoles();
if ($u->getRolesText() == '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tohle není moc hezké, co getRoles() empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pozor, že se tu míchají 2 typy rolí - skupinové a uživatelské. Smazat by se měl jen uživatel, který nemá ani jednu (není ve skupině, ani se nepřihlásil přes skautIS)

$this->userRepository->remove($u);
}
}

$this->patrolRepository->remove($patrol);
});
}
}
50 changes: 50 additions & 0 deletions app/Model/User/Commands/Handlers/DeleteTroopHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace App\Model\User\Commands\Handlers;

use App\Model\User\Commands\DeletePatrol;
use App\Model\User\Commands\DeleteTroop;
use App\Model\User\Queries\TroopByIdQuery;
use App\Model\User\Repositories\TroopRepository;
use App\Model\User\Repositories\UserGroupRoleRepository;
use App\Model\User\Repositories\UserRepository;
use App\Services\CommandBus;
use App\Services\QueryBus;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

class DeleteTroopHandler implements MessageHandlerInterface
{
public function __construct(
private QueryBus $queryBus,
private CommandBus $commandBus,
private EntityManagerInterface $em,
private TroopRepository $troopRepository,
private UserGroupRoleRepository $userGroupRoleRepository,
private UserRepository $userRepository
) {
}

public function __invoke(DeleteTroop $command): void
{
$this->em->wrapInTransaction(function () use ($command): void {
$troop = $this->queryBus->handle(new TroopByIdQuery($command->id));
foreach ($troop->getPatrols() as $patrol) {
$this->commandBus->handle(new DeletePatrol($patrol->getId()));
}

foreach ($troop->getUsersRoles() as $usersRole) {
$this->userGroupRoleRepository->remove($usersRole);
$u = $usersRole->getUser();

if ($u->getRolesText() == '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viz mazání družiny

$this->userRepository->remove($usersRole->getUser());
}
}

$this->troopRepository->remove($troop);
});
}
}
6 changes: 6 additions & 0 deletions app/Model/User/Repositories/PatrolRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ public function save(Patrol $patrol): void
$this->em->persist($patrol);
$this->em->flush();
}

public function remove(Patrol $patrol): void
{
$this->em->remove($patrol);
$this->em->flush();
}
}
6 changes: 6 additions & 0 deletions app/Model/User/Repositories/TroopRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,10 @@ public function save(Troop $troop): void
$this->em->persist($troop);
$this->em->flush();
}

public function remove(Troop $troop): void
{
$this->em->remove($troop);
$this->em->flush();
}
}