/**
* 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;
}