convertCriteria() public method

Converts the criteria into query fragments.
public convertCriteria ( string $fieldTypeIdentifier, eZ\Publish\Core\Persistence\Database\SelectQuery $query, eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion, string $column ) : eZ\Publish\Core\Persistence\Database\Expression
$fieldTypeIdentifier string
$query eZ\Publish\Core\Persistence\Database\SelectQuery
$criterion eZ\Publish\API\Repository\Values\Content\Query\Criterion
$column string
return eZ\Publish\Core\Persistence\Database\Expression
Example #1
0
    /**
     * Generate query expression for a Criterion this handler accepts
     *
     * accept() must be called before calling this method.
     *
     * @throws \eZ\Publish\API\Repository\Exceptions\NotImplementedException If no searchable fields are found for the given criterion target.
     *
     * @param \eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter $converter
     * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query
     * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
     *
     * @return \eZ\Publish\Core\Persistence\Database\Expression
     */
    public function handle( CriteriaConverter $converter, SelectQuery $query, Criterion $criterion )
    {
        $fieldsInformation = $this->getFieldsInformation( $criterion->target );

        $subSelect = $query->subSelect();
        $subSelect->select(
            $this->dbHandler->quoteColumn( 'contentobject_id' )
        )->from(
            $this->dbHandler->quoteTable( 'ezcontentobject_attribute' )
        );

        $whereExpressions = array();
        foreach ( $fieldsInformation as $fieldTypeIdentifier => $fieldsInfo )
        {
            if ( $fieldsInfo['column'] === false )
            {
                throw new NotImplementedException(
                    "A field of type '{$fieldTypeIdentifier}' is not searchable in the legacy search engine."
                );
            }

            $filter = $this->fieldValueConverter->convertCriteria(
                $fieldTypeIdentifier,
                $subSelect,
                $criterion,
                $fieldsInfo['column']
            );

            $whereExpressions[] = $subSelect->expr->lAnd(
                $subSelect->expr->in(
                    $this->dbHandler->quoteColumn( 'contentclassattribute_id' ),
                    $fieldsInfo['ids']
                ),
                $filter
            );
        }

        $subSelect->where(
            $subSelect->expr->lAnd(
                $subSelect->expr->eq(
                    $this->dbHandler->quoteColumn( 'version', 'ezcontentobject_attribute' ),
                    $this->dbHandler->quoteColumn( 'current_version', 'ezcontentobject' )
                ),
                // Join conditions with a logical OR if several conditions exist
                count( $whereExpressions ) > 1 ? $subSelect->expr->lOr( $whereExpressions ) : $whereExpressions[0]
            )
        );

        return $query->expr->in(
            $this->dbHandler->quoteColumn( 'id', 'ezcontentobject' ),
            $subSelect
        );
    }