5 use Doctrine\DBAL\Query\Expression\CompositeExpression;
 
   40             'subject_guids' => 
null,
 
   41             'object_guids' => 
null,
 
   42             'target_guids' => 
null,
 
   43             'annotation_ids' => 
null,
 
   45             'action_types' => 
null,
 
   46             'created_after' => 
null,
 
   47             'created_before' => 
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();
 
  109             $annotation = AnnotationWhereClause::factory([
'names' => $property]);
 
  113         $qb->joinAnnotationTable(
$qb->getTableAlias(), 
'annotation_id', 
null, 
'inner', $alias);
 
  114         $qb->select(
"{$function}({$alias}.value) AS calculation");
 
  135         $distinct = $this->options->distinct ? 
'DISTINCT ' : 
'';
 
  136         $qb->select(
"{$distinct}{$qb->getTableAlias()}.*");
 
  143         $original_order = 
elgg_extract(
'order_by', $this->options->__original_options);
 
  144         if (empty($this->options->order_by) && $original_order !== 
false) {
 
  145             $qb->addOrderBy(
"{$qb->getTableAlias()}.posted", 
'desc');
 
  153         $callback = $callback ?: $this->options->callback;
 
  154         if (!isset($callback)) {
 
  155             $callback = 
function ($row) {
 
  156                 return new \ElggRiverItem($row);
 
  163             $preload = array_filter(
$items, 
function($e) {
 
  164                 return $e instanceof \ElggRiverItem;
 
  184         if ($this->options->annotation_calculation) {
 
  185             $clauses = $this->options->annotation_name_value_pairs;
 
  186             if (
count($clauses) > 1 && $this->options->annotation_name_value_pairs_operator !== 
'OR') {
 
  187                 throw new LogicException(
'Annotation calculation can not be performed on multiple annotation name value pairs merged with AND');
 
  190             $clause = array_shift($clauses);
 
  192             return $this->
calculate($this->options->annotation_calculation, $clause->names, 
'annotation');
 
  193         } 
elseif ($this->options->count) {
 
  194             return $this->
count();
 
  195         } 
elseif ($this->options->batch) {
 
  196             return $this->
batch($this->options->limit, $this->options->offset, $this->options->callback);
 
  198             return $this->
get($this->options->limit, $this->options->offset, $this->options->callback);
 
  212         foreach ($this->options->joins as $join) {
 
  213             $join->prepare(
$qb, 
$qb->getTableAlias());
 
  216         foreach ($this->options->wheres as $where) {
 
  217             $ands[] = $where->prepare(
$qb, 
$qb->getTableAlias());
 
  222         $ands[] = $this->
buildPairedAnnotationClause($qb, $this->options->annotation_name_value_pairs, $this->options->annotation_name_value_pairs_operator);
 
  225         $ands = 
$qb->merge($ands);
 
  228             $qb->andWhere($ands);
 
  243         $where->ids = $this->options->ids;
 
  244         $where->views = $this->options->views;
 
  245         $where->action_types = $this->options->action_types;
 
  246         $where->subject_guids = $this->options->subject_guids;
 
  247         $where->object_guids = $this->options->object_guids;
 
  248         $where->target_guids = $this->options->target_guids;
 
  249         $where->created_after = $this->options->created_after;
 
  250         $where->created_before = $this->options->created_before;
 
  251         $where->annotation_ids = $this->options->river_annotation_ids;
 
  253         return $where->prepare(
$qb, 
$qb->getTableAlias());
 
  265         $use_access_clause = !
_elgg_services()->userCapabilities->canBypassPermissionsCheck();
 
  269         if (!empty($this->options->subject_guids) || $use_access_clause) {
 
  270             $qb->joinEntitiesTable(
$qb->getTableAlias(), 
'subject_guid', 
'inner', 
'se');
 
  272             $subject->guids = $this->options->subject_guids;
 
  276         if (!empty($this->options->object_guids) || $use_access_clause || !empty($this->options->type_subtype_pairs)) {
 
  277             $qb->joinEntitiesTable(
$qb->getTableAlias(), 
'object_guid', 
'inner', 
'oe');
 
  279             $object->guids = $this->options->object_guids;
 
  280             $object->type_subtype_pairs = $this->options->type_subtype_pairs;
 
  284         if (!empty($this->options->target_guids) || $use_access_clause) {
 
  286             $qb->joinEntitiesTable(
$qb->getTableAlias(), 
'target_guid', 
'left', 
'te');
 
  288             $target->guids = $this->options->target_guids;
 
  291             $target_ors[] = 
$qb->compare(
'te.guid', 
'IS NULL');
 
  292             $ands[] = 
$qb->merge($target_ors, 
'OR');
 
  295         return $qb->merge($ands);
 
  311         foreach ($clauses as $clause) {
 
  312             if (strtoupper($boolean) === 
'OR' || 
count($clauses) === 1) {
 
  313                 $joined_alias = 
$qb->joinAnnotationTable(
$qb->getTableAlias(), 
'annotation_id');
 
  315                 $joined_alias = 
$qb->joinAnnotationTable(
$qb->getTableAlias(), 
'annotation_id', $clause->names);
 
  318             $parts[] = $clause->prepare(
$qb, $joined_alias);
 
  321         return $qb->merge($parts, $boolean);
 
  336         foreach ($clauses as $clause) {
 
  337             $join_on = $clause->join_on === 
'guid' ? 
'subject_guid' : $clause->join_on;
 
  338             if (strtoupper($boolean) === 
'OR' || 
count($clauses) === 1) {
 
  341                 $joined_alias = 
$qb->joinRelationshipTable(
$qb->getTableAlias(), $join_on, $clause->names, $clause->inverse);
 
  344             $parts[] = $clause->prepare(
$qb, $joined_alias);
 
  347         return $qb->merge($parts, $boolean);
 
Builds queries for matching annotations against their properties.
Builds queries for filtering entities by their properties in the entities table.
Builds clauses for filtering entities by their properties in entity_relationships table.
Builds queries for matching river items against their properties.
Database abstraction query builder.
Abstract methods for interfacing with the database.
expandInto(QueryBuilder $qb, $table_alias=null)
Extend query builder with select, group_by, having and order_by clauses from $options.
batch($limit=null, $offset=null, $callback=null)
Fetch rows as an ElggBatch.
River repository contains methods for fetching/counting river items.
buildEntityClauses($qb)
Add subject, object and target clauses Make sure all three are accessible by the user.
buildQuery(QueryBuilder $qb)
Build a database query.
buildRiverClause(QueryBuilder $qb)
Process river properties.
calculate($function, $property, $property_type='annotation')
Performs a mathematical calculation on river annotations.
buildPairedAnnotationClause(QueryBuilder $qb, $clauses, $boolean='AND')
Process annotation name value pairs Joins the annotation table on entity guid in the entities table a...
__construct(array $options=[])
{Constructor.ege* options}
static find(array $options=[])
Build and execute a new query from an array of legacy options.
execute()
Execute the query resolving calculation, count and/or batch options.
buildPairedRelationshipClause(QueryBuilder $qb, $clauses, $boolean='AND')
Process relationship pairs.
static fromTable(string $table, ?string $alias=null)
Returns a QueryBuilder for selecting data from a given table.
Exception thrown if a value does not adhere to a defined valid data domain.
Exception that represents error in the program logic.
if($email instanceof \Elgg\Email) $object
$subject
HTML body of an email.
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
_elgg_services()
Get the global service provider.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.