mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
controller + template made to list confirmed parcours for a specific user
This commit is contained in:
parent
387b7c2fbd
commit
97731b0a9b
@ -32,6 +32,11 @@ final class UserRepository implements ObjectRepository
|
|||||||
$this->repository = $entityManager->getRepository(User::class);
|
$this->repository = $entityManager->getRepository(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
|
||||||
|
{
|
||||||
|
return $this->repository->createQueryBuilder($alias, $indexBy);
|
||||||
|
}
|
||||||
|
|
||||||
public function countBy(array $criteria): int
|
public function countBy(array $criteria): int
|
||||||
{
|
{
|
||||||
return $this->repository->count($criteria);
|
return $this->repository->count($criteria);
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,17 +11,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Controller;
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\User;
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
||||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||||
use Doctrine\ORM\EntityRepository;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Form\FormInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
||||||
use Symfony\Component\Security\Core\Security;
|
|
||||||
|
|
||||||
class UserAccompanyingPeriodController extends AbstractController
|
class UserAccompanyingPeriodController extends AbstractController
|
||||||
{
|
{
|
||||||
@ -29,13 +23,10 @@ class UserAccompanyingPeriodController extends AbstractController
|
|||||||
|
|
||||||
private PaginatorFactory $paginatorFactory;
|
private PaginatorFactory $paginatorFactory;
|
||||||
|
|
||||||
private Security $security;
|
public function __construct(AccompanyingPeriodRepository $accompanyingPeriodRepository, PaginatorFactory $paginatorFactory)
|
||||||
|
|
||||||
public function __construct(AccompanyingPeriodRepository $accompanyingPeriodRepository, PaginatorFactory $paginatorFactory, Security $security)
|
|
||||||
{
|
{
|
||||||
$this->accompanyingPeriodRepository = $accompanyingPeriodRepository;
|
$this->accompanyingPeriodRepository = $accompanyingPeriodRepository;
|
||||||
$this->paginatorFactory = $paginatorFactory;
|
$this->paginatorFactory = $paginatorFactory;
|
||||||
$this->security = $security;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,58 +68,4 @@ class UserAccompanyingPeriodController extends AbstractController
|
|||||||
'pagination' => $pagination,
|
'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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Repository;
|
namespace Chill\PersonBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
@ -92,4 +93,26 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
|
|||||||
|
|
||||||
return $qb->getQuery()->getResult();
|
return $qb->getQuery()->getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array|AccompanyingPeriod[]
|
||||||
|
*/
|
||||||
|
public function findByUserConfirmed(?User $user, int $limit, int $offset): array
|
||||||
|
{
|
||||||
|
if (null === $user) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap');
|
||||||
|
|
||||||
|
$qb->where($qb->expr()->eq('ap.user', ':user'))
|
||||||
|
->andWhere(
|
||||||
|
$qb->expr()->eq('ap.step', ':confirmed')
|
||||||
|
)
|
||||||
|
->setParameter('user', $user)
|
||||||
|
->setParameter('confirmed', AccompanyingPeriod::STEP_CONFIRMED);
|
||||||
|
|
||||||
|
return $qb->getQuery()->getResult();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
{% extends 'ChillMainBundle::layout.html.twig' %}
|
||||||
|
|
||||||
|
{% block title "Liste de parcours à réassigner" %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{{ encore_entry_script_tags('mod_set_referrer') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block css %}
|
||||||
|
{{ encore_entry_link_tags('mod_set_referrer') }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{# {% macro period_meta(period) %}
|
||||||
|
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %}
|
||||||
|
<div class="item-col item-meta">
|
||||||
|
{% set job_id = null %}
|
||||||
|
{% if period.job is defined %}
|
||||||
|
{% set job_id = period.job.id %}
|
||||||
|
{% endif %}
|
||||||
|
<span
|
||||||
|
data-set-referrer-app="data-set-referrer-app"
|
||||||
|
data-set-referrer-accompanying-period-id="{{ period.id }}"
|
||||||
|
data-set-referrer-job-id="{{ job_id }}"
|
||||||
|
></span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %} #}
|
||||||
|
|
||||||
|
{% macro period_actions(period) %}
|
||||||
|
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', period) %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ chill_path_add_return_path('chill_person_accompanying_course_index', {'accompanying_period_id': period.id}) }}" class="btn btn-show"></a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% import _self as m %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="col-10">
|
||||||
|
<h1>{{ block('title') }}</h1>
|
||||||
|
|
||||||
|
{{ form_start(form) }}
|
||||||
|
<div class="row filter-box" style="padding: 2rem 2rem 2rem 0;">
|
||||||
|
<div class="col-md-6" style="display: flex; justify-content: space-between;">
|
||||||
|
{{ form_label(form.user ) }}
|
||||||
|
{{ form_widget(form.user, {'attr': {'class': 'select2'}}) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<button type="submit" class="btn btn-save change-icon">
|
||||||
|
<i class="fa fa-filter"></i> Filtrer
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{{ form_end(form) }}
|
||||||
|
|
||||||
|
{% if form.user.vars.value is empty %}
|
||||||
|
<p class="chill-no-data-statement">Choisissez un référent pour afficher ses parcours.</p>
|
||||||
|
{% elseif periods|length == 0 and form.user.vars.value is not empty %}
|
||||||
|
<p class="chill-no-data-statement">Aucun parcour à réassigner pour cet utilisateur.</p>
|
||||||
|
{% else %}
|
||||||
|
<p><span class="badge rounded-pill bg-primary">Amount of</span> parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})</p>
|
||||||
|
|
||||||
|
<div class="flex-table">
|
||||||
|
{% for period in periods %}
|
||||||
|
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
|
||||||
|
'recordAction': m.period_actions(period) } %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{# {{ chill_pagination(paginator) }} #}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -41,6 +41,11 @@ services:
|
|||||||
autowire: true
|
autowire: true
|
||||||
tags: ['controller.service_arguments']
|
tags: ['controller.service_arguments']
|
||||||
|
|
||||||
|
Chill\PersonBundle\Controller\ReassignAccompanyingPeriodController:
|
||||||
|
autoconfigure: true
|
||||||
|
autowire: true
|
||||||
|
tags: ['controller.service_arguments']
|
||||||
|
|
||||||
Chill\PersonBundle\Controller\PersonApiController:
|
Chill\PersonBundle\Controller\PersonApiController:
|
||||||
arguments:
|
arguments:
|
||||||
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user