Get documents matching criteria

@return array
18621
protected function getData() {

        $sql = ['SELECT document FROM '.$this->collection->name];

        if ($this->criteria) {

            $sql[] = 'WHERE document_criteria("'.$this->criteria.'", document)';
        }

        if ($this->sort) {

            $orders = [];

            foreach ($this->sort as $field => $direction) {
                $orders[] = 'document_key("'.$field.'", document) '.($direction==-1 ? 'DESC':'ASC');
            }

            $sql[] = 'ORDER BY '.\implode(',', $orders);
        }

        if ($this->limit) {
            $sql[] = 'LIMIT '.$this->limit;

            if ($this->skip) { $sql[] = 'OFFSET '.$this->skip; }
        }

        $sql = implode(' ', $sql);

        $stmt      = $this->collection->database->connection->query($sql);
        $result    = $stmt->fetchAll( \PDO::FETCH_ASSOC);
        $documents = [];

        if (!$this->projection) {

            foreach ($result as &$doc) {
                $documents[] = \json_decode($doc['document'], true);
            }

        } else {

            $exclude = [];
            $include = [];

            foreach ($this->projection as $key => $value) {

                if ($value) {
                    $include[$key] = 1;
                } else {
                    $exclude[$key] = 1;
                }
            }

            foreach ($result as &$doc) {

                $item = \json_decode($doc['document'], true);
                $id   = $item['_id'];

                if ($exclude) {
                    $item = \array_diff_key($item, $exclude);
                }

                if ($include) {
                    $item = array_key_intersect($item, $include);
                }

                if (!isset($exclude['_id'])) {
                    $item['_id'] = $id;
                }

                $documents[] = $item;
            }
        }

        return $documents;
    }
384773
public function getAllProfiles()
    {
        $profiles = [];

        $search = $this->repo->createSearch();
        $filter = new BoolQuery();
        $filter->add(new TermQuery('type', 'experiment'), BoolQuery::MUST_NOT);
        $topHitsAgg = new TopHitsAggregation('documents', 20);
        $termAgg = new TermsAggregation('profiles', 'profile.profile');
        $filterAgg = new FilterAggregation('filter', $filter);
        $termAgg->addAggregation($topHitsAgg);
        $filterAgg->addAggregation($termAgg);
        $search->addAggregation($filterAgg);

        $result = $this->repo->findDocuments($search);

        /** @var Setting $activeProfiles */
        $activeProfiles = $this->getValue($this->activeProfilesSettingName, []);

        /** @var AggregationValue $agg */
        foreach ($result->getAggregation('filter')->getAggregation('profiles') as $agg) {
            $settings = [];
            $docs = $agg->getAggregation('documents');
            foreach ($docs['hits']['hits'] as $doc) {
                $settings[] = $doc['_source']['name'];
            }
            $name = $agg->getValue('key');
            $profiles[] = [
                'active' => $activeProfiles ? in_array($agg->getValue('key'), (array)$activeProfiles) : false,
                'name' => $name,
                'settings' => implode(', ', $settings),
            ];
        }

        return $profiles;
    }
1359020
protected function getMatchers()
    {
        // @todo change to dynamic
        return [
            Matchers\DateMatch::class,
            Matchers\DigitMatch::class,
            Matchers\L33tMatch::class,
            Matchers\RepeatMatch::class,
            Matchers\SequenceMatch::class,
            Matchers\SpatialMatch::class,
            Matchers\YearMatch::class,
            Matchers\DictionaryMatch::class,
        ];
    }
333037
public function search(array $criteria = array())
    {
        $criteria['where'] = isset($criteria['where']) ? $criteria['where'] : '';
        if (isset($this->events[ self::EVENT_ON_BEFORE_SEARCH ])) {
            $this->secureEval($this->events[ self::EVENT_ON_BEFORE_SEARCH ], array(
                'criteria' => &$criteria
            ));
        }

        $results = $this->getDriver()->search($criteria);

        if (isset($this->events[ self::EVENT_ON_AFTER_SEARCH ])) {
            $this->secureEval($this->events[ self::EVENT_ON_AFTER_SEARCH ], array(
                'criteria' => &$criteria,
                'results' => &$results
            ));
        }

        return $results;
    }
1098349
public static function findAllEntitiesByCriteria(array $criteria = [], array $exclude = []): array
    {
        $class = static::class;

        /** @var EntityRepository $obj_collection */
        $obj_collection = new $class();

        foreach ($criteria as $k => $v) {
            $obj_collection->addSimpleWhereField($k, $v);
        }

        foreach ($exclude as $k => $v) {
            $obj_collection->addWhereFieldIsNot($k, $v);
        }

        return $obj_collection->getAsArrayOfObjects();
    }
1176554
public function matchesRequest()
    {
        return Collection::make($this->config->get('matchingData'))->diffAssoc($this->event)->isEmpty();
    }
1311661
public function getValues()
        {
            $values = [];

            foreach ($this->parts as $part) {
                if ($part instanceof Criterion) {
                    if ($part->getValue() !== null) {
                        $values[] = $part->getValue();
                    }
                } else {
                    foreach ($part->getValues() as $value) {
                        if ($value !== null) {
                            $values[] = $value;
                        }
                    }
                }
            }

            return $values;
        }
653724
public function getOrderedProducts(): Collection
    {
        return $this->products->matching(Criteria::create()->orderBy(['order' => Criteria::ASC]));
    }
1222802
private function getQueryForDocument(object $document) : array
    {
        $id = $this->uow->getDocumentIdentifier($document);
        $id = $this->class->getDatabaseIdentifierValue($id);

        $shardKeyQueryPart = $this->getShardKeyQuery($document);
        return array_merge(['_id' => $id], $shardKeyQueryPart);
    }
459717
public function getDocumentTypes()
  {
    $documentTypes = array();

    $this->DocumentType->byOrganization($this->AuthenticationManager->getCurrentUserOrganizationId())->each(function($DocumentType) use (&$documentTypes)
    {
      array_push($documentTypes, array('label'=> $DocumentType->name , 'value'=>$DocumentType->id));
    });

    return $documentTypes;
  }
58771
public function getValues()
        {
            $values = $this->values;

            foreach ($this->criteria as $criteria) {
                foreach ($criteria->getValues() as $value) {
                    if (is_array($value)) {
                        foreach ($value as $single_value) {
                            $values[] = $single_value;
                        }
                    } else {
                        $values[] = $value;
                    }
                }
            }

            return $values;
        }
545797
private function getDocumentClasses()
    {
        /** @var MetadataCollector $metadataCollector */
        $metadataCollector = $this->getContainer()->get('es.metadata_collector');
        $classes = [];

        foreach ($this->getContainer()->getParameter('es.managers') as $manager) {
            $documents = $metadataCollector->getMappings($manager['mappings']);
            foreach ($documents as $document) {
                $classes[] = sprintf('%s:%s', $document['bundle'], $document['class']);
            }
        }

        return $classes;
    }
1084405
protected function getCriteria()
    {
        $result = array();

        if($this->filters){
            $result['filters'] = $this->filters;
        }

        if($this->limit!==null){
            $result['limit'] = $this->limit;
        }

        if($this->order!==null){
            $result['order'] = $this->order;
        }

        if($this->page!==null){
            $result['page'] = $this->page;
        }

        return $result;
    }
284515
public function getDefinedMethods() : Collection
    {
        return collect($this->getMethods())
            ->filter(function ($method) {
                return $method->getFileName() == $this->getFileName();
            });
    }
27909
public function getCriteriaData()
    {
        $criteriaData = [
            'object_list_type' => self::LIST_TYPE_FULL,
        ];

        if (!empty($this->publicationState)) {
            $criteriaData['show_type'] = $this->publicationState;
        }

        if (!empty($this->channels)) {
            $criteriaData['rubric_list'] = implode(',', $this->channels);
        }

        if (!is_null($this->limit)) {
            $criteriaData['videosperpage'] = $this->limit;
        }

        if (!is_null($this->page)) {
            $criteriaData['page'] = $this->page;
        }

        if (!is_null($this->sortColumn)) {
            if ($this->sortColumn == 'views') {
                $criteriaData['sort'] = 2; // Sort by 'most popular'
            } else {
                $criteriaData['sort_by_column'] = $this->sortColumn;

                if (!is_null($this->sortByColumnOrder)) {
                    // Put this here because providing this field doesn't
                    // do anything if you don't provide 'sort_by_column'
                    if (!in_array($this->sortByColumnOrder, array(self::SORT_ORDER_ASC, self::SORT_ORDER_DESC))) {
                        throw new \Exception('Invalid sort order provided.');
                    }

                    $criteriaData['sort_by_column_order'] = $this->sortByColumnOrder;
                }
            }
        }

        if (!is_null($this->searchTerm)) {
            $criteriaData['searchstring'] = $this->searchTerm;
        }

        if (!is_null($this->page)) {
            $criteriaData['page'] = $this->page;
        } elseif (!is_null($this->offset)) {
            if (is_null($this->limit)) {
                throw new \Exception('Criteria \'offset\' can only be used in conjunction with \'limit\'.');
            }

            $criteriaData['page'] = ceil($this->offset / $this->limit) + 1;
        }

        return $criteriaData;
    }
894972
public function matching(Criteria $criteria)
    {
        if ($this->isDirty) {
            $this->initialize();
        }

        if ($this->initialized) {
            return $this->collection->matching($criteria);
        }

        if ($this->association instanceof ManyToManyAssociationMetadata) {
            $persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);

            return new ArrayCollection($persister->loadCriteria($this, $criteria));
        }

        $builder         = Criteria::expr();
        $ownerExpression = $builder->eq($this->backRefFieldName, $this->owner);
        $expression      = $criteria->getWhereExpression();
        $expression      = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression;

        $criteria = clone $criteria;
        $criteria->where($expression);

        $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association->getTargetEntity());

        return $this->association->getFetchMode() === FetchMode::EXTRA_LAZY
            ? new LazyCriteriaCollection($persister, $criteria)
            : new ArrayCollection($persister->loadCriteria($criteria));
    }
559634
public function all()
    {
        $result = [];
        foreach ($this->collection->find() as $document) {
            $result[] = [
                'program' => $document['program'],
                'process' => $document['process'],
            ];
        }
        return $result;
    }