Returns entity collection with all entities.
public findAll ( ) : Nextras\Orm\Collection\ICollection | ||
Результат | Nextras\Orm\Collection\ICollection |
protected function createComponentPagination() : Ytnuk\Orm\Pagination\Control { if (!$this->repository) { $this->error(); } return new Ytnuk\Orm\Pagination\Control($this->repository->findAll(), self::ITEMS_PER_PAGE); }
protected function fetchByTwoPassStrategy(SqlBuilder $builder, array $values) { $builder = clone $builder; $targetPrimaryKey = $this->targetMapper->getStorageReflection()->getStoragePrimaryKey(); $isComposite = count($targetPrimaryKey) !== 1; foreach (array_unique(array_merge($targetPrimaryKey, [$this->joinStorageKey])) as $key) { $builder->addSelect($key); } $sqls = $args = []; foreach ($values as $primaryValue) { $builderPart = clone $builder; $builderPart->addWhere($this->joinStorageKey, $primaryValue); $sqls[] = $builderPart->buildSelectQuery(); $args = array_merge($args, $builderPart->getParameters()); } $query = '(' . implode(') UNION ALL (', $sqls) . ')'; $result = $this->context->queryArgs($query, $args); $map = $ids = []; if ($isComposite) { foreach ($result->fetchAll() as $row) { $id = []; foreach ($targetPrimaryKey as $key) { $id[] = $row->{$key}; } $ids[] = $id; $map[$row->{$this->joinStorageKey}][] = implode(',', $id); } } else { $targetPrimaryKey = $targetPrimaryKey[0]; foreach ($result->fetchAll() as $row) { $ids[] = $row->{$targetPrimaryKey}; $map[$row->{$this->joinStorageKey}][] = $row->{$targetPrimaryKey}; } } if (count($ids) === 0) { return new EntityIterator([]); } if ($isComposite) { $collectionMapper = $this->targetRepository->findAll()->getCollectionMapper(); if (!$collectionMapper instanceof CollectionMapper) { throw new InvalidStateException(); } $builder = $collectionMapper->getSqlBuilder(); $builder->addWhere($targetPrimaryKey, $ids); $collectionMapper = new SqlBuilderCollectionMapper($this->targetRepository, $this->context, $builder); $entitiesResult = []; foreach ($collectionMapper->getIterator() as $entity) { $entitiesResult[implode(',', $entity->getValue('id'))] = $entity; } } else { $entitiesResult = $this->targetRepository->findBy([$targetPrimaryKey => $ids])->fetchPairs($targetPrimaryKey, NULL); } $entities = []; foreach ($map as $joiningStorageKey => $primaryValues) { foreach ($primaryValues as $primaryValue) { $entity = $entitiesResult[$primaryValue]; $entities[$entity->getForeignKey($this->metadata->relationshipProperty)][] = $entity; } } return new EntityIterator($entities); }