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 rv.id" :
"*";
79 $qb->select(
"COUNT({$count_expr}) AS total");
102 public function calculate($function, $property, $property_type =
'annotation') {
111 if (!empty($this->options->annotation_name_value_pairs) && $this->options->annotation_name_value_pairs[0]->names != $property) {
112 $alias =
$qb->getNextJoinAlias();
119 $qb->join(
'rv',
'annotations', $alias,
"rv.annotation_id = $alias.id");
120 $qb->select(
"{$function}(n_table.value) AS calculation");
130 return (
int)
$result->calculation;
146 $distinct = $this->options->distinct ?
"DISTINCT" :
"";
147 $qb->select(
"$distinct rv.*");
154 $original_order =
elgg_extract(
'order_by', $this->options->__original_options);
155 if (empty($original_order) && $original_order !==
false) {
156 $qb->addOrderBy(
'rv.posted',
'desc');
161 $qb->setFirstResult((
int) $offset);
164 $callback = $callback ? : $this->options->callback;
165 if (!isset($callback)) {
166 $callback =
function ($row) {
167 return new \ElggRiverItem($row);
174 $preload = array_filter(
$items,
function($e) {
175 return $e instanceof \ElggRiverItem;
196 if ($this->options->annotation_calculation) {
197 $clauses = $this->options->annotation_name_value_pairs;
198 if (
count($clauses) > 1 && $this->options->annotation_name_value_pairs_operator !==
'OR') {
199 throw new LogicException(
"Annotation calculation can not be performed on multiple annotation name value pairs merged with AND");
202 $clause = array_shift($clauses);
204 return $this->
calculate($this->options->annotation_calculation, $clause->names,
'annotation');
205 }
else if ($this->options->count) {
206 return $this->
count();
207 }
else if ($this->options->batch) {
208 return $this->
batch($this->options->limit, $this->options->offset, $this->options->callback);
210 return $this->
get($this->options->limit, $this->options->offset, $this->options->callback);
225 foreach ($this->options->joins as $join) {
226 $join->prepare($qb,
'rv');
229 foreach ($this->options->wheres as $where) {
230 $ands[] = $where->prepare($qb,
'rv');
235 $ands[] = $this->
buildPairedAnnotationClause($qb, $this->options->annotation_name_value_pairs, $this->options->annotation_name_value_pairs_operator);
238 $ands = $qb->
merge($ands);
241 $qb->andWhere($ands);
256 $where->ids = $this->options->ids;
257 $where->views = $this->options->views;
258 $where->action_types = $this->options->action_types;
259 $where->subject_guids = $this->options->subject_guids;
260 $where->object_guids = $this->options->object_guids;
261 $where->target_guids = $this->options->target_guids;
262 $where->created_after = $this->options->created_after;
263 $where->created_before = $this->options->created_before;
264 $where->annotation_ids = $this->options->river_annotation_ids;
266 return $where->prepare($qb,
'rv');
279 $use_access_clause = !
_elgg_services()->userCapabilities->canBypassPermissionsCheck();
283 if (!empty($this->options->subject_guids) || $use_access_clause) {
284 $qb->joinEntitiesTable(
'rv',
'subject_guid',
'inner',
'se');
286 $subject->guids = $this->options->subject_guids;
290 if (!empty($this->options->object_guids) || $use_access_clause || !empty($this->options->type_subtype_pairs)) {
291 $qb->joinEntitiesTable(
'rv',
'object_guid',
'inner',
'oe');
293 $object->guids = $this->options->object_guids;
294 $object->type_subtype_pairs = $this->options->type_subtype_pairs;
298 if (!empty($this->options->target_guids) || $use_access_clause) {
300 $qb->joinEntitiesTable(
'rv',
'target_guid',
'left',
'te');
302 $target->guids = $this->options->target_guids;
305 $target_ors[] =
$qb->compare(
'te.guid',
'IS NULL');
306 $ands[] =
$qb->merge($target_ors,
'OR');
309 return $qb->merge($ands);
325 foreach ($clauses as $clause) {
327 $joined_alias =
'n_table';
331 $joins = $qb->getQueryPart(
'join');
333 if (!empty($joins[
'rv'])) {
334 foreach ($joins[
'rv'] as $join) {
335 if ($join[
'joinAlias'] === $joined_alias) {
342 $qb->
join(
'rv',
'annotations', $joined_alias,
"$joined_alias.id = rv.annotation_id");
345 $parts[] = $clause->prepare($qb, $joined_alias);
348 return $qb->
merge($parts, $boolean);
363 foreach ($clauses as $clause) {
364 $join_on = $clause->join_on ===
'guid' ?
'subject_guid' : $clause->join_on;
370 $parts[] = $clause->prepare($qb, $joined_alias);
373 return $qb->
merge($parts, $boolean);
Exception thrown if an argument is not of the expected type.
batch($limit=null, $offset=null, $callback=null)
{Fetch rows as an ElggBatch.Number of rows to fetch Index of the first row Callback function to run d...
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.
Database abstraction query builder.
buildQuery(QueryBuilder $qb)
Build a database query.
if($pagination &&($position== 'after'||$position== 'both')) $limit
Builds queries for matching annotations against their properties.
execute()
Execute the query resolving calculation, count and/or batch options.
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.
join($fromAlias, $join, $alias, $condition=null)
{}
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...
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
getNextJoinAlias()
Get an index of the next available join alias.
static fromTable($table, $alias=null)
{}
if($email instanceof\Elgg\Email) $object
merge($parts=null, $boolean= 'AND')
Merges multiple composite expressions with a boolean.
buildRiverClause(QueryBuilder $qb)
Process river properties.
_elgg_services()
Get the global service provider.
joinRelationshipTable($from_alias= '', $from_column= 'guid', $name=null, $inverse=false, $join_type= 'inner', $joined_alias=null)
Join relationship table from alias and return joined table alias.
static find(array $options=[])
Build and execute a new query from an array of legacy options.
__construct(array $options=[])
{}