mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix methods for accompanying period repository acl aware
* add method to interface * delegate ACL to another method
This commit is contained in:
parent
293efc03b4
commit
ac9e55e2fc
@ -16,6 +16,7 @@ use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Templating\Entity\UserRender;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepository;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodACLAwareRepositoryInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
@ -30,7 +31,7 @@ use Symfony\Component\Templating\EngineInterface;
|
||||
|
||||
class ReassignAccompanyingPeriodController extends AbstractController
|
||||
{
|
||||
private AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository;
|
||||
private AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository;
|
||||
|
||||
private EngineInterface $engine;
|
||||
|
||||
@ -44,7 +45,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(AccompanyingPeriodACLAwareRepository $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security, UserRender $userRender)
|
||||
public function __construct(AccompanyingPeriodACLAwareRepositoryInterface $accompanyingPeriodACLAwareRepository, UserRepository $userRepository, EngineInterface $engine, FormFactoryInterface $formFactory, PaginatorFactory $paginatorFactory, Security $security, UserRender $userRender)
|
||||
{
|
||||
$this->accompanyingPeriodACLAwareRepository = $accompanyingPeriodACLAwareRepository;
|
||||
$this->engine = $engine;
|
||||
@ -68,13 +69,14 @@ class ReassignAccompanyingPeriodController extends AbstractController
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
$total = $this->accompanyingPeriodACLAwareRepository->countByUserConfirmed(
|
||||
$total = $this->accompanyingPeriodACLAwareRepository->countByUserOpenedAccompanyingPeriod(
|
||||
$form['user']->getData()
|
||||
);
|
||||
$paginator = $this->paginatorFactory->create($total);
|
||||
$periods = $this->accompanyingPeriodACLAwareRepository
|
||||
->findByUserConfirmed(
|
||||
->findByUserOpenedAccompanyingPeriod(
|
||||
$form['user']->getData(),
|
||||
['openingDate' => 'ASC'],
|
||||
$paginator->getItemsPerPage(),
|
||||
$paginator->getCurrentPageFirstItemNumber()
|
||||
);
|
||||
|
@ -42,28 +42,32 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
|
||||
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
||||
}
|
||||
|
||||
public function buildQueryByUser(?User $user)
|
||||
public function buildQueryOpenedAccompanyingCourseByUser(?User $user)
|
||||
{
|
||||
$qb = $this->accompanyingPeriodRepository->createQueryBuilder('ap');
|
||||
|
||||
$qb->where($qb->expr()->eq('ap.user', ':user'))
|
||||
->andWhere(
|
||||
$qb->expr()->eq('ap.step', ':confirmed'),
|
||||
$qb->expr()->eq('ap.confidential', 'false')
|
||||
$qb->expr()->neq('ap.step', ':draft'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('ap.closingDate'),
|
||||
$qb->expr()->gt('ap.closingDate', ':now')
|
||||
)
|
||||
)
|
||||
->setParameter('user', $user)
|
||||
->setParameter('confirmed', AccompanyingPeriod::STEP_CONFIRMED);
|
||||
->setParameter('now', new \DateTime('now'))
|
||||
->setParameter('draft', AccompanyingPeriod::STEP_DRAFT);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function countByUserConfirmed(?User $user)
|
||||
public function countByUserOpenedAccompanyingPeriod(?User $user): int
|
||||
{
|
||||
if (null === $user) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $this->buildQueryByUser($user)
|
||||
return $this->buildQueryOpenedAccompanyingCourseByUser($user)
|
||||
->select('COUNT(ap)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
@ -124,13 +128,20 @@ final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodAC
|
||||
/**
|
||||
* @return array|AccompanyingPeriod[]
|
||||
*/
|
||||
public function findByUserConfirmed(?User $user, int $limit, int $offset): array
|
||||
public function findByUserOpenedAccompanyingPeriod(?User $user, array $orderBy = [], int $limit = 0, int $offset = 50): array
|
||||
{
|
||||
if (null === $user) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$qb = $this->buildQueryByUser($user);
|
||||
$qb = $this->buildQueryOpenedAccompanyingCourseByUser($user);
|
||||
|
||||
$qb->setFirstResult($offset)
|
||||
->setMaxResults($limit);
|
||||
|
||||
foreach ($orderBy as $field => $direction) {
|
||||
$qb->addOrderBy('ap.'.$field, $direction);
|
||||
}
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
interface AccompanyingPeriodACLAwareRepositoryInterface
|
||||
@ -22,4 +23,8 @@ interface AccompanyingPeriodACLAwareRepositoryInterface
|
||||
?int $limit = null,
|
||||
?int $offset = null
|
||||
): array;
|
||||
|
||||
public function findByUserOpenedAccompanyingPeriod(?User $user, array $orderBy = [], int $limit = 0, int $offset = 50): array;
|
||||
|
||||
public function countByUserOpenedAccompanyingPeriod(?User $user): int;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{% extends 'ChillMainBundle::layout.html.twig' %}
|
||||
|
||||
{% block title "Liste de parcours à réassigner pour un utilisateur" %}
|
||||
{% block title 'period_by_user_list.Period by user'|trans %}
|
||||
|
||||
{% block js %}
|
||||
{{ encore_entry_script_tags('mod_set_referrer') }}
|
||||
@ -60,9 +60,10 @@
|
||||
{{ 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>
|
||||
<p class="chill-no-data-statement">{{ 'period_by_user_list.Pick a user'|trans }}</p>
|
||||
{% elseif periods|length == 0 and form.user.vars.value is not empty %}
|
||||
<p class="chill-no-data-statement">Aucun parcours actifs pour ce référent.</p>
|
||||
<p class="chill-no-data-statement">{{ 'period_by_user_list.Any course or no authorization to see them'|trans }}</p>
|
||||
|
||||
{% else %}
|
||||
<p><span class="badge rounded-pill bg-primary">{{ paginator.totalItems }}</span> parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})</p>
|
||||
|
||||
|
@ -579,3 +579,8 @@ My accompanying periods in draft: Mes parcours brouillons
|
||||
|
||||
workflow:
|
||||
Doc for evaluation (n°%eval%): Document de l'évaluation n°%eval%
|
||||
|
||||
period_by_user_list:
|
||||
Period by user: Parcours d'accompagnement par utilisateur
|
||||
Pick a user: Choisissez un utilisateur pour obtenir la liste de ses parcours
|
||||
Any course or no authorization to see them: Aucun parcours pour ce référent, ou aucun droit pour visualiser les parcours de ce référent.
|
||||
|
Loading…
x
Reference in New Issue
Block a user