Bolt\Storage\Query\SelectQuery::getWhereExpression PHP Method

getWhereExpression() public method

Creates a composite expression that adds all the attached filters individual expressions into a combined one.
public getWhereExpression ( ) : CompositeExpression
return Doctrine\DBAL\Query\Expression\CompositeExpression
    public function getWhereExpression()
    {
        if (!count($this->filters)) {
            return null;
        }
        $expr = $this->qb->expr()->andX();
        foreach ($this->filters as $filter) {
            $expr = $expr->add($filter->getExpression());
        }
        return $expr;
    }

Usage Example

Example #1
0
 public function testQuery()
 {
     $app = $this->getApp();
     $filters = ['username' => '%fred%', 'email' => '%fred', 'status' => 'published'];
     $query = new SelectQuery($app['storage']->createQueryBuilder(), $app['query.parser.handler']);
     $query->setContentType('pages');
     $query->setParameters($filters);
     $expr = $query->getWhereExpression();
     $this->assertEquals('(pages.username LIKE :username_1) AND (pages.email LIKE :email_1) AND (pages.status = :status_1)', $expr->__toString());
     $this->assertEquals(['%fred%', '%fred', 'published'], array_values($query->getWhereParameters()));
 }