/** * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query * @param \DWenzel\T3events\Domain\Model\Dto\DemandInterface $demand * @return array */ public function createConstraintsFromDemand(QueryInterface $query, DemandInterface $demand) { /** @var ReservationDemand $demand */ $constraints = []; if ($demand->getLessonDeadline()) { $constraints[] = $query->logicalAnd($query->lessThan('lesson.deadline', $demand->getLessonDeadline())); } if ($demand->getStatus()) { $statusArr = GeneralUtility::intExplode(',', $demand->getStatus()); $statusConstraints = []; foreach ($statusArr as $status) { $statusConstraints[] = $query->equals('status', $status); } $constraints[] = $query->logicalOr($statusConstraints); } if ($demand->getMinAge()) { $constraints[] = $query->logicalAnd($query->lessThan('tstamp', time() - $demand->getMinAge())); } if ($demand->getLessonDate()) { if ($demand->getPeriod() === 'futureOnly') { $constraints[] = $query->greaterThanOrEqual('lesson.date', $demand->getLessonDate()); } elseif ($demand->getPeriod() === 'pastOnly') { $constraints[] = $query->lessThanOrEqual('lesson.date', $demand->getLessonDate()); } } if ((bool) ($genreConstraints = $this->createGenreConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $genreConstraints, $demand->getCategoryConjunction()); } if ((bool) ($searchConstraints = $this->createSearchConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $searchConstraints, 'OR'); } if ((bool) ($eventTypeConstraints = $this->createEventTypeConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $eventTypeConstraints, $demand->getCategoryConjunction()); } if ((bool) ($periodConstraints = $this->createPeriodConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $periodConstraints); } if ((bool) ($audienceConstraints = $this->createAudienceConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $audienceConstraints); } return $constraints; }
/** * Returns an array of constraints created from a given demand object. * * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query * @param \DWenzel\T3events\Domain\Model\Dto\DemandInterface $demand * @return array<\TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint> */ public function createConstraintsFromDemand(QueryInterface $query, DemandInterface $demand) { /** @var \CPSIT\T3eventsReservation\Domain\Model\Dto\PersonDemand $demand */ $constraints = []; if ($demand->getTypes()) { $personTypes = explode(',', $demand->getTypes()); $personConstraints = []; foreach ($personTypes as $personType) { $personConstraints[] = $query->equals('type', $personType); } if (count($personConstraints)) { $constraints[] = $query->logicalAnd($personConstraints); } } if ($demand->getLessonDeadline()) { $constraints[] = $query->logicalAnd($query->lessThan('lesson.deadline', $demand->getLessonDeadline())); } if ($demand->getLessonDate()) { if ($demand->getLessonPeriod() === 'futureOnly') { $constraints[] = $query->greaterThanOrEqual('reservation.lesson.date', $demand->getLessonDate()); } elseif ($demand->getLessonPeriod() === 'pastOnly') { $constraints[] = $query->lessThanOrEqual('reservation.lesson.date', $demand->getLessonDate()); } } if ((bool) ($genreConstraints = $this->createGenreConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $genreConstraints, $demand->getCategoryConjunction()); } if ((bool) ($searchConstraints = $this->createSearchConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $searchConstraints, 'OR'); } if ((bool) ($eventTypeConstraints = $this->createEventTypeConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $eventTypeConstraints, $demand->getCategoryConjunction()); } if ((bool) ($categoryConstraints = $this->createCategoryConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $categoryConstraints, $demand->getCategoryConjunction()); } if ((bool) ($periodConstraints = $this->createPeriodConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $periodConstraints); } if ((bool) ($audienceConstraints = $this->createAudienceConstraints($query, $demand))) { $this->combineConstraints($query, $constraints, $audienceConstraints); } return $constraints; }