Returns a collection containing all Comics which match the given criteria.

@param Api\Client $client   The API Client.
@param array      $criteria The criteria for searching.

@return Api\Collection
164850
final public static function findAll(Api\Client $client, array $criteria = []) : Api\Collection
    {
        $filters = [
            'format' => [
                [
                    'in',
                    [
                        'comic', 'hardcover', 'trade paperback', 'magazine', 'digest',
                        'graphic novel', 'digital comic', 'infinite comic',
                    ]
                ],
            ],
            'formatType' => [['in', ['comic', 'collection']]],
            'noVariants' => [['bool'], ['bool-convert']],
            'dateDescriptor' => [['in', ['lastWeek', 'thisWeek', 'nextWeek', 'thisMonth']]],
            'fromDate' => [['date', true]],
            'toDate' => [['date', true]],
            'hasDigitalIssue' => [['bool'], ['bool-convert']],
            'modifiedSince' => [['date', true], ['date-format', 'c']],
            'creators' => [['ofScalars', [['uint']]], ['implode', ',']],
            'characters' => [['ofScalars', [['uint']]], ['implode', ',']],
            'series' => [['ofScalars', [['uint']]], ['implode', ',']],
            'events' => [['ofScalars', [['uint']]], ['implode', ',']],
            'stories' => [['ofScalars', [['uint']]], ['implode', ',']],
            'sharedAppearances' => [['ofScalars', [['uint']]], ['implode', ',']],
            'collaborators' => [['ofScalars', [['uint']]], ['implode', ',']],
            'orderBy' => [
                [
                    'in',
                    [
                        'focDate', 'onsaleDate', 'title', 'issueNumber', 'modified',
                        '-focDate', '-onsaleDate', '-title', '-issueNumber', '-modified',
                    ],
                ]
            ],

        ];

        list($success, $filteredCriteria, $error) = Api\Filterer::filter($filters, $criteria);
        Util::ensure(true, $success, $error);
        $toDate = Util\Arrays::get($filteredCriteria, 'toDate');
        $fromDate = Util\Arrays::get($filteredCriteria, 'fromDate');
        if ($toDate !== null && $fromDate !== null) {
            unset($filteredCriteria['toDate'], $filteredCriteria['fromDate']);
            $filteredCriteria['dateRange'] = "{$fromDate->format('c')},{$toDate->format('c')}";
        }

        return new Api\Collection($client, self::API_RESOURCE, $filteredCriteria);
    }
996425
public function getFacetsByCriteria(Criteria $criteria)
    {
        $qb = $this->createCriteriaQueryBuilder($criteria, 'm');

        $channelsQb = clone $qb;
        $channels = $channelsQb->select('DISTINCT m.channel')->getQuery()->getScalarResult();

        $typeQb = clone $qb;
        $types = $typeQb->select('DISTINCT m.type')->getQuery()->getScalarResult();

        $priorityQb = clone $qb;
        $priorities = $priorityQb->select('DISTINCT m.priority')->getQuery()->getScalarResult();

        $roleQb = clone $qb;
        $roles = $roleQb->select('DISTINCT m.role')->getQuery()->getScalarResult();

        return [
            'channels' => array_column($channels, 'channel'),
            'types' => array_column($types, 'type'),
            'priorities' => array_column($priorities, 'priority'),
            'roles' => array_column($roles, 'role'),
        ];
    }
85365
public function getFacetsByCriteria(Criteria $criteria)
    {
        $query = new Query();
        $query->setSize(0);

        $filter = $this->createFilterFromCriteria($criteria);

        $priorityFacet = new Facet\Terms('priorities');
        $priorityFacet->setField('priority');
        if ($filter->getFilters()) {
            $priorityFacet->setFilter($filter);
        }
        $query->addFacet($priorityFacet);

        $typeFacet = new Facet\Terms('types');
        $typeFacet->setField('type');
        if ($filter->getFilters()) {
            $typeFacet->setFilter($filter);
        }
        $query->addFacet($typeFacet);

        $channelFacet = new Facet\Terms('channels');
        $channelFacet->setField('channel');
        if ($filter->getFilters()) {
            $channelFacet->setFilter($filter);
        }
        $query->addFacet($channelFacet);

        $roleFacet = new Facet\Terms('roles');
        $roleFacet->setField('role');
        if ($filter->getFilters()) {
            $roleFacet->setFilter($filter);
        }
        $query->addFacet($roleFacet);

        $resultSet = $this->getType()->search($query);
        $facets = $resultSet->getFacets();

        $filterSets = [
            'priorities' => array_column($facets['priorities']['terms'], 'term'),
            'types' => array_column($facets['types']['terms'], 'term'),
            'channels' => array_column($facets['channels']['terms'], 'term'),
            'roles' => array_column($facets['roles']['terms'], 'term'),
        ];

        return $filterSets;
    }
901056
public function searchContentfulEntries(string $searchText, int $offset = 0, int $limit = 25, ?Client $client = null): array
    {
        $client = $client ?? $this->defaultClient;

        $query = new Query();
        $query->setLimit($limit);
        $query->setSkip($offset);
        $query->where('query', $searchText);

        return $this->buildContentfulEntries($client->getEntries($query), $client);
    }
309912
public function grabFromCollection($collection, $criteria = [])
    {
        $collection = $this->driver->getDbh()->selectCollection($collection);
        return $collection->findOne($criteria);
    }
76360
public static function getAllResults(ClientInterface $client, $url)
    {
        $data = [];
        do {
            $response = $client->get($url);
            $data = array_merge($data, $response->json());

            $url = GithubApplication::parseLinkHeader($response)['next'];
        } while ($url);

        return $data;
    }
818123
private function chooseHttpClient(RequestInterface $request)
    {
        foreach ($this->clients as $client) {
            if ($client['matcher']->matches($request)) {
                return $client['client'];
            }
        }

        throw new HttpClientNoMatchException('No client found for the specified request', $request);
    }
1188752
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null, $indexBy = null)
    {
        $this->checkRepository();

        $data = parent::findBy($criteria, $orderBy, $limit, $offset);

        if ($data && $indexBy) {
            $data = $this->sortCollection($data, $indexBy);
        }

        return $data;
    }
1254543
public function findBy(array $criteria = array(), array $orderBy = null, $limit = null, $offset = null)
    {
        return $this->findAll();
    }
343616
public function findOneByClientAndRefreshToken(ApiClientInterface $client, $refreshToken)
    {
        $qb = $this->createQueryBuilder();

        $qb->field('client.id')->equals($client->getId());
        $qb->field('refreshCode')->equals($refreshToken);
        $qb->limit(1);

        return $qb->getQuery()->getSingleResult();
    }
453824
public function getQuery($criteria = [])
    {

        /** @var ElementInterface $elementClass */
        $elementClass = static::elementClass();

        /** @var ElementQueryInterface $query */
        $query = $elementClass::find();

        // Configure it
        QueryHelper::configure(
            $query,
            $criteria
        );

        return $query;
    }
190004
public function getAllIds($collection)
    {
        $params   = [
            self::OPTION_COLLECTION => $this->makeCollection($collection)
        ];
        $response = $this->getConnection()->put(Urls::URL_ALL_KEYS, $this->json_encode_wrapper($params));

        $data = $response->getJson();
        if (!isset($data[Cursor::ENTRY_RESULT])) {
            throw new ClientException('Got an invalid document list from the server');
        }

        $cursor = new Cursor($this->getConnection(), $response->getJson(), ['_documentClass' => $this->_documentClass]);
        $ids    = [];
        foreach ($cursor->getAll() as $location) {
            $ids[] = UrlHelper::getDocumentIdFromLocation($location);
        }

        return $ids;
    }
1274783
public function createQuery(array $criteria = array())
    {
        $class = $this->documentClass.'Query';
        $query = new $class($this);
        $query->criteria($criteria);

        return $query;
    }
400343
public function refresh(Client $client)
    {
        $clientId = $client->getId();
        $this->clients[$clientId] = $client;
        $this->removeClientForRequest($clientId, $client->getPreviousRequest());

        $requestId = $client->getRequest();
        if ($requestId  !== null) {
            if (!isset($this->requests[$requestId])) {
                $this->requests[$requestId] = array();
            }
            $this->requests[$requestId][$clientId] = $client;
            $this->clientRequest[$clientId] = $requestId;
        }

        return $this;
    }
28541
public function getAll(array $criteria = [])
    {
        $query = sprintf('%s/images?per_page=%d', $this->endpoint, 200);

        if (isset($criteria['type']) && in_array($criteria['type'], ['distribution', 'application'])) {
            $query = sprintf('%s&type=%s', $query, $criteria['type']);
        }

        if (isset($criteria['private']) && true === (bool) $criteria['private']) {
            $query = sprintf('%s&private=true', $query);
        }

        $images = $this->adapter->get($query);

        $images = json_decode($images);

        $this->extractMeta($images);

        return array_map(function ($image) {
            return new ImageEntity($image);
        }, $images->images);
    }
342200
public function searchContentfulEntriesCount(string $searchText, ?Client $client = null): int
    {
        $client = $client ?? $this->defaultClient;

        $query = new Query();
        $query->where('query', $searchText);

        return count($client->getEntries($query));
    }
857213
public function matching(Criteria $criteria): array
    {
        $queryBuilder = $this->entityManager->createQueryBuilder()
            ->select('e.id')
            ->from($this->getEntityName(), 'e');

        $queryBuilder->addCriteria($criteria);

        $ids = $queryBuilder->getQuery()->getResult(ColumnHydrator::HYDRATOR_MODE);

        if (count($ids) === 0) {
            return [];
        }

        return $this->findByIds($ids);
    }