Elgg  Version 4.3
river.php
Go to the documentation of this file.
1 <?php
27 function elgg_create_river_item(array $options = []) {
28  $item = new \ElggRiverItem();
29  $item->action_type = elgg_extract('action_type', $options);
30  $item->view = elgg_extract('view', $options);
31  $item->subject_guid = elgg_extract('subject_guid', $options, elgg_get_logged_in_user_guid());
32  $item->object_guid = elgg_extract('object_guid', $options);
33  $item->target_guid = elgg_extract('target_guid', $options);
34  $item->annotation_id = elgg_extract('annotation_id', $options);
35  $item->posted = elgg_extract('posted', $options);
36 
37  if (!$item->save()) {
38  return false;
39  }
40 
41  return (bool) elgg_extract('return_item', $options, false) ? $item : $item->id;
42 }
43 
100 function elgg_get_river(array $options = []) {
101  return \Elgg\Database\River::find($options);
102 }
103 
112  return _elgg_services()->riverTable->get($id) ?? false;
113 }
114 
133 function elgg_delete_river(array $options = []) {
134 
135  $required = [
136  'id', 'ids',
137  'subject_guid', 'subject_guids',
138  'object_guid', 'object_guids',
139  'target_guid', 'target_guids',
140  'annotation_id', 'annotation_ids',
141  'view', 'views',
142  ];
143 
144  $found = false;
145  foreach ($required as $key) {
146  // check that it exists and is something.
147  if (isset($options[$key]) && !elgg_is_empty($options[$key])) {
148  $found = true;
149  break;
150  }
151  }
152 
153  if (!$found) {
154  return false;
155  }
156 
157  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($options) {
158  $options['batch'] = true;
159  $options['batch_size'] = 25;
160  $options['batch_inc_offset'] = false;
161 
162  $river = elgg_get_river($options);
163  $count = $river->count();
164 
165  if (!$count) {
166  return;
167  }
168 
169  $success = 0;
170  foreach ($river as $river_item) {
171  if ($river_item->delete()) {
172  $success++;
173  }
174  }
175 
176  return $success == $count;
177  });
178 }
179 
191 function elgg_list_river(array $options = []) {
192  $defaults = [
193  'offset' => (int) max(get_input('offset', 0), 0),
194  'limit' => (int) max(get_input('limit', max(20, _elgg_services()->config->default_limit)), 0),
195  'pagination' => true,
196  'list_class' => 'elgg-list-river',
197  ];
198 
199  $options = array_merge($defaults, $options);
200 
201  $options['register_rss_link'] = elgg_extract('register_rss_link', $options, elgg_extract('pagination', $options));
202  if ($options['register_rss_link']) {
204  }
205 
206  if (!$options["limit"] && !$options["offset"]) {
207  // no need for pagination if listing is unlimited
208  $options["pagination"] = false;
209  }
210 
211  $options['count'] = false;
213  $options['count'] = is_array($items) ? count($items) : 0;
214 
215  if (!empty($items)) {
216  $count_needed = true;
217  if (!$options['pagination']) {
218  $count_needed = false;
219  } elseif (!$options['offset'] && !$options['limit']) {
220  $count_needed = false;
221  } elseif (($options['count'] < (int) $options['limit']) && !$options['offset']) {
222  $count_needed = false;
223  }
224 
225  if ($count_needed) {
226  $options['count'] = true;
227 
228  $options['count'] = (int) elgg_get_river($options);
229  }
230  }
231 
232  $options['items'] = $items;
233 
234  return elgg_view('page/components/list', $options);
235 }
if(!$items) $item
Definition: delete.php:13
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:592
$defaults
elgg_delete_river(array $options=[])
Delete river items based on $options.
Definition: river.php:133
elgg_create_river_item(array $options=[])
Elgg river.
Definition: river.php:27
$options
Elgg admin footer.
Definition: footer.php:6
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:179
$items
Definition: delete.php:8
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:146
get_input($variable, $default=null, $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_get_river(array $options=[])
Get river items.
Definition: river.php:100
$count
Definition: ban.php:24
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:547
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
$required
Definition: label.php:12
elgg_get_river_item_from_id(int $id)
Get river item from its ID.
Definition: river.php:111
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
elgg_list_river(array $options=[])
List river items.
Definition: river.php:191
$id
Generic annotation delete action.
Definition: delete.php:6
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:179
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:34
elgg_register_rss_link()
Include the RSS icon link and link element in the head.
Definition: views.php:1326