/**
  * Returns all categories depending on the settings in the demand object
  *
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand $demand CategoryDamand
  *
  * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
  */
 public function findDemanded($demand)
 {
     $constraints = [];
     $query = $this->createQuery();
     if ($demand->getRestrictToStoragePage()) {
         $pidList = GeneralUtility::intExplode(',', $demand->getStoragePage(), true);
         $constraints[] = $query->in('pid', $pidList);
     }
     if ($demand->getCategories()) {
         if ($demand->getIncludeSubcategories()) {
             $categoryList = CategoryService::getCategoryListWithChilds($demand->getCategories());
             $pidList = GeneralUtility::intExplode(',', $categoryList, true);
         } else {
             $pidList = GeneralUtility::intExplode(',', $demand->getCategories(), true);
         }
         $constraints[] = $query->in('uid', $pidList);
     }
     if (count($constraints) > 0) {
         $query->matching($query->logicalAnd($constraints));
     }
     return $query->execute();
 }
 /**
  * Sets the category constraint to the given constraints array
  *
  * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query
  * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand
  * @param array $constraints Constraints
  *
  * @return void
  */
 protected function setCategoryConstraint($query, $eventDemand, &$constraints)
 {
     if ($eventDemand->getCategory() != '') {
         $categoryConstraints = [];
         if ($eventDemand->getIncludeSubcategories()) {
             $categoryList = CategoryService::getCategoryListWithChilds($eventDemand->getCategory());
             $categories = GeneralUtility::intExplode(',', $categoryList, true);
         } else {
             $categories = GeneralUtility::intExplode(',', $eventDemand->getCategory(), true);
         }
         foreach ($categories as $category) {
             $categoryConstraints[] = $query->contains('category', $category);
         }
         if (count($categoryConstraints) > 0) {
             $constraints[] = $query->logicalOr($categoryConstraints);
         }
     }
 }