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 = []) {
112 return static::with($options)->execute();
127 public function batch(
$limit = null, $offset = null, $callback = null) {
128 $options = $this->options->getArrayCopy();
130 $options[
'limit'] = (int)
$limit;
131 $options[
'offset'] = (int) $offset;
132 $options[
'callback'] = $callback;
133 unset($options[
'count'],
135 $options[
'batch_size'],
136 $options[
'batch_inc_offset']
139 $batch_size = $this->options->batch_size;
140 $batch_inc_offset = $this->options->batch_inc_offset;
142 return new \ElggBatch([static::class,
'find'], $options, null, $batch_size, $batch_inc_offset);
150 abstract public function execute();
197 public function join($joined_table, $joined_alias = null, $x = null, $comparison = null, $y = null,
$type = null, $case_sensitive = null) {
198 $join =
new JoinClause($joined_table, $joined_alias,
function (
QueryBuilder $qb, $joined_alias) use ($x, $comparison, $y,
$type, $case_sensitive) {
199 return $qb->
compare(
"$joined_alias.$x", $comparison, $y,
$type, $case_sensitive);
201 $this->options->join($join);
240 public function orderBy($expression, $direction) {
241 $this->options->orderBy(
new OrderByClause($expression, $direction));
255 foreach ($this->options->selects as $select_clause) {
256 $select_clause->prepare($qb, $table_alias);
259 foreach ($this->options->group_by as $group_by_clause) {
260 $group_by_clause->prepare($qb, $table_alias);
263 foreach ($this->options->having as $having_clause) {
264 $having_clause->prepare($qb, $table_alias);
267 if (!empty($this->options->order_by)) {
268 foreach ($this->options->order_by as $order_by_clause) {
269 $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.
Extends QueryBuilder with GROUP BY statements.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
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.
join($joined_table, $joined_alias=null, $x=null, $comparison=null, $y=null, $type=null, $case_sensitive=null)
Add JOIN clause Join a database table on an $x to $y comparison.
expandInto(QueryBuilder $qb, $table_alias=null)
Extend query builder with select, group_by, having and order_by clauses from $options.
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
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.