personRender = $personRender; $this->thirdpartyRender = $thirdPartyRender; } public function validate($participations, Constraint $constraint) { if (!$constraint instanceof ParticipationOverlap) { throw new UnexpectedTypeException($constraint, ParticipationOverlap::class); } if (!$participations instanceof Collection) { throw new UnexpectedTypeException($participations, 'This should be a collection'); } if (count($participations) <= self::MAX_PARTICIPATION) { return; } if (0 === count($participations)) { return; } $participationList = []; foreach ($participations as $participation) { if (!$participation instanceof AccompanyingPeriodParticipation) { throw new UnexpectedTypeException($participation, AccompanyingPeriodParticipation::class); } $personId = $participation->getPerson()->getId(); $participationList[$personId][] = $participation; } foreach ($participationList as $group) { if (count($group) > 1) { $overlaps = new DateRangeCovering(self::MAX_PARTICIPATION, $participations[0]->getStartDate()->getTimezone()); foreach ($group as $p) { $overlaps->add($p->getStartDate(), $p->getEndDate(), $p->getId()); } $overlaps->compute(); if ($overlaps->hasIntersections()) { foreach ($overlaps->getIntersections() as [$start, $end, $ids]) { $msg = null === $end ? $constraint->message : $constraint->message; $this->context->buildViolation($msg) ->setParameters([ '{{ start }}' => $start->format('d-m-Y'), '{{ end }}' => null === $end ? null : $end->format('d-m-Y'), '{{ ids }}' => $ids, '{{ name }}' => $this->personRender->renderString($participation->getPerson(), []), ]) ->addViolation(); } } } } } }