26 $this->options =
new QueryOptions($options, \ArrayObject::ARRAY_AS_PROPS);
33 if (!isset($this->options->$name)) {
37 $val = &$this->options->$name;
46 $this->options->$name =
$value;
53 unset($this->options->$name);
60 return isset($this->options->$name);
70 public static function with(array $options = []) {
79 abstract public function count();
90 abstract public function calculate($function, $property, $property_type = null);
101 abstract public function get(
$limit = null,
$offset = null, $callback = null);
110 public static function find(array $options = []) {
111 return static::with($options)->execute();
123 public function batch(
$limit = null, $offset = null, $callback = null) {
124 $options = $this->options->getArrayCopy();
126 $options[
'limit'] = (int)
$limit;
127 $options[
'offset'] = (int) $offset;
128 $options[
'callback'] = $callback;
129 unset($options[
'count'],
131 $options[
'batch_size'],
132 $options[
'batch_inc_offset']
135 $batch_size = $this->options->batch_size;
136 $batch_inc_offset = $this->options->batch_inc_offset;
138 return new \ElggBatch([static::class,
'find'], $options, null, $batch_size, $batch_inc_offset);
146 abstract public function execute();
158 public function filter(\Closure $closure) {
193 public function join($joined_table, $joined_alias = null, $join_column = null, $comparison = null, $values = null,
$type = null, $case_sensitive = null) {
194 $join =
new JoinClause($joined_table, $joined_alias,
function (
QueryBuilder $qb, $joined_alias) use ($join_column, $comparison, $values,
$type, $case_sensitive) {
195 return $qb->
compare(
"{$joined_alias}.{$join_column}", $comparison, $values,
$type, $case_sensitive);
197 $this->options->join($join);
236 public function orderBy($expression, $direction) {
237 $this->options->orderBy(
new OrderByClause($expression, $direction));
251 foreach ($this->options->selects as $select_clause) {
252 $select_clause->prepare($qb, $table_alias);
255 foreach ($this->options->group_by as $group_by_clause) {
256 $group_by_clause->prepare($qb, $table_alias);
259 foreach ($this->options->having as $having_clause) {
260 $having_clause->prepare($qb, $table_alias);
263 if (!empty($this->options->order_by)) {
264 foreach ($this->options->order_by as $order_by_clause) {
265 $order_by_clause->prepare($qb, $table_alias);
batch($limit=null, $offset=null, $callback=null)
Fetch rows as an ElggBatch.
calculate($function, $property, $property_type=null)
Apply numeric calculation to a column.
static find(array $options=[])
Build and execute a new query from an array of legacy options.
if(!$user||!$user->canDelete()) $name
Extends QueryBuilder with JOIN clauses.
Extends QueryBuilder with SELECT clauses.
Database abstraction query builder.
join($joined_table, $joined_alias=null, $join_column=null, $comparison=null, $values=null, $type=null, $case_sensitive=null)
Add JOIN clause Join a database table on an $x to $y comparison.
Extends QueryBuilder with GROUP BY statements.
filter(\Closure $closure)
Filter query prior to execution Callback function will receive QueryBuilder as the first argument and...
Abstract methods for interfacing with the database.
Extends QueryBuilder with HAVING clauses.
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
expandInto(QueryBuilder $qb, $table_alias=null)
Extend query builder with select, group_by, having and order_by clauses from $options.
select($expression)
Add SELECT.
Extends QueryBuilder with ORDER BY clauses.
Builds a clause from closure or composite expression.
groupBy($expression)
Add GROUP BY.
having($expression)
Add HAVING.
orderBy($expression, $direction)
Add ORDER BY.
__construct(array $options=[])
Constructor.
static with(array $options=[])
Constructs a new.
execute()
Apply correct execution method based on calculation, count or other criteria.