mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
first commit
This commit is contained in:
parent
5c68879509
commit
387b7c2fbd
@ -11,11 +11,17 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class UserAccompanyingPeriodController extends AbstractController
|
||||
{
|
||||
@ -23,10 +29,13 @@ class UserAccompanyingPeriodController extends AbstractController
|
||||
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
public function __construct(AccompanyingPeriodRepository $accompanyingPeriodRepository, PaginatorFactory $paginatorFactory)
|
||||
private Security $security;
|
||||
|
||||
public function __construct(AccompanyingPeriodRepository $accompanyingPeriodRepository, PaginatorFactory $paginatorFactory, Security $security)
|
||||
{
|
||||
$this->accompanyingPeriodRepository = $accompanyingPeriodRepository;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,4 +77,58 @@ class UserAccompanyingPeriodController extends AbstractController
|
||||
'pagination' => $pagination,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/person/accompanying-periods/my/drafts", name="chill_person_accompanying_period_draft_user")
|
||||
*/
|
||||
public function listConfirmedAction(Request $request)
|
||||
{
|
||||
if (!$this->security->isGranted('ROLE_USER') || !$this->security->getUser() instanceof User) {
|
||||
throw new AccessDeniedException();
|
||||
}
|
||||
|
||||
$form = $this->buildUserSelectionForm();
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$user = $_POST['user'];
|
||||
|
||||
$periods = $this->getDoctrine()->getRepository(AccompanyingPeriod::class)->findConfirmedByUser($user);
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingPeriod/user_reassign_periods_list.html.twig', [
|
||||
'accompanyingPeriods' => $periods,
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render('@ChillPerson/AccompanyingPeriod/user_reassign_periods_list.html.twig', [
|
||||
'form' => $form
|
||||
]);
|
||||
}
|
||||
|
||||
private function buildUserSelectionForm(): FormInterface
|
||||
{
|
||||
$data = [
|
||||
'users' => [],
|
||||
];
|
||||
|
||||
$builder = $this->formFactory->createBuilder(FormType::class, $data, [
|
||||
'method' => 'get', 'csrf_protection' => false]);
|
||||
|
||||
$builder
|
||||
->add('users', EntityType::class, [
|
||||
'class' => User::class,
|
||||
'query_builder' => function (EntityRepository $er) {
|
||||
$qb = $er->createQueryBuilder('u');
|
||||
return $qb;
|
||||
},
|
||||
'choice_label' => function(User $u) {
|
||||
return $u->getUsername();
|
||||
},
|
||||
'multiple' => false,
|
||||
'label' => 'User',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
return $builder->getForm();
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,16 @@ final class AccompanyingPeriodRepository implements ObjectRepository
|
||||
->getResult();
|
||||
}
|
||||
|
||||
public function findConfirmedByUser(User $user)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('ap');
|
||||
$qb->where($qb->expr()->eq('ap.user', ':user'))
|
||||
->andWhere('ap.step', 'CONFIRMED')
|
||||
->setParameter('user', $user);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria): ?AccompanyingPeriod
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
|
Loading…
x
Reference in New Issue
Block a user