mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
fix cs
This commit is contained in:
parent
537fefee15
commit
fc7d2fcca3
@ -19,16 +19,15 @@ use Chill\CalendarBundle\Repository\CalendarRepository;
|
|||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||||
use Chill\MainBundle\Repository\UserRepository;
|
use Chill\MainBundle\Repository\UserRepository;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|
||||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface;
|
use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
|
use DateTimeImmutable;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
||||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
use Symfony\Component\Form\Form;
|
use Symfony\Component\Form\Form;
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
@ -40,10 +39,10 @@ use Symfony\Component\Serializer\SerializerInterface;
|
|||||||
|
|
||||||
class CalendarController extends AbstractController
|
class CalendarController extends AbstractController
|
||||||
{
|
{
|
||||||
private CalendarRepository $calendarRepository;
|
|
||||||
|
|
||||||
private CalendarACLAwareRepositoryInterface $calendarACLAwareRepository;
|
private CalendarACLAwareRepositoryInterface $calendarACLAwareRepository;
|
||||||
|
|
||||||
|
private CalendarRepository $calendarRepository;
|
||||||
|
|
||||||
private FilterOrderHelperFactoryInterface $filterOrderHelperFactory;
|
private FilterOrderHelperFactoryInterface $filterOrderHelperFactory;
|
||||||
|
|
||||||
private LoggerInterface $logger;
|
private LoggerInterface $logger;
|
||||||
@ -203,32 +202,24 @@ class CalendarController extends AbstractController
|
|||||||
$filterOrder = $this->buildListFilterOrder();
|
$filterOrder = $this->buildListFilterOrder();
|
||||||
['from' => $from, 'to' => $to] = $filterOrder->getDateRangeData('startDate');
|
['from' => $from, 'to' => $to] = $filterOrder->getDateRangeData('startDate');
|
||||||
|
|
||||||
$total = $this->calendarACLAwareRepository
|
$total = $this->calendarACLAwareRepository
|
||||||
->countByAccompanyingPeriod($accompanyingPeriod, $from, $to);
|
->countByAccompanyingPeriod($accompanyingPeriod, $from, $to);
|
||||||
$paginator = $this->paginator->create($total);
|
$paginator = $this->paginator->create($total);
|
||||||
$calendarItems = $this->calendarACLAwareRepository->findByAccompanyingPeriod(
|
$calendarItems = $this->calendarACLAwareRepository->findByAccompanyingPeriod(
|
||||||
$accompanyingPeriod,
|
$accompanyingPeriod,
|
||||||
$from,
|
$from,
|
||||||
$to,
|
$to,
|
||||||
['startDate' => 'DESC'],
|
['startDate' => 'DESC'],
|
||||||
$paginator->getCurrentPageFirstItemNumber(),
|
$paginator->getCurrentPageFirstItemNumber(),
|
||||||
$paginator->getItemsPerPage()
|
$paginator->getItemsPerPage()
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->render('@ChillCalendar/Calendar/listByAccompanyingCourse.html.twig', [
|
return $this->render('@ChillCalendar/Calendar/listByAccompanyingCourse.html.twig', [
|
||||||
'calendarItems' => $calendarItems,
|
'calendarItems' => $calendarItems,
|
||||||
'accompanyingCourse' => $accompanyingPeriod,
|
'accompanyingCourse' => $accompanyingPeriod,
|
||||||
'paginator' => $paginator,
|
'paginator' => $paginator,
|
||||||
'filterOrder' => $filterOrder,
|
'filterOrder' => $filterOrder,
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
private function buildListFilterOrder(): FilterOrderHelper
|
|
||||||
{
|
|
||||||
$filterOrder = $this->filterOrderHelperFactory->create(self::class);
|
|
||||||
$filterOrder->addDateRange('startDate', 'chill_calendar.start date filter', new \DateTimeImmutable('3 days ago'), null);
|
|
||||||
|
|
||||||
return $filterOrder->build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -394,6 +385,14 @@ class CalendarController extends AbstractController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildListFilterOrder(): FilterOrderHelper
|
||||||
|
{
|
||||||
|
$filterOrder = $this->filterOrderHelperFactory->create(self::class);
|
||||||
|
$filterOrder->addDateRange('startDate', 'chill_calendar.start date filter', new DateTimeImmutable('3 days ago'), null);
|
||||||
|
|
||||||
|
return $filterOrder->build();
|
||||||
|
}
|
||||||
|
|
||||||
private function buildParamsToUrl(?User $user, ?AccompanyingPeriod $accompanyingPeriod): array
|
private function buildParamsToUrl(?User $user, ?AccompanyingPeriod $accompanyingPeriod): array
|
||||||
{
|
{
|
||||||
$params = [];
|
$params = [];
|
||||||
|
@ -18,12 +18,9 @@ use Chill\MainBundle\Form\DataTransformer\IdToLocationDataTransformer;
|
|||||||
use Chill\MainBundle\Form\DataTransformer\IdToUserDataTransformer;
|
use Chill\MainBundle\Form\DataTransformer\IdToUserDataTransformer;
|
||||||
use Chill\MainBundle\Form\DataTransformer\IdToUsersDataTransformer;
|
use Chill\MainBundle\Form\DataTransformer\IdToUsersDataTransformer;
|
||||||
use Chill\MainBundle\Form\Type\CommentType;
|
use Chill\MainBundle\Form\Type\CommentType;
|
||||||
|
use Chill\MainBundle\Form\Type\PrivateCommentType;
|
||||||
use Chill\PersonBundle\Form\DataTransformer\PersonsToIdDataTransformer;
|
use Chill\PersonBundle\Form\DataTransformer\PersonsToIdDataTransformer;
|
||||||
use Chill\ThirdPartyBundle\Form\DataTransformer\ThirdPartiesToIdDataTransformer;
|
use Chill\ThirdPartyBundle\Form\DataTransformer\ThirdPartiesToIdDataTransformer;
|
||||||
use Chill\MainBundle\Form\Type\PrivateCommentType;
|
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\CalendarBundle\Repository;
|
namespace Chill\CalendarBundle\Repository;
|
||||||
|
|
||||||
use Chill\CalendarBundle\Entity\Calendar;
|
use Chill\CalendarBundle\Entity\Calendar;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use DateTimeImmutable;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
|
||||||
@ -11,45 +21,12 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface
|
|||||||
{
|
{
|
||||||
private EntityManagerInterface $em;
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param EntityManagerInterface $em
|
|
||||||
*/
|
|
||||||
public function __construct(EntityManagerInterface $em)
|
public function __construct(EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function buildQueryByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): QueryBuilder
|
||||||
/**
|
|
||||||
* @return array|Calendar[]
|
|
||||||
*/
|
|
||||||
public function findByAccompanyingPeriod(AccompanyingPeriod $period, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, ?array $orderBy = [], ?int $offset = null, ?int $limit = null): array
|
|
||||||
{
|
|
||||||
$qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('c');
|
|
||||||
|
|
||||||
foreach ($orderBy as $sort => $order) {
|
|
||||||
$qb->addOrderBy('c.'.$sort, $order);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $offset) {
|
|
||||||
$qb->setFirstResult($offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $limit) {
|
|
||||||
$qb->setMaxResults($limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $qb->getQuery()->getResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function countByAccompanyingPeriod(AccompanyingPeriod $period, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate): int
|
|
||||||
{
|
|
||||||
$qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('count(c)');
|
|
||||||
|
|
||||||
return $qb->getQuery()->getSingleScalarResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function buildQueryByAccompanyingPeriod(AccompanyingPeriod $period, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate): QueryBuilder
|
|
||||||
{
|
{
|
||||||
$qb = $this->em->createQueryBuilder();
|
$qb = $this->em->createQueryBuilder();
|
||||||
$qb->from(Calendar::class, 'c');
|
$qb->from(Calendar::class, 'c');
|
||||||
@ -72,4 +49,32 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface
|
|||||||
return $qb;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function countByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int
|
||||||
|
{
|
||||||
|
$qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('count(c)');
|
||||||
|
|
||||||
|
return $qb->getQuery()->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array|Calendar[]
|
||||||
|
*/
|
||||||
|
public function findByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate, ?array $orderBy = [], ?int $offset = null, ?int $limit = null): array
|
||||||
|
{
|
||||||
|
$qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('c');
|
||||||
|
|
||||||
|
foreach ($orderBy as $sort => $order) {
|
||||||
|
$qb->addOrderBy('c.' . $sort, $order);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $offset) {
|
||||||
|
$qb->setFirstResult($offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $limit) {
|
||||||
|
$qb->setMaxResults($limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $qb->getQuery()->getResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\CalendarBundle\Repository;
|
namespace Chill\CalendarBundle\Repository;
|
||||||
|
|
||||||
use Chill\CalendarBundle\Entity\Calendar;
|
use Chill\CalendarBundle\Entity\Calendar;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use DateTimeImmutable;
|
||||||
|
|
||||||
interface CalendarACLAwareRepositoryInterface
|
interface CalendarACLAwareRepositoryInterface
|
||||||
{
|
{
|
||||||
|
public function countByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|Calendar[]
|
* @return array|Calendar[]
|
||||||
*/
|
*/
|
||||||
public function findByAccompanyingPeriod(AccompanyingPeriod $period, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, ?array $orderBy = [], ?int $offset = null, ?int $limit = null): array;
|
public function findByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate, ?array $orderBy = [], ?int $offset = null, ?int $limit = null): array;
|
||||||
|
|
||||||
public function countByAccompanyingPeriod(AccompanyingPeriod $period, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate): int;
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\MainBundle\Templating\Listing;
|
namespace Chill\MainBundle\Templating\Listing;
|
||||||
|
|
||||||
use Chill\MainBundle\Form\Type\Listing\FilterOrderType;
|
use Chill\MainBundle\Form\Type\Listing\FilterOrderType;
|
||||||
use \DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Symfony\Component\Form\FormFactoryInterface;
|
use Symfony\Component\Form\FormFactoryInterface;
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
@ -86,9 +86,9 @@ class FilterOrderHelper
|
|||||||
return $this->getFormData()['checkboxes'][$name];
|
return $this->getFormData()['checkboxes'][$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDateRanges(): array
|
public function getCheckboxes(): array
|
||||||
{
|
{
|
||||||
return $this->dateRanges;
|
return $this->checkboxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,9 +99,9 @@ class FilterOrderHelper
|
|||||||
return $this->getFormData()['dateRanges'][$name];
|
return $this->getFormData()['dateRanges'][$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCheckboxes(): array
|
public function getDateRanges(): array
|
||||||
{
|
{
|
||||||
return $this->checkboxes;
|
return $this->dateRanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getQueryString(): ?string
|
public function getQueryString(): ?string
|
||||||
|
@ -11,7 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Templating\Listing;
|
namespace Chill\MainBundle\Templating\Listing;
|
||||||
|
|
||||||
use \DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Symfony\Component\Form\FormFactoryInterface;
|
use Symfony\Component\Form\FormFactoryInterface;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user