diff --git a/src/Bundle/ChillMainBundle/Entity/Address.php b/src/Bundle/ChillMainBundle/Entity/Address.php index 1bd1a453a..9fcb07fe5 100644 --- a/src/Bundle/ChillMainBundle/Entity/Address.php +++ b/src/Bundle/ChillMainBundle/Entity/Address.php @@ -255,6 +255,7 @@ class Address implements TrackCreationInterface, TrackUpdateInterface public function syncWithReference(AddressReference $addressReference): Address { + dump($addressReference); $this ->setPoint($addressReference->getPoint()) ->setPostcode($addressReference->getPostcode()) diff --git a/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php b/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php index 8554b4431..6a4d07167 100644 --- a/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php +++ b/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Templating\Listing; +use Chill\MainBundle\Entity\User; use Chill\MainBundle\Form\Type\Listing\FilterOrderType; use DateTimeImmutable; use Symfony\Component\Form\Extension\Core\Type\FormType; @@ -134,7 +135,7 @@ class FilterOrderHelper return $this->userPickers; } - public function getUserPickerData(string $name): array + public function getUserPickerData(string $name) { return $this->getFormData()['user_pickers'][$name]; } diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php index c56489afd..3eb6e67f5 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseWorkController.php @@ -161,7 +161,7 @@ class AccompanyingCourseWorkController extends AbstractController 'types' => $filter->getEntityChoiceData('typesFilter'), 'before' => $filter->getDateRangeData('dateFilter')['to'], 'after' => $filter->getDateRangeData('dateFilter')['from'], - 'users' => $filter->getUserPickerData('userFilter') + 'user' => $filter->getUserPickerData('userFilter') ]; $totalItems = $this->workRepository->countByAccompanyingPeriod($period); @@ -226,7 +226,7 @@ class AccompanyingCourseWorkController extends AbstractController ->addEntityChoice('typesFilter', 'accompanying_course_work.types_filter', \Chill\PersonBundle\Entity\SocialWork\SocialAction::class, $types, [ 'choice_label' => fn (SocialAction $sa) => $this->translatableStringHelper->localize($sa->getTitle()) ]) - ->addUserPicker('userFilter', 'accompanying_course_work.user_filter', ['required' => false]) + ->addUserPicker('userFilter', 'accompanying_course_work.user_filter', ['required' => false, 'multiple' => false]) ; return $filterBuilder->build(); diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php index a5e27afd5..6fc8ff86e 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php @@ -103,40 +103,52 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository $rsm->addRootEntityFromClassMetadata(AccompanyingPeriodWork::class, 'w'); $sql = "SELECT {$rsm} FROM chill_person_accompanying_period_work w - WHERE accompanyingPeriod_id = :periodId - ORDER BY - CASE WHEN enddate IS NULL THEN '-infinity'::timestamp ELSE 'infinity'::timestamp END ASC, - startdate DESC, - enddate DESC, - id DESC"; + WHERE accompanyingPeriod_id = :periodId"; // implement filters if([] !== ($filters['types'] ?? [])) { - $sql .= "AND WHERE w.socialAction IN (:types)"; + $sql .= " AND w.socialaction_id IN (:types)"; } if([] !== ($filters['users'] ?? [])) { - $sql .= "AND WHERE w.createdBy IN (:users)"; + $sql .= " AND w.createdBy = (:userCreated)"; - foreach ($filters['users'] as $key => $user) { - $sql .= "OR :user_" . $key . " IN w.referrers)"; + $sql .= " OR :userReferrer IN (w.referrers)"; + } - $nq = $this->em->createNativeQuery($sql, $rsm) - ->setParameter(':user_' . $key); - } - - // ... to be continued + if (null !== ($after = $filters['after'] ?? null) && null === $filters['before']) { + $sql .= " AND w.startdate::date >= :after"; + } elseif (null !== ($before = $filters['before'] ?? null) && null === $filters['after']) { + $sql .= " AND COALESCE(w.enddate::date, 'infinity'::date) <= :before"; + } elseif (null !== ($after = $filters['after'] ?? null) && null !== ($before = $filters['before'] ?? null)) { + $sql .= " AND w.startdate::date >= :after AND COALESCE(w.enddate::date, 'now'::date) <= :before"; } // set limit and offset + $sql .= " ORDER BY + CASE WHEN enddate IS NULL THEN '-infinity'::timestamp ELSE 'infinity'::timestamp END ASC, + startdate DESC, + enddate DESC, + id DESC"; + $sql .= " LIMIT :limit OFFSET :offset"; + $typeIds = []; + foreach ($filters['types'] as $type) { + $typeIds[] = $type->getId(); + } + $nq = $this->em->createNativeQuery($sql, $rsm) ->setParameter('periodId', $period->getId(), Types::INTEGER) + ->setParameter('types', $typeIds) + ->setParameter('userCreated', $filters['user']) + ->setParameter('userReferrer', $filters['user']) + ->setParameter('after', $filters['after']) + ->setParameter('before', $filters['before']) ->setParameter('limit', $limit, Types::INTEGER) ->setParameter('offset', $offset, Types::INTEGER);