40 'subject_guids' => null,
41 'object_guids' => null,
42 'target_guids' => null,
43 'annotation_ids' => null,
45 'action_types' => null,
46 'posted_time_lower' => null,
47 'posted_time_upper' => null,
78 $count_expr = $this->options->distinct ?
"DISTINCT {$qb->getTableAlias()}.id" :
'*';
79 $qb->select(
"COUNT({$count_expr}) AS total");
98 public function calculate($function, $property, $property_type =
'annotation') {
100 throw new DomainException(
"'{$function}' is not a valid numeric function");
106 if (!empty($this->options->annotation_name_value_pairs) && $this->options->annotation_name_value_pairs[0]->names != $property) {
107 $alias =
$qb->getNextJoinAlias();
114 $qb->joinAnnotationTable(
$qb->getTableAlias(),
'annotation_id', null,
'inner', $alias);
115 $qb->select(
"{$function}({$alias}.value) AS calculation");
136 $distinct = $this->options->distinct ?
'DISTINCT ' :
'';
137 $qb->select(
"{$distinct}{$qb->getTableAlias()}.*");
144 $original_order =
elgg_extract(
'order_by', $this->options->__original_options);
145 if (empty($this->options->order_by) && $original_order !==
false) {
146 $qb->addOrderBy(
"{$qb->getTableAlias()}.posted",
'desc');
150 $qb->setMaxResults((
int)
$limit);
151 $qb->setFirstResult((
int) $offset);
154 $callback = $callback ?: $this->options->callback;
155 if (!isset($callback)) {
156 $callback =
function ($row) {
157 return new \ElggRiverItem($row);
164 $preload = array_filter(
$items,
function($e) {
165 return $e instanceof \ElggRiverItem;
185 if ($this->options->annotation_calculation) {
186 $clauses = $this->options->annotation_name_value_pairs;
187 if (
count($clauses) > 1 && $this->options->annotation_name_value_pairs_operator !==
'OR') {
188 throw new LogicException(
'Annotation calculation can not be performed on multiple annotation name value pairs merged with AND');
191 $clause = array_shift($clauses);
193 return $this->
calculate($this->options->annotation_calculation, $clause->names,
'annotation');
194 }
elseif ($this->options->count) {
195 return $this->
count();
196 }
elseif ($this->options->batch) {
197 return $this->
batch($this->options->limit, $this->options->offset, $this->options->callback);
199 return $this->
get($this->options->limit, $this->options->offset, $this->options->callback);
213 foreach ($this->options->joins as $join) {
217 foreach ($this->options->wheres as $where) {
223 $ands[] = $this->
buildPairedAnnotationClause($qb, $this->options->annotation_name_value_pairs, $this->options->annotation_name_value_pairs_operator);
226 $ands = $qb->
merge($ands);
229 $qb->andWhere($ands);
244 $where->ids = $this->options->ids;
245 $where->views = $this->options->views;
246 $where->action_types = $this->options->action_types;
247 $where->subject_guids = $this->options->subject_guids;
248 $where->object_guids = $this->options->object_guids;
249 $where->target_guids = $this->options->target_guids;
250 $where->created_after = $this->options->created_after;
251 $where->created_before = $this->options->created_before;
252 $where->annotation_ids = $this->options->river_annotation_ids;
266 $use_access_clause = !
_elgg_services()->userCapabilities->canBypassPermissionsCheck();
270 if (!empty($this->options->subject_guids) || $use_access_clause) {
271 $qb->joinEntitiesTable(
$qb->getTableAlias(),
'subject_guid',
'inner',
'se');
273 $subject->guids = $this->options->subject_guids;
277 if (!empty($this->options->object_guids) || $use_access_clause || !empty($this->options->type_subtype_pairs)) {
278 $qb->joinEntitiesTable(
$qb->getTableAlias(),
'object_guid',
'inner',
'oe');
280 $object->guids = $this->options->object_guids;
281 $object->type_subtype_pairs = $this->options->type_subtype_pairs;
285 if (!empty($this->options->target_guids) || $use_access_clause) {
287 $qb->joinEntitiesTable(
$qb->getTableAlias(),
'target_guid',
'left',
'te');
289 $target->guids = $this->options->target_guids;
292 $target_ors[] =
$qb->compare(
'te.guid',
'IS NULL');
293 $ands[] =
$qb->merge($target_ors,
'OR');
296 return $qb->merge($ands);
312 foreach ($clauses as $clause) {
319 $parts[] = $clause->prepare($qb, $joined_alias);
322 return $qb->
merge($parts, $boolean);
337 foreach ($clauses as $clause) {
338 $join_on = $clause->join_on ===
'guid' ?
'subject_guid' : $clause->join_on;
345 $parts[] = $clause->prepare($qb, $joined_alias);
348 return $qb->
merge($parts, $boolean);
joinAnnotationTable(string $from_alias= '', string $from_column= 'guid', $name=null,?string $join_type= 'inner', string $joined_alias=null)
Join annotations table from alias and return joined table alias.
batch($limit=null, $offset=null, $callback=null)
Fetch rows as an ElggBatch.
calculate($function, $property, $property_type= 'annotation')
Performs a mathematical calculation on river annotations.
buildEntityClauses($qb)
Add subject, object and target clauses Make sure all three are accessible by the user.
Exception thrown if a value does not adhere to a defined valid data domain.
Database abstraction query builder.
buildQuery(QueryBuilder $qb)
Build a database query.
Builds queries for matching annotations against their properties.
execute()
Execute the query resolving calculation, count and/or batch options.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
buildPairedRelationshipClause(QueryBuilder $qb, $clauses, $boolean= 'AND')
Process relationship pairs.
River repository contains methods for fetching/counting river items.
Abstract methods for interfacing with the database.
Builds queries for matching river items against their properties.
Builds queries for filtering entities by their properties in the entities table.
expandInto(QueryBuilder $qb, $table_alias=null)
Extend query builder with select, group_by, having and order_by clauses from $options.
Exception that represents error in the program logic.
buildPairedAnnotationClause(QueryBuilder $qb, $clauses, $boolean= 'AND')
Process annotation name value pairs Joins the annotation table on entity guid in the entities table a...
joinRelationshipTable(string $from_alias= '', string $from_column= 'guid', $name=null, bool $inverse=false,?string $join_type= 'inner', string $joined_alias=null)
Join relationship table from alias and return joined table alias.
if($email instanceof\Elgg\Email) $object
getTableAlias()
Returns the alias of the primary table.
merge($parts=null, $boolean= 'AND')
Merges multiple composite expressions with a boolean.
buildRiverClause(QueryBuilder $qb)
Process river properties.
static fromTable(string $table, string $alias=null)
Returns a QueryBuilder for selecting data from a given table.
_elgg_services()
Get the global service provider.
static find(array $options=[])
Build and execute a new query from an array of legacy options.
__construct(array $options=[])
{}