mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
controller + template made to list confirmed parcours for a specific user
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
|
||||
class ReassignAccompanyingPeriodController extends AbstractController
|
||||
{
|
||||
private AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository;
|
||||
|
||||
private EngineInterface $engine;
|
||||
|
||||
private FormFactoryInterface $formFactory;
|
||||
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
private Security $security;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security)
|
||||
{
|
||||
$this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository;
|
||||
$this->engine = $engine;
|
||||
$this->formFactory = $formFactory;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
$this->security = $security;
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/person/accompanying-periods/reassign", name="chill_course_list_reassign")
|
||||
*/
|
||||
public function listAction(Request $request): Response
|
||||
{
|
||||
if (!$this->security->isGranted('ROLE_USER') || !$this->security->getUser() instanceof User) {
|
||||
throw new AccessDeniedException();
|
||||
}
|
||||
|
||||
$form = $this->buildFilterForm();
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
// $total = $this->accompanyingPeriodACLAwareRepository->countByUserConfirmed(
|
||||
// $form['jobs']->getData(),
|
||||
// $form['services']->getData(),
|
||||
// $form['locations']->getData(),
|
||||
// );
|
||||
// $paginator = $this->paginatorFactory->create($total);
|
||||
$periods = $this->accompanyingPeriodACLAwareRepository
|
||||
->findByUserConfirmed(
|
||||
$form['user']->getData(),
|
||||
1,
|
||||
1
|
||||
);
|
||||
|
||||
return new Response(
|
||||
$this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [
|
||||
// 'paginator' => $paginator,
|
||||
'periods' => $periods,
|
||||
'form' => $form->createView()
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
private function buildFilterForm(): FormInterface
|
||||
{
|
||||
$builder = $this->formFactory->createBuilder(FormType::class, [
|
||||
'method' => 'get', 'csrf_protection' => false]);
|
||||
|
||||
$builder
|
||||
->add('user', EntityType::class, [
|
||||
'class' => User::class,
|
||||
'query_builder' => function () {
|
||||
$qb = $this->userRepository->createQueryBuilder('u');
|
||||
|
||||
$qb->where('u.enabled = true')
|
||||
->orderBy('u.username', 'ASC');
|
||||
|
||||
return $qb;
|
||||
},
|
||||
'choice_label' => function (User $u) {
|
||||
return $u->getUsername();
|
||||
},
|
||||
'multiple' => false,
|
||||
'label' => 'User',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
return $builder->getForm();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user