Elgg  Version master
river.php
Go to the documentation of this file.
1 <?php
8 
29  $item = new \ElggRiverItem();
30  $item->action_type = elgg_extract('action_type', $options);
31  $item->view = elgg_extract('view', $options);
32  $item->subject_guid = elgg_extract('subject_guid', $options, elgg_get_logged_in_user_guid());
33  $item->object_guid = elgg_extract('object_guid', $options);
34  $item->target_guid = elgg_extract('target_guid', $options);
35  $item->annotation_id = elgg_extract('annotation_id', $options);
36  $item->posted = elgg_extract('posted', $options);
37 
38  if (!$item->save()) {
39  return null;
40  }
41 
42  return $item;
43 }
44 
101 function elgg_get_river(array $options = []) {
102  return \Elgg\Database\River::find($options);
103 }
104 
113  return _elgg_services()->riverTable->get($id);
114 }
115 
135 function elgg_delete_river(array $options = []): bool {
136 
137  $required = [
138  'id', 'ids',
139  'subject_guid', 'subject_guids',
140  'object_guid', 'object_guids',
141  'target_guid', 'target_guids',
142  'annotation_id', 'annotation_ids',
143  'view', 'views',
144  ];
145 
146  $found = false;
147  foreach ($required as $key) {
148  // check that it exists and is something.
149  if (isset($options[$key]) && !elgg_is_empty($options[$key])) {
150  $found = true;
151  break;
152  }
153  }
154 
155  if (!$found) {
156  // requirements not met
157  throw new ElggInvalidArgumentException(__METHOD__ . ' requires at least one of the following keys in $options: ' . implode(', ', $required));
158  }
159 
160  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($options) {
161  $options['batch'] = true;
162  $options['batch_size'] = 25;
163  $options['batch_inc_offset'] = false;
164 
165  $river = elgg_get_river($options);
166  $count = $river->count();
167 
168  if (!$count) {
169  return true;
170  }
171 
172  $success = 0;
173  foreach ($river as $river_item) {
174  if ($river_item->delete()) {
175  $success++;
176  }
177  }
178 
179  return $success === $count;
180  });
181 }
182 
194 function elgg_list_river(array $options = []): string {
195  $defaults = [
196  'offset' => (int) max(get_input('offset', 0), 0),
197  'limit' => (int) max(get_input('limit', max(20, _elgg_services()->config->default_limit)), 0),
198  'pagination' => true,
199  'list_class' => 'elgg-list-river',
200  ];
201 
202  $options = array_merge($defaults, $options);
203 
204  $options['register_rss_link'] = elgg_extract('register_rss_link', $options, elgg_extract('pagination', $options));
205  if ($options['register_rss_link']) {
207  }
208 
209  if (!$options['limit'] && !$options['offset']) {
210  // no need for pagination if listing is unlimited
211  $options['pagination'] = false;
212  }
213 
214  $options['count'] = false;
216  $options['count'] = is_array($items) ? count($items) : 0;
217 
218  if (!empty($items)) {
219  $count_needed = true;
220  if (!$options['pagination']) {
221  $count_needed = false;
222  } elseif (!$options['offset'] && !$options['limit']) {
223  $count_needed = false;
224  } elseif (($options['count'] < (int) $options['limit']) && !$options['offset']) {
225  $count_needed = false;
226  }
227 
228  if ($count_needed) {
229  $options['count'] = true;
230 
231  $options['count'] = (int) elgg_get_river($options);
232  }
233  }
234 
235  $options['items'] = $items;
236 
237  return elgg_view('page/components/list', $options);
238 }
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:304
$defaults
Generic entity header upload helper.
Definition: header.php:6
elgg_delete_river(array $options=[])
Delete river items based on $options.
Definition: river.php:135
elgg_create_river_item(array $options=[])
Elgg river.
Definition: river.php:28
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:176
$items
Definition: delete.php:8
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:121
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
elgg_get_river(array $options=[])
Get river items.
Definition: river.php:101
$count
Definition: ban.php:24
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
$required
Definition: label.php:12
elgg_get_river_item_from_id(int $id)
Get river item from its ID.
Definition: river.php:112
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
elgg_list_river(array $options=[])
List river items.
Definition: river.php:194
$id
Generic annotation delete action.
Definition: delete.php:6
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:1272