Elgg  Version master
notifications.php
Go to the documentation of this file.
1 <?php
6 use Elgg\Values;
7 
8 $guid = (int) get_input('guid');
9 
11 if (!$user instanceof ElggUser || !$user->canEdit()) {
12  return elgg_error_response(elgg_echo('actionunauthorized'));
13 }
14 
16 if (empty($methods)) {
17  return elgg_error_response(elgg_echo('usersettings:notifications:save:fail'));
18 }
19 
20 // notification settings
21 $notification_settings = (array) get_input('notification_setting', []);
22 foreach ($notification_settings as $purpose => $prefered_methods) {
23  if (!is_array($prefered_methods)) {
24  $prefered_methods = [];
25  }
26 
27  foreach ($methods as $method) {
28  $user->setNotificationSetting($method, in_array($method, $prefered_methods), $purpose);
29  }
30 }
31 
32 // delayed email interval
33 if ((bool) elgg_get_config('enable_delayed_email')) {
34  $delayed_email_interval = (string) get_input('delayed_email_interval');
35  if (!empty($delayed_email_interval) && $user->delayed_email_interval !== $delayed_email_interval) {
36  // save new setting
37  $user->delayed_email_interval = $delayed_email_interval;
38 
39  // update all queued notifications to the new interval
40  _elgg_services()->delayedEmailQueueTable->updateRecipientInterval($user->guid, $delayed_email_interval);
41  }
42 }
43 
44 // timed muting
45 $start = (int) get_input('timed_muting_start');
46 $end = (int) get_input('timed_muting_end');
47 if (!empty($start) && !empty($end) && $start <= $end) {
48  // change end to [date 23:59:59] instead of [date 00:00:00]
49  $end_date = Values::normalizeTime($end);
50  $end_date->setTime(23, 59, 59);
51  $end = $end_date->getTimestamp();
52 
53  $user->timed_muting_start = $start;
54  $user->timed_muting_end = $end;
55 } else {
56  unset($user->timed_muting_start);
57  unset($user->timed_muting_end);
58 }
59 
60 return elgg_ok_response('', elgg_echo('usersettings:notifications:save:ok'));
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
if(!$user instanceof ElggUser||!$user->canEdit()) $methods
Saves user notification settings.
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
$guid
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
foreach($notification_settings as $purpose=> $prefered_methods) if((bool) elgg_get_config('enable_delayed_email')) $start
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.
$user
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
$purpose
Definition: record.php:16
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
elgg_get_notification_methods()
Returns registered delivery methods for notifications [ &#39;email&#39; => &#39;email&#39;, &#39;sms&#39; => &#39;sms&#39;...
$end
if(empty($methods)) $notification_settings