/** * Compiles the Builder instance into an LDAP query string. * * @param \Adldap\Query\Builder $builder * * @return string */ public function compileQuery(Builder $builder) { // Retrieve the query 'where' bindings. $wheres = $builder->getWheres(); // Retrieve the query 'orWhere' bindings. $orWheres = $builder->getOrWheres(); // Retrieve the query filter bindings. $filters = $builder->getFilters(); // We'll combine all raw filters together first. $query = implode(null, $filters); // Compile wheres. $query = $this->compileWheres($wheres, $query); // Compile or wheres. $query = $this->compileOrWheres($orWheres, $query); // Count the total amount of filters. $total = count($wheres) + count($filters); // Make sure we wrap the query in an 'and' if using // multiple filters. We also need to check if only // one where is used with multiple orWheres, that // we wrap it in an `and` query. if ($total > 1 || count($wheres) === 1 && count($orWheres) > 0) { $query = $this->compileAnd($query); } return $query; }
/** * Compiles the Builder instance into an LDAP query string. * * @param \Adldap\Query\Builder $builder * * @return string */ public function compileQuery(Builder $builder) { $query = implode(null, $builder->getFilters()); $query = $this->compileWheres($builder, $query); $query = $this->compileOrWheres($builder, $query); // Count the total amount of filters. $total = count($builder->getWheres()) + count($builder->getOrWheres()) + count($builder->getFilters()); // Make sure we wrap the query in an 'and' // if using multiple filters. if ($total > 1) { $query = $this->compileAnd($query); } return $query; }