47 if (empty($action_type)) {
85 'subtype' =>
$object->getSubtype(),
86 'action_type' => $action_type,
87 'access_id' => $access_id,
89 'subject_guid' => $subject_guid,
90 'object_guid' => $object_guid,
91 'target_guid' => $target_guid,
92 'annotation_id' => $annotation_id,
97 'subtype' =>
'string',
98 'action_type' =>
'string',
101 'subject_guid' =>
'int',
102 'object_guid' =>
'int',
103 'target_guid' =>
'int',
104 'annotation_id' =>
'int',
110 if ($values ==
false) {
118 $sql_columns[] =
$name;
119 $sql_values[] =
":$name";
123 INSERT INTO {$dbprefix}river (" . implode(
',', $sql_columns) .
") 124 VALUES (" . implode(
',', $sql_values) .
") 133 $object->updateLastAction($values[
'posted']);
145 return $return_item ? $river_items[0] :
$id;
209 'relationship' => null,
210 'relationship_guid' => null,
211 'inverse_relationship' =>
false,
226 'batch_inc_offset' =>
true,
229 'order_by' =>
'rv.posted desc',
237 $msg = __FUNCTION__ .
' does not support the "views" option, though you may specify values for' 238 .
' the "rv.view" column using the "wheres" option.';
245 $batch_size =
$options[
'batch_size'];
246 $batch_inc_offset =
$options[
'batch_inc_offset'];
251 return new \ElggBatch(
'elgg_get_river',
$options, null, $batch_size, $batch_inc_offset);
254 $singulars = array(
'id',
'subject_guid',
'object_guid',
'target_guid',
'annotation_id',
'action_type',
'type',
'subtype');
268 if (
$options[
'posted_time_lower'] && is_int(
$options[
'posted_time_lower'])) {
269 $wheres[] =
"rv.posted >= {$options['posted_time_lower']}";
272 if (
$options[
'posted_time_upper'] && is_int(
$options[
'posted_time_upper'])) {
273 $wheres[] =
"rv.posted <= {$options['posted_time_upper']}";
277 $wheres[] =
"rv.enabled = 'yes'";
284 $joins[] =
"JOIN {$dbprefix}entities oe ON rv.object_guid = oe.guid";
287 $joins[] =
"LEFT JOIN {$dbprefix}entities te ON rv.target_guid = te.guid";
289 if (
$options[
'relationship_guid']) {
296 $wheres = array_merge($wheres, $clauses[
'wheres']);
297 $joins = array_merge($joins, $clauses[
'joins']);
302 $joins = array_merge($joins,
$options[
'joins']);
306 foreach ($wheres as $i => $where) {
307 if ($where ===
false) {
309 } elseif (empty($where)) {
315 $wheres = array_unique($wheres);
318 $distinct =
$options[
'distinct'] ?
"DISTINCT" :
"";
320 $query =
"SELECT $distinct rv.* FROM {$CONFIG->dbprefix}river rv ";
323 $count_expr =
$options[
'distinct'] ?
"DISTINCT rv.id" :
"*";
325 $query =
"SELECT COUNT($count_expr) as total FROM {$CONFIG->dbprefix}river rv ";
329 foreach ($joins as $j) {
336 foreach ($wheres as $w) {
337 $query .=
" $w AND ";
347 $query .=
"$object_access_where AND ($target_access_where OR te.guid IS NULL) ";
352 $query .=
" GROUP BY {$options['group_by']}";
356 $query .=
" ORDER BY {$options['order_by']}";
361 $query .=
" LIMIT $offset, $limit";
364 $river_items =
get_data($query,
'_elgg_row_to_elgg_river_item');
370 return (
int)$total->total;
383 foreach ($river_items as
$item) {
384 if ($item->subject_guid && !
_elgg_services()->entityCache->get($item->subject_guid)) {
385 $guids[$item->subject_guid] =
true;
387 if ($item->object_guid && !
_elgg_services()->entityCache->get($item->object_guid)) {
388 $guids[$item->object_guid] =
true;
390 if ($item->target_guid && !
_elgg_services()->entityCache->get($item->target_guid)) {
391 $guids[$item->target_guid] =
true;
399 'guids' => array_keys(
$guids),
407 foreach ($river_items as $item) {
408 $object = $item->getObjectEntity();
416 'guids' => array_keys(
$guids),
445 'offset' => (
int) max(
get_input(
'offset', 0), 0),
447 'pagination' =>
true,
448 'list_class' =>
'elgg-list-river',
464 $count_needed =
true;
466 $count_needed =
false;
468 $count_needed =
false;
469 } elseif ((
$options[
'count'] < (
int)
$options[
'limit']) && !$options[
'offset']) {
470 $count_needed =
false;
474 $options[
'count'] =
true;
499 return new \ElggRiverItem(
$row);
524 $types_wheres = array();
525 $subtypes_wheres = array();
528 if (!is_array($pairs)) {
530 if (!is_array($types)) {
531 $types = array($types);
533 foreach ($types as
$type) {
535 $types_wheres[] =
"({$table}.type = '$type')";
545 $subtypes_wheres[] =
"({$table}.subtype = '$subtype')";
549 if (is_array($types_wheres) && count($types_wheres)) {
550 $types_wheres = array(implode(
' OR ', $types_wheres));
553 if (is_array($subtypes_wheres) && count($subtypes_wheres)) {
554 $subtypes_wheres = array(
'(' . implode(
' OR ', $subtypes_wheres) .
')');
557 $wheres = array(implode(
' AND ', array_merge($types_wheres, $subtypes_wheres)));
561 foreach ($pairs as $paired_type => $paired_subtypes) {
563 if (is_array($paired_subtypes)) {
564 $paired_subtypes = array_map(
'sanitise_string', $paired_subtypes);
565 $paired_subtype_str = implode(
"','", $paired_subtypes);
566 if ($paired_subtype_str) {
567 $wheres[] =
"({$table}.type = '$paired_type'" 568 .
" AND {$table}.subtype IN ('$paired_subtype_str'))";
572 $wheres[] =
"({$table}.type = '$paired_type'" 573 .
" AND {$table}.subtype = '$paired_subtype')";
578 if (is_array($wheres) && count($wheres)) {
579 $where = implode(
' OR ', $wheres);
600 if (!is_array($types)) {
602 return "(rv.action_type = '$types')";
606 $types_sanitized = array();
607 foreach ($types as
$type) {
611 $type_str = implode(
"','", $types_sanitized);
612 return "(rv.action_type IN ('$type_str'))";
629 if (!is_array($views)) {
631 return "(rv.view = '$views')";
635 $views_sanitized = array();
636 foreach ($views as
$view) {
640 $view_str = implode(
"','", $views_sanitized);
641 return "(rv.view IN ('$view_str'))";
656 UPDATE {$dbprefix}river 657 SET access_id = :access_id 658 WHERE object_guid = :object_guid 662 ':access_id' => (int) $access_id,
663 ':object_guid' => (
int) $object_guid,
689 $vars[
'subject_username'] = $page_username;
704 $value[] = $CONFIG->path .
'engine/tests/ElggCoreRiverAPITest.php';
726 SET rv.enabled =
'no' 727 WHERE (rv.subject_guid = {$entity->guid} OR rv.object_guid = {$entity->guid} OR rv.target_guid = {$entity->guid});
753 LEFT JOIN {
$dbprefix}entities AS se ON se.guid = rv.subject_guid
754 LEFT JOIN {
$dbprefix}entities AS oe ON oe.guid = rv.object_guid
755 LEFT JOIN {
$dbprefix}entities AS te ON te.guid = rv.target_guid
756 SET rv.enabled =
'yes' 758 (se.enabled =
'yes' OR se.guid IS NULL) AND
759 (oe.enabled =
'yes' OR oe.guid IS NULL) AND
760 (te.enabled =
'yes' OR te.guid IS NULL)
762 AND (se.guid = {$entity->guid} OR oe.guid = {$entity->guid} OR te.guid = {$entity->guid});
775 $item = new \ElggMenuItem(
'activity',
elgg_echo(
'activity'),
'activity');
792 $events->registerHandler(
'init',
'system',
'_elgg_river_init');
793 $events->registerHandler(
'disable:after',
'all',
'_elgg_river_disable', 600);
794 $events->registerHandler(
'enable:after',
'all',
'_elgg_river_enable', 600);
insert_data($query, array $params=[])
Insert a row into the database.
elgg_list_river(array $options=array())
List river items.
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
$object
These two snippets demonstrates triggering an event and how to register for that event.
_elgg_river_get_action_where_sql($types)
Get the where clause based on river action type strings.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
_elgg_river_init()
Initialize river library private.
_elgg_river_page_handler($segments)
Page handler for activity.
if($guid==elgg_get_logged_in_user_guid()) $name
_elgg_river_get_view_where_sql($views)
Get the where clause based on river view strings.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
elgg_view_resource($name, array $vars=[])
Render a resource view.
_elgg_river_test($hook, $type, $value)
Register river unit tests private.
_elgg_get_guid_based_where_sql($column, $guids)
Returns SQL where clause for owner and containers.
_elgg_prefetch_river_entities(array $river_items)
Prefetch entities that will be displayed in the river.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
if(empty($vars['value'])&&$vars['value']!==0 &&$vars['value']!== '0') $query_params
Elgg single tag output.
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
update_river_access_by_object($object_guid, $access_id)
Sets the access ID on river items for a particular object.
$options
Main activity stream list page.
elgg_gatekeeper()
Used at the top of a page to mark it as logged in users only.
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an and optionally for type and subtype.
get_data_row($query, $callback=null, array $params=[])
Retrieve a single row from the database.
elgg_get_annotation_from_id($id)
Get a specific annotation by its id.
elgg_create_river_item(array $options=array())
Adds an item to the river.
_elgg_row_to_elgg_river_item($row)
Convert a database row to a new .
update_data($query, array $params=[], $get_num_rows=false)
Update a row in the database.
elgg_set_ignore_access($ignore=true)
Set if Elgg's access system should be ignored.
sanitise_string($string)
Alias of sanitize_string.
const ELGG_ENTITIES_ANY_VALUE
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
elgg_get_entity_relationship_where_sql($column, $relationship=null, $relationship_guid=null, $inverse_relationship=false)
Returns SQL appropriate for relationship joins and wheres.
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
elgg global
Pointer to the global context.
get_data($query, $callback=null, array $params=[])
Retrieve rows from the database.
elgg_extend_view($view, $view_extension, $priority=501)
Extends a view with another view.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
access_get_show_hidden_status()
Return current status of showing disabled entities.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
_elgg_river_enable($event, $type, $entity)
Enable river entries that reference a re-enabled entity as subject/object/target. ...
elgg_log($message, $level= 'NOTICE')
Display or log a message.
elgg_ok_response($content= '', $message= '', $forward_url=null, $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
_elgg_river_disable($event, $type, $entity)
Disable river entries that reference a disabled entity as subject/object/target.
elgg_get_river(array $options=array())
Get river items.
elgg_register_menu_item($menu_name, $menu_item)
Register an item for an Elgg menu.
sanitise_int($int, $signed=true)
Alias of sanitize_int.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
elgg_register_action($action, $filename="", $access= 'logged_in')
Registers an action.
_elgg_normalize_plural_options_array($options, $singulars)
Normalise the singular keys in an options array to plural keys.
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
elgg_trigger_event($event, $object_type, $object=null)
if(!$collection_name) $id
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
_elgg_get_river_type_subtype_where_sql($table, $types, $subtypes, $pairs)
Returns SQL where clause for type and subtype on river table.
get_entity($guid)
Loads and returns an entity object from a guid.
elgg_register_rss_link()
Include the RSS icon link and link element in the head.