@param \Netgen\EzPlatformSiteApi\Core\Site\QueryType\CriterionDefinition $definition

@throws \InvalidArgumentException

@return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\DateMetadata
187428
private function buildDateMetadataCreated(CriterionDefinition $definition)
    {
        return new DateMetadata(
            DateMetadata::CREATED,
            $definition->operator,
            $this->resolveTimeValues($definition->value)
        );
    }
681854
protected function loadMapping(FinalizedMapperDefinition $definition) : \Dms\Core\Persistence\Db\Mapping\Hierarchy\ParentObjectMapping
    {
        return new ParentObjectMapping($definition);
    }
1268248
protected function createCriterion()
    {
        $content = $this->fileManager->get(
            __DIR__.'/../stubs/Eloquent/Criteria/Example.php'
        );

        $criterion = $this->argument('criterion');

        $replacements = [
            '%namespaces.repositories%' => $this->config('namespaces.repositories'),
            '%criterion%'               => $criterion,
        ];

        $content = str_replace(array_keys($replacements), array_values($replacements), $content);

        $fileName      = $criterion;
        $fileDirectory = app()->basePath().'/app/'.$this->config('paths.repositories').'Criteria';
        $filePath      = $fileDirectory.'/'.$fileName.'.php';

        if (!$this->fileManager->exists($fileDirectory)) {
            $this->fileManager->makeDirectory($fileDirectory, 0755, true);
        }

        if ($this->laravel->runningInConsole() && $this->fileManager->exists($filePath)) {
            $response = $this->ask("The criterion [{$fileName}] already exists. Do you want to overwrite it?", 'Yes');

            if (!$this->isResponsePositive($response)) {
                $this->line("The criterion [{$fileName}] will not be overwritten.");
                return;
            }

            $this->fileManager->put($filePath, $content);
        } else {
            $this->fileManager->put($filePath, $content);
        }

        $this->line("The criterion [{$fileName}] has been created.");
    }
471948
public function createCriteriaQueryBuilder($criterias, QueryBuilder $query)
    {
        $tag = $criterias['tag'];
        $author = $criterias['author'];
        $date = $criterias['date'];
        $blogId = $criterias['blogId'];

        if (null !== $tag) {
            $query
                ->join('post.tags', 'pt')
                ->andWhere('pt.id = :tagId')
                ->setParameter('tagId', $tag->getId())
            ;
        } elseif (null !== $author) {
            $query
                ->andWhere('post.author = :authorId')
                ->setParameter('authorId', $author->getId())
            ;
        } elseif (null !== $date) {
            $dates = explode('-', $date);
            $startDate = new \DateTime();
            $endDate = new \DateTime();

            $countDateParts = count($dates);
            if (2 === $countDateParts) {
                $startDate
                    ->setDate($dates[1], $dates[0], 1)
                    ->setTime(0, 0);
                $endDate->setTimestamp(strtotime('+1 month', $startDate->getTimestamp()));
            } elseif (2 < $countDateParts) {
                $startDate
                    ->setDate($dates[2], $dates[1], $dates[0])
                    ->setTime(0, 0);
                $endDate->setTimestamp(strtotime('+1 day', $startDate->getTimestamp()));
            } else {
                throw new \InvalidArgumentException('Invalid format for date filter argument');
            }

            $query
                ->andWhere('post.publicationDate >= :startDate')
                ->andWhere('post.publicationDate < :endDate')
                ->setParameter('startDate', $startDate)
                ->setParameter('endDate', $endDate);
        }

        $query
            ->setParameter('blogId', $blogId)
            ->orderBy('post.publicationDate', 'DESC')
        ;

        return $query;
    }
911187
protected function parseDefinition($definition = null)
    {
        if (is_null($definition)) {
            if (!is_null($this->definition)) {
                throw new \InvalidArgumentException(
                    'Cannot parse rule definitions for rule "'. $this->name. '", attrib "'
                    . $this->attrib->getName(). '" without definition!'
                );
            }
            $definition = $this->definition;
            $this->definition = null;
        }

        // required, simple
        if (is_string($definition) || is_callable($definition)) {
            $definition = array('constraint' => $definition);
        }

        // init empty to reduce isset checks..
        $definition = array_merge(self::$DEFAULT_ATTRIBS, $definition);

        // set attribs
        $this->sufficient = $definition['sufficient'];
        $this->skipEmpty  = $definition['skipEmpty'];
        $this->error      = $definition['error'];

        // having old style callable constraint
        if (is_callable($definition['constraint']) && is_array($definition['constraint'])) { // !($definition['constraint'] instanceof \Closure)) {
            $cb = $definition['constraint'];
            $definition['constraint'] = function () use ($cb) {
                $args = func_get_args();
                return call_user_func_array($cb, $args);
            };
        }

        // from string -> check predefined
        elseif (is_string($definition['constraint'])) {
            $args = preg_split('/:/', $definition['constraint']);
            $method = 'rule'. array_shift($args);
            $found = false;
            foreach ($this->dataFilter->getPredefinedRuleClasses() as $className) {
                if (is_callable(array($className, $method)) && method_exists($className, $method)) {
                    $definition['constraint'] = call_user_func_array(array($className, $method), $args);
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                throw new \InvalidArgumentException(
                    'Could not use constraint "'. $definition['constraint']. '" for rule "'
                    . $this->name. '", attrib "'. $this->attrib->getName(). '" because no '
                    . 'predefined rule class found implementing "'. $method. '()"'
                );
            }
        }

        // determine class
        $constraintClass = is_object($definition['constraint'])
            ? get_class($definition['constraint'])
            : '(Scalar)';

        // at this point: it has to be a closure!
        if ($constraintClass !== 'Closure') {
            throw new \InvalidArgumentException(
                'Definition for rule "'. $this->name. '", attrib "'. $this->attrib->getName(). '"'
                . ' has an invalid constraint of class '. $constraintClass
            );
        }
        $this->constraint = $definition['constraint'];
    }
39863
private function isTrivialInstance(Definition $definition)
    {
        if ($definition->isSynthetic() || $definition->getFile() || $definition->getMethodCalls() || $definition->getProperties() || $definition->getConfigurator()) {
            return false;
        }
        if ($definition->isDeprecated() || $definition->isLazy() || $definition->getFactory() || 3 < count($definition->getArguments())) {
            return false;
        }

        foreach ($definition->getArguments() as $arg) {
            if (!$arg || $arg instanceof Parameter) {
                continue;
            }
            if (is_array($arg) && 3 >= count($arg)) {
                foreach ($arg as $k => $v) {
                    if ($this->dumpValue($k) !== $this->dumpValue($k, false)) {
                        return false;
                    }
                    if (!$v || $v instanceof Parameter) {
                        continue;
                    }
                    if ($v instanceof Reference && $this->container->has($id = (string) $v) && $this->container->findDefinition($id)->isSynthetic()) {
                        continue;
                    }
                    if (!is_scalar($v) || $this->dumpValue($v) !== $this->dumpValue($v, false)) {
                        return false;
                    }
                }
            } elseif ($arg instanceof Reference && $this->container->has($id = (string) $arg) && $this->container->findDefinition($id)->isSynthetic()) {
                continue;
            } elseif (!is_scalar($arg) || $this->dumpValue($arg) !== $this->dumpValue($arg, false)) {
                return false;
            }
        }

        if (false !== strpos($this->dumpLiteralClass($this->dumpValue($definition->getClass())), '$')) {
            return false;
        }

        return true;
    }
343627
protected function getTotalCount(Criterion $criterion, array $languageFilter)
    {
        $query = $this->handler->createSelectQuery();
        $query
            ->select($query->alias($query->expr->count('*'), 'count'))
            ->from($this->handler->quoteTable('ezcontentobject_tree'))
            ->innerJoin(
                'ezcontentobject',
                'ezcontentobject_tree.contentobject_id',
                'ezcontentobject.id'
            )
            ->innerJoin(
                'ezcontentobject_version',
                'ezcontentobject.id',
                'ezcontentobject_version.contentobject_id'
            );

        $query->where(
            $this->criteriaConverter->convertCriteria($query, $criterion, $languageFilter),
            $query->expr->eq(
                'ezcontentobject.status',
                //ContentInfo::STATUS_PUBLISHED
                $query->bindValue(1, null, PDO::PARAM_INT)
            ),
            $query->expr->eq(
                'ezcontentobject_version.status',
                //VersionInfo::STATUS_PUBLISHED
                $query->bindValue(1, null, PDO::PARAM_INT)
            ),
            $query->expr->neq(
                $this->handler->quoteColumn('depth', 'ezcontentobject_tree'),
                $query->bindValue(0, null, PDO::PARAM_INT)
            )
        );

        // If not main-languages query
        if (!empty($languageFilter['languages'])) {
            $query->where(
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->handler->quoteColumn('language_mask', 'ezcontentobject'),
                        $query->bindValue(
                            $this->getLanguageMask($languageFilter),
                            null,
                            PDO::PARAM_INT
                        )
                    ),
                    $query->bindValue(0, null, PDO::PARAM_INT)
                )
            );
        }

        $statement = $query->prepare();
        $statement->execute();

        return (int)$statement->fetchColumn();
    }
99571
public function canVisit(Criterion $criterion)
    {
        return
            $criterion instanceof Criterion\ContentTypeGroupId &&
            (
                ($criterion->operator ?: Operator::IN) === Operator::IN ||
                $criterion->operator === Operator::EQ
            );
    }
403025
protected function validateCriterionInput(Criterion $criterion)
    {
        /** @var $criterion \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalOperator */
        if (!isset($criterion->criteria[0]) || (count($criterion->criteria) > 1)) {
            throw new RuntimeException('Invalid aggregation in LogicalNot criterion.');
        }
    }
931597
public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof \AttributeType\Model\AttributeTypeI18nQuery) {
            return $criteria;
        }
        $query = new \AttributeType\Model\AttributeTypeI18nQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }
338516
public static function create($name, $definition)
    {
        if (preg_match('/^(.*?)KEY\s*\((.*?)\)/', $definition, $matches)) {
            return new self([
                'name' => $name,
                'columns' => preg_split('/\s*,\s*/', $matches[2]),
                'type' => trim($matches[1])
            ]);
        } else {
            throw new \InvalidArgumentException("Invalid index definition '$definition'");
        }
    }
924407
private function buildIsMainLocation(CriterionDefinition $definition)
    {
        if (null === $definition->value) {
            return null;
        }

        $isMainLocation = $definition->value ? IsMainLocation::MAIN : IsMainLocation::NOT_MAIN;

        return new IsMainLocation($isMainLocation);
    }
777573
protected function _resolveDefinition(
        DefinitionInterface $definition, array $parameters = [])
    {
        $entryName = $definition->getName();
        $definitionResolver = $this->_getDefinitionResolver($definition);

        try {
            $value = $definitionResolver->resolve($definition, $parameters);
        } catch (\Exception $exception) {
            throw new DependencyException(
                "An error occurred while resolving " .
                "entry '{$entryName}': " . $exception->getMessage(),
                0,
                $exception
            );
        }

        return $value;
    }
31223
protected function formatDatetime(DateTimeInterface $date, PropDefinition $definition): string
    {
        $timezone = $definition->get('timezone', $this->getDefaultTimezone());
        if ($timezone !== null) {
            $date = $this->convertTimeZone($date, $timezone);
        }

        return $date->format($definition->get('format', $this->getDatetimeFormat()));
    }
366476
public function init(BaseModelCriteria $criteria, DataFetcherInterface $dataFetcher = null)
    {
        $this->dbName = $criteria->getDbName();
        $this->setClass($criteria->getModelName());
        $this->setWith($criteria->getWith());
        $this->asColumns = $criteria->getAsColumns();
        $this->hasLimit = $criteria->getLimit() != -1;
        if ($dataFetcher) {
            $this->setDataFetcher($dataFetcher);
        }

        return $this;
    }
1074585
public function parseMigrationDefinition(MigrationDefinition $definition)
    {
        try {
            $data = json_decode($definition->rawDefinition, true);
        } catch (\Exception $e) {
            return new WorkflowDefinition(
                $definition->name,
                $definition->path,
                $definition->rawDefinition,
                MigrationDefinition::STATUS_INVALID,
                array(),
                $e->getMessage()
            );
        }

        return $this->parseMigrationDefinitionData($data, $definition, 'Json');
    }
1219694
public function canVisit(Criterion $criterion)
    {
        return
            $criterion instanceof Criterion\Field &&
            (
                ($criterion->operator ?: Operator::IN) === Operator::IN ||
                $criterion->operator === Operator::EQ ||
                $criterion->operator === Operator::CONTAINS
            );
    }