/**
  * Find by a specification.
  *
  * It is highly recommend to pass a QuerySpecification. Otherwise all items have to be loaded!.
  *
  * @param Specification $specification The specification.
  *
  * @return array|CollectionInterface|ModelInterface[]|\string[]
  */
 public function findBySpecification(Specification $specification)
 {
     if ($specification instanceof QuerySpecification) {
         $config = $this->provider->getEmptyConfig();
         $specification->prepare($config);
         return $this->provider->fetchAll($config);
     }
     $result = $this->provider->fetchAll($this->provider->getEmptyConfig());
     $filtered = array();
     foreach ($result as $entity) {
         if ($specification->isSatisfiedBy($entity)) {
             $filtered[] = $entity;
         }
     }
     return $filtered;
 }
Beispiel #2
0
 /**
  * Retrieve the children of a model (if any exist).
  *
  * @param DataProviderInterface         $dataProvider   The data provider.
  *
  * @param ModelInterface                $model          The model.
  *
  * @param ParentChildConditionInterface $childCondition The condition.
  *
  * @return CollectionInterface|null
  */
 private function getChildrenOfModel($dataProvider, $model, $childCondition)
 {
     $childIds = $dataProvider->fetchAll($dataProvider->getEmptyConfig()->setFilter($childCondition->getFilter($model))->setIdOnly(true));
     if (!$childIds) {
         return null;
     }
     return $dataProvider->fetchAll($dataProvider->getEmptyConfig()->setSorting(array('sorting' => 'ASC'))->setFilter(FilterBuilder::fromArray()->getFilter()->andPropertyValueIn('id', $childIds)->getAllAsArray()));
 }