Elgg  Version 4.3
RemoveAdminUserEventHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Notifications;
4 
6 
13 
19  protected function recipientIsChangedUser(\ElggUser $recipient): bool {
20  return $this->event->getObject()->guid === $recipient->guid;
21  }
22 
26  protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
27  if ($this->recipientIsChangedUser($recipient)) {
28  return elgg_echo('admin:notification:remove_admin:user:subject', [elgg_get_site_entity()->getDisplayName()], $recipient->getLanguage());
29  } else {
30  return elgg_echo('admin:notification:remove_admin:admin:subject', [elgg_get_site_entity()->getDisplayName()], $recipient->getLanguage());
31  }
32  }
33 
37  protected function getNotificationBody(\ElggUser $recipient, string $method): string {
38 
39  $actor = $this->event->getActor();
40  if (!$actor instanceof \ElggUser) {
41  return parent::getNotificationBody($recipient, $method);
42  }
43 
45 
46  if ($this->recipientIsChangedUser($recipient)) {
47  return elgg_echo('admin:notification:remove_admin:user:body', [
49  $site->getDisplayName(),
50  $site->getURL(),
51  ], $recipient->getLanguage());
52  } else {
53  $entity = $this->event->getObject();
54 
55  return elgg_echo('admin:notification:remove_admin:admin:body', [
57  $entity->getDisplayName(),
58  $site->getDisplayName(),
59  $entity->getURL(),
60  ], $recipient->getLanguage());
61  }
62  }
63 
67  protected function getNotificationURL(\ElggUser $recipient, string $method): string {
68  if ($this->recipientIsChangedUser($recipient)) {
69  return '';
70  }
71 
72  return elgg_generate_url('admin', ['segments' => 'users/admins']);
73  }
74 
78  protected function addMuteLink(): bool {
79  return false;
80  }
81 
87  public function getSubscriptions(): array {
88  $result = parent::getSubscriptions();
89 
90  /* @var $user \ElggUser */
91  $user = $this->event->getObject();
92 
93  if (_elgg_services()->config->security_notify_user_admin) {
94  // add the user to the subscribers
95  $result[$user->guid] = ['email'];
96  }
97 
98  if (_elgg_services()->config->security_notify_admins) {
99  // add the current site admins to the subscribers
100 
101  $admin_batch = elgg_get_admins([
102  'limit' => false,
103  'wheres' => [
104  function (QueryBuilder $qb, $main_alias) use ($user) {
105  return $qb->compare("{$main_alias}.guid", '!=', $user->guid, ELGG_VALUE_GUID);
106  },
107  ],
108  'batch' => true,
109  ]);
110 
111  foreach ($admin_batch as $admin) {
112  $result[$admin->guid] = ['email'];
113  }
114  }
115 
116  return $result;
117  }
118 
122  public static function isConfigurableByUser(): bool {
123  return false;
124  }
125 }
getLanguage($fallback=null)
Get user language or default to site language.
Definition: ElggUser.php:73
if(($owner instanceof\ElggGroup||$owner instanceof\ElggUser)&&!in_array($owner->guid, $mute_guids)) $actor
Definition: mute.php:86
$admin
Definition: useradd.php:21
getNotificationBody(\ElggUser $recipient, string $method)
const ELGG_VALUE_GUID
Definition: constants.php:128
Database abstraction query builder.
getNotificationSubject(\ElggUser $recipient, string $method)
$site
Definition: icons.php:5
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
elgg_get_admins(array $options=[])
Elgg admin functions.
Definition: admin.php:26
getSubscriptions()
Add the user to the subscribers when changing admin rights.
Notification Event Handler handles preparation of a notification.
Notification Event Handler for &#39;user&#39; &#39;user&#39; &#39;remove_admin&#39; action.
recipientIsChangedUser(\ElggUser $recipient)
Tells if the recipient is the user being changed.
$entity
Definition: reset.php:8
elgg_generate_url($name, array $parameters=[])
Generate a URL for named route.
$user
Definition: ban.php:7
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
elgg_get_site_entity()
Get the current site entity.
Definition: entities.php:99
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
$qb
Definition: queue.php:11
$recipient
Definition: mute.php:8
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:318
getNotificationURL(\ElggUser $recipient, string $method)