diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index fff20940a..e7226b1bd 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -36,7 +36,9 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Role\Role; use Chill\CalendarBundle\Entity\Calendar; use Chill\CalendarBundle\Form\CalendarType; +use Chill\CalendarBundle\Repository\CalendarRepository; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Pagination\PaginatorFactory; use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Routing\Annotation\Route; @@ -55,16 +57,24 @@ class CalendarController extends AbstractController protected SerializerInterface $serializer; + protected PaginatorFactory $paginator; + + private CalendarRepository $calendarRepository; + public function __construct( EventDispatcherInterface $eventDispatcher, AuthorizationHelper $authorizationHelper, LoggerInterface $logger, - SerializerInterface $serializer + SerializerInterface $serializer, + PaginatorFactory $paginator, + CalendarRepository $calendarRepository ) { $this->eventDispatcher = $eventDispatcher; $this->authorizationHelper = $authorizationHelper; $this->logger = $logger; $this->serializer = $serializer; + $this->paginator = $paginator; + $this->calendarRepository = $calendarRepository; } /** @@ -73,31 +83,40 @@ class CalendarController extends AbstractController */ public function listAction(Request $request): Response { - $em = $this->getDoctrine()->getManager(); $view = null; [$user, $accompanyingPeriod] = $this->getEntity($request); if ($user instanceof User) { - $calendarItems = $em->getRepository(Calendar::class) - ->findByUser($user) - ; + $calendarItems = $this->calendarRepository->findByUser($user); + $view = '@ChillCalendar/Calendar/listByUser.html.twig'; + + return $this->render($view, [ + 'calendarItems' => $calendarItems, + 'user' => $user + ]); + } elseif ($accompanyingPeriod instanceof AccompanyingPeriod) { - $calendarItems = $em->getRepository(Calendar::class)->findBy( + + $total = $this->calendarRepository->countByAccompanyingPeriod($accompanyingPeriod); + $paginator = $this->paginator->create($total); + $calendarItems = $this->calendarRepository->findBy( ['accompanyingPeriod' => $accompanyingPeriod], - ['startDate' => 'DESC'] + ['startDate' => 'DESC'], + $paginator->getItemsPerPage(), + $paginator->getCurrentPageFirstItemNumber() ); $view = '@ChillCalendar/Calendar/listByAccompanyingCourse.html.twig'; - } - return $this->render($view, [ - 'calendarItems' => $calendarItems, - 'user' => $user, - 'accompanyingCourse' => $accompanyingPeriod, - ]); + return $this->render($view, [ + 'calendarItems' => $calendarItems, + 'accompanyingCourse' => $accompanyingPeriod, + 'paginator' => $paginator + ]); + } } /** diff --git a/src/Bundle/ChillCalendarBundle/Repository/CalendarRepository.php b/src/Bundle/ChillCalendarBundle/Repository/CalendarRepository.php index edb51bb35..b87f4f525 100644 --- a/src/Bundle/ChillCalendarBundle/Repository/CalendarRepository.php +++ b/src/Bundle/ChillCalendarBundle/Repository/CalendarRepository.php @@ -3,7 +3,9 @@ namespace Chill\CalendarBundle\Repository; use Chill\CalendarBundle\Entity\Calendar; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\ORM\EntityRepository; use Doctrine\Persistence\ManagerRegistry; /** @@ -14,9 +16,13 @@ use Doctrine\Persistence\ManagerRegistry; */ class CalendarRepository extends ServiceEntityRepository { + + // private EntityRepository $repository; + public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Calendar::class); + // $this->repository = $entityManager->getRepository(AccompanyingPeriodWork::class); } // /** diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/list.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/list.html.twig deleted file mode 100644 index 44295e192..000000000 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/list.html.twig +++ /dev/null @@ -1,135 +0,0 @@ -{% set user_id = null %} -{% if user %} - {% set user_id = user.id %} -{% endif %} - -{% set accompanying_course_id = null %} -{% if accompanyingCourse %} - {% set accompanying_course_id = accompanyingCourse.id %} -{% endif %} - -{% if context == 'user' %} -
- {{ "There is no calendar items."|trans }} - -
- {% else %} - -- - {{ calendar.endDate.diff(calendar.startDate)|date("%H:%M")}} -
-+ {{ "There is no calendar items."|trans }} + +
+{% else %} + + +{% endif %} + + + + +{% endblock %} \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByUser.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByUser.html.twig index 004000fc6..6171a0026 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByUser.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByUser.html.twig @@ -5,7 +5,10 @@ {% block title %}{{ 'My calendar list' |trans }}{% endblock title %} {% block content %} - {% include 'ChillCalendarBundle:Calendar:list.html.twig' with {'context': 'user'} %} + +