Retrieve cache data generator.

@param SearchCriteriaInterface $searchCriteria

@throws InvalidCacheKeyException

@return void
977410
private function getCacheItemGenerator(SearchCriteriaInterface $searchCriteria)
    {
        try {
            foreach ($searchCriteria->getIdList() as $item) {
                $cacheKey = $this->keyGenerator->generate($item, $searchCriteria);

                yield $item => $this->cacheItemPool->getItem($cacheKey);
            }
        } catch (PsrCacheInvalidArgumentException $e) {
            throw new InvalidCacheKeyException($e->getMessage(), $e->getCode(), $e);
        }
    }
1325605
protected function getLeftComparison(SearchCriterion $searchCriterion)
    {
        switch ($searchCriterion->getComparison()) {
            case SearchCriterion::GREATER_EQUAL:
            case SearchCriterion::GREATER_THAN:
                return $searchCriterion->getValue();
            case SearchCriterion::ISNULL:
            case SearchCriterion::ISNOTNULL:
            case SearchCriterion::LESS_EQUAL:
            case SearchCriterion::LESS_THAN:
                return '*';
            default:
                throw new InvalidArgumentException('Invalid comparison for RangeCriterion');
        }
    }
582097
protected function fetchCache($criteria)
    {
        $ser = serialize($criteria);

        if (isset($this->cache[$ser])) {
            return $this->cache[$ser];
        }
    }
582552
protected <O> CriteriaQuery<O> createCriteriaQuery(Class<O> clazz)
	{
		return getCriteriaBuilder().createQuery(clazz);
	}
1141624
public function save(WritableCriteriaInterface $criteria, $dataOrObject)
    {
        $isObject = is_object($dataOrObject);
        $hydrator = $this->getHydrator();

        if ($isObject) {

            // Check if the object is valid for this model
            $objectPrototype = $this->getObjectPrototype();
            if (!$dataOrObject instanceof $objectPrototype) {
                throw new Exception\InvalidArgumentException(sprintf(
                    '$dataOrObject with type "%s" is not valid for this model, expected an instance of "%s"',
                    get_class($dataOrObject),
                    get_class($objectPrototype)
                ));
            }

            // Inject the model
            if ($dataOrObject instanceof ModelAwareInterface) {
                $dataOrObject->setModel($this);
            }

            // Use the object hydrator as fallback if a model hydrator is not available
            if (!$hydrator && ($dataOrObject instanceof HydratorAwareInterface)) {
                $hydrator = $dataOrObject->getHydrator();
            }

            // Extract data
            if ($hydrator) {
                $data = $hydrator->extract($dataOrObject);
            } elseif (method_exists($dataOrObject, 'toArray')) {
                $data = $dataOrObject->toArray();
            } elseif (method_exists($dataOrObject, 'getArrayCopy')) {
                $data = $dataOrObject->getArrayCopy();
            }
        } elseif (is_array($dataOrObject)) {

            // If an hydrator was provided, we can still use it
            // to convert each array member
            if ($hydrator) {
                if (!method_exists($hydrator, 'extractName') || !method_exists($hydrator, 'extractValue')) {
                    throw new Exception\RuntimeException(
                        'Hydrator must have extractName() and extractValue() methods ' .
                        'in order to extract a single value'
                    );
                }
                $data = [];
                $context = (object) $dataOrObject;
                foreach ($dataOrObject as $key => $value) {
                    $data[
                        $hydrator->extractName($key, $context)
                    ] = $hydrator->extractValue($key, $value, $context);
                }
            } else {
                $data = $dataOrObject;
            }
        }

        if (!isset($data)) {
            throw new Exception\InvalidArgumentException(sprintf(
                '$dataOrObject with type "%s" cannot be casted to an array',
                $isObject ? get_class($dataOrObject) : gettype($dataOrObject)
            ));
        }

        $result = $criteria->applyWrite($this, $data);

        if (!is_integer($result)) {
            $result = null;
        }

        // Make sure data and original data are in sync after save
        if ($result && $hydrator && $isObject) {
            $hydrator->hydrate($data, $dataOrObject);
        }

        return $result;
    }
166249
public function addNamedCriteria(string $name, CriteriaInterface $criteria): NamedCriteriaCollectionInterface
    {
        return $this->addNamedItem($name, $criteria);
    }
705717
private function createCriteriaQueryBuilder(Criteria $criteria, $prefix)
    {
        $qb = $this->createQueryBuilder($prefix);

        if ($criteria->count()) {
            $composite = $this->applyCriteriaToQueryBuilder($criteria, $qb, $prefix);

            if ($composite->count()) {
                $qb->where($composite);
            }
        }

        return $qb;
    }
1030570
public function find($searchCriteria = false, $returnArray = false)
    {
        $result = array();

        if (is_int($searchCriteria)) {
            $primaryKeyValueForSearch = intval($searchCriteria);
            $result = $this->_db_adapter->getOneResult($this->_table_name, array($this->_primary_key => $primaryKeyValueForSearch));
        } else if (is_array($searchCriteria) && !empty($searchCriteria)) {
            $limit = isset($searchCriteria['limit']) ? $searchCriteria['limit'] : 0;
            unset($searchCriteria['limit']);
            $result = $this->_db_adapter->Select($this->_table_name, $searchCriteria, $limit);
        } else if(empty($searchCriteria) || !$searchCriteria) {
            $result = $this->_db_adapter->Select($this->_table_name);
        }

        if($returnArray) {
            return $result;
        }

        return $this->convertSearchResultIntoBean($result);
    }
879139
protected final <T> TypedQuery<T> createCachedQuery(CriteriaQuery<T> criteriaQuery) {
        final TypedQuery<T> query = this.getEntityManager().createQuery(criteriaQuery);
        final String cacheRegion = getCacheRegionName(criteriaQuery);
        query.setHint("org.hibernate.cacheable", true);
        query.setHint("org.hibernate.cacheRegion", cacheRegion);
        return query;
    }
399006
public function search(string $identifier, string $searchQuery): array
    {
        if (in_array($identifier, [static::SEARCH_NAME, static::SEARCH_IMDB, static::SEARCH_ZAP2IT]) === false) {
            throw new InvalidArgumentException('Given search identifier is invalid!');
        }
        $options = ['query' => [$identifier => $searchQuery]];

        $json = $this->parent->performAPICallWithJsonResponse('get', '/search/series', $options);
        return DataParser::parseDataArray($json, BasicSeries::class);
    }
446807
public function getList(SearchCriteriaInterface $searchCriteria)
    {
        /** @var \Limesharp\Stockists\Api\Data\StockistSearchResultsInterface $searchResults */
        $searchResults = $this->searchResultsFactory->create();
        $searchResults->setSearchCriteria($searchCriteria);

        /** @var \Limesharp\Stockists\Model\ResourceModel\Stores\Collection $collection */
        $collection = $this->stockistCollectionFactory->create();

        //Add filters from root filter group to the collection
        /** @var FilterGroup $group */
        foreach ($searchCriteria->getFilterGroups() as $group) {
            $this->addFilterGroupToCollection($group, $collection);
        }
        $sortOrders = $searchCriteria->getSortOrders();
        /** @var SortOrder $sortOrder */
        if ($sortOrders) {
            foreach ($searchCriteria->getSortOrders() as $sortOrder) {
                $field = $sortOrder->getField();
                $collection->addOrder(
                    $field,
                    ($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC'
                );
            }
        } else {
            // set a default sorting order since this method is used constantly in many
            // different blocks
            $field = 'stockist_id';
            $collection->addOrder($field, 'ASC');
        }
        $collection->setCurPage($searchCriteria->getCurrentPage());
        $collection->setPageSize($searchCriteria->getPageSize());

        /** @var \Limesharp\Stockists\Api\Data\StockistInterface[] $stockists */
        $stockists = [];
        /** @var \Limesharp\Stockists\Model\Stores $stockist */
        foreach ($collection as $stockist) {
            /** @var \Limesharp\Stockists\Api\Data\StockistInterface $stockistDataObject */
            $stockistDataObject = $this->stockistInterfaceFactory->create();
            $this->dataObjectHelper->populateWithArray($stockistDataObject, $stockist->getData(), StockistInterface::class);
            $stockists[] = $stockistDataObject;
        }
        $searchResults->setTotalCount($collection->getSize());
        return $searchResults->setItems($stockists);
    }
1125754
public function save(SearchCriteriaInterface $searchCriteria, array $data) : bool
    {
        // before save event
        $eventBeforeName = 'beforeSave';
        if ($this->hasObserver($eventBeforeName)) {
            $eventBefore = $this->eventBuilder
                ->setName($eventBeforeName)
                ->setSearchCriteria($searchCriteria)
                ->setArgumentList([$data])
                ->build();

            $this->notify($eventBefore);
        }

        // execute operation
        $result = $this->cacheManager->save($searchCriteria, $data);

        // after save event
        $eventAfterName = 'afterSave';
        if ($this->hasObserver($eventAfterName)) {
            $eventAfter = $this->eventBuilder
                ->setName($eventAfterName)
                ->setSearchCriteria($searchCriteria)
                ->setArgumentList([$data])
                ->setOperationResult($result)
                ->build();

            $this->notify($eventAfter);
        }

        return $result;
    }
721392
public function search_courses($searchcriteria) {
        global $CFG;
        $content = '';
        if (!empty($searchcriteria)) {
            // print search results

            $displayoptions = array('sort' => array('displayname' => 1));
            // take the current page and number of results per page from query
            $perpage = optional_param('perpage', 0, PARAM_RAW);
            if ($perpage !== 'all') {
                $displayoptions['limit'] = ((int)$perpage <= 0) ? $CFG->coursesperpage : (int)$perpage;
                $page = optional_param('page', 0, PARAM_INT);
                $displayoptions['offset'] = $displayoptions['limit'] * $page;
            }
            // options 'paginationurl' and 'paginationallowall' are only used in method coursecat_courses()
            $displayoptions['paginationurl'] = new moodle_url('/course/search.php', $searchcriteria);
            $displayoptions['paginationallowall'] = true; // allow adding link 'View all'

            $class = 'course-search-result';
            foreach ($searchcriteria as $key => $value) {
                if (!empty($value)) {
                    $class .= ' course-search-result-'. $key;
                }
            }
            $chelper = new coursecat_helper();
            $chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT)->
                    set_courses_display_options($displayoptions)->
                    set_search_criteria($searchcriteria)->
                    set_attributes(array('class' => $class));

            $courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options());
            $totalcount = core_course_category::search_courses_count($searchcriteria);
            $courseslist = $this->coursecat_courses($chelper, $courses, $totalcount);

            if (!$totalcount) {
                if (!empty($searchcriteria['search'])) {
                    $content .= $this->heading(get_string('nocoursesfound', '', $searchcriteria['search']));
                } else {
                    $content .= $this->heading(get_string('novalidcourses'));
                }
            } else {
                $content .= $this->heading(get_string('searchresults'). ": $totalcount");
                $content .= $courseslist;
            }

            if (!empty($searchcriteria['search'])) {
                // print search form only if there was a search by search string, otherwise it is confusing
                $content .= $this->box_start('generalbox mdl-align');
                $content .= $this->course_search_form($searchcriteria['search']);
                $content .= $this->box_end();
            }
        } else {
            // just print search form
            $content .= $this->box_start('generalbox mdl-align');
            $content .= $this->course_search_form();
            $content .= $this->box_end();
        }
        return $content;
    }
1174829
public static function query( ezpContentCriteria $criteria )
    {
        $fetchParams = self::translateFetchParams( $criteria );
        $nodes = eZContentObjectTreeNode::subTreeByNodeID( $fetchParams->params, $fetchParams->rootNodeId );
        $return = array();
        foreach( $nodes as $node )
        {
            $return[] = ezpContent::fromNode( $node );
        }
        return $return;
    }
150206
private function applyCriteriaToQueryBuilder(array $criteria, QueryBuilder $qb)
    {
        foreach ($criteria as $key => $value) {
            if (in_array($key, ['treeId', 'teaserId', 'eid', 'version'])) {
                $qb->andWhere($qb->expr()->eq("h.$key", $value));
            } elseif (in_array($key, ['language', 'action'])) {
                $qb->andWhere($qb->expr()->eq("h.$key", $qb->expr()->literal($value)));
            } elseif (in_array($key, ['comment'])) {
                $qb->andWhere($qb->expr()->like("h.$key", $qb->expr()->literal("%$value%")));
            } else {
                throw new InvalidArgumentException("Unkown field $key");
            }
        }
    }
691430
protected function extendsBuildModelCriteria(ModelCriteria $search = null)
    {
        if (null === $search) {
            return null;
        }

        $eventName = $this->getDispatchEventName(TheliaEvents::LOOP_EXTENDS_BUILD_MODEL_CRITERIA);
        if (null !== $eventName) {
            $this->dispatcher->dispatch(
                $eventName,
                new LoopExtendsBuildModelCriteriaEvent($this, $search)
            );
        }

        return $search;
    }
896661
protected function _getFindOrCreateQuery($search)
    {
        if (is_callable($search)) {
            $query = $this->find();
            $search($query);
        } elseif (is_array($search)) {
            $query = $this->find()->where($search);
        } elseif ($search instanceof Query) {
            $query = $search;
        } else {
            throw new InvalidArgumentException('Search criteria must be an array, callable or Query');
        }

        return $query;
    }