eZ\Publish\Core\Persistence\Doctrine\DoctrineExpression::searchedCase PHP Method

searchedCase() public method

Accepts an arbitrary number of parameters. The first parameter (array) must always be specified, the last parameter (string) specifies the ELSE result. Example: $q = $dbHandler->createSelectQuery(); $q->select( $q->expr->searchedCase( array( $q->expr->gte( 'column1', 20 ), 'column1' ) , array( $q->expr->gte( 'column2', 50 ), 'column2' ) , 'column3' ) ) ->from( 'table' );
public searchedCase ( ) : string
return string
    public function searchedCase()
    {
        $args = func_get_args();
        if (count($args) === 0) {
            throw new QueryException('Expected at least one parameter in searchedCase()');
        }
        $expr = ' CASE';
        foreach ($args as $arg) {
            if (is_array($arg) && count($arg) == 2) {
                $column1 = $arg[0];
                $column2 = $arg[1];
                $expr .= " WHEN {$column1} THEN {$column2}";
            } elseif (is_scalar($arg)) {
                $column = $arg;
                $expr .= " ELSE {$column}";
            }
        }
        $expr .= ' END ';
        return $expr;
    }