Elgg  Version 5.1
subscriptions.php
Go to the documentation of this file.
1 <?php
6 $guid = (int) get_input('guid');
8 
9 if (!$user || !$user->canEdit()) {
10  return elgg_error_response(elgg_echo('actionunauthorized'));
11 }
12 
14 if (empty($methods)) {
15  return elgg_error_response(elgg_echo('usersettings:notifications:subscriptions:save:fail'));
16 }
17 
18 $subscriptions = (array) get_input('subscriptions', []);
19 if (empty($subscriptions)) {
20  return elgg_error_response(elgg_echo('error:missing_data'));
21 }
22 
24  'guids' => array_keys($subscriptions),
25  'limit' => false,
26  'batch' => true,
27 ]);
28 
29 /* @var $target \ElggEntity */
30 foreach ($targets as $target) {
31  $keys = $subscriptions[$target->guid];
32 
33  foreach ($keys as $key => $preferred_methods) {
34  list (, $type, $subtype, $action) = array_pad(explode(':', $key), 4, null); // array_pad() is to prevent PHP notice undefined index in list()
35 
36  if (!is_array($preferred_methods)) {
37  $preferred_methods = [];
38  }
39 
40  foreach ($methods as $method) {
41  if (in_array($method, $preferred_methods)) {
42  $target->addSubscription($user->guid, $method, $type, $subtype, $action);
43  } else {
44  $target->removeSubscription($user->guid, $method, $type, $subtype, $action);
45  }
46  }
47  }
48 }
49 
50 return elgg_ok_response('', elgg_echo('usersettings:notifications:subscriptions:save:ok'));
if(!$comment instanceof\ElggComment||!$comment->canEdit()) $target
Definition: edit.php:15
elgg_ok_response($content= '', string|array $message= '', string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$type
Definition: delete.php:22
$user
$keys
Definition: access.php:31
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_error_response(string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:504
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
$guid
Saves subscription record notification settings.
$preferred_methods
Definition: record.php:28
$action
Definition: subscribe.php:11
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
$subtype
Definition: delete.php:23
if(empty($subscriptions)) $targets
elgg_get_notification_methods()
Returns registered delivery methods for notifications [ &#39;email&#39; => &#39;email&#39;, &#39;sms&#39; => &#39;sms&#39;...
if(empty($methods)) $subscriptions
if(!$user||!$user->canEdit()) $methods