Elgg  Version master
RemoveAdminUserEventHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Notifications;
4 
6 
13 
21  protected function recipientIsChangedUser(\ElggUser $recipient): bool {
22  return $this->event->getObject()->guid === $recipient->guid;
23  }
24 
28  protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
29  if ($this->recipientIsChangedUser($recipient)) {
30  return elgg_echo('admin:notification:remove_admin:user:subject', [elgg_get_site_entity()->getDisplayName()], $recipient->getLanguage());
31  } else {
32  return elgg_echo('admin:notification:remove_admin:admin:subject', [elgg_get_site_entity()->getDisplayName()], $recipient->getLanguage());
33  }
34  }
35 
39  protected function getNotificationBody(\ElggUser $recipient, string $method): string {
40 
41  $actor = $this->event->getActor();
42  if (!$actor instanceof \ElggUser) {
43  return parent::getNotificationBody($recipient, $method);
44  }
45 
47 
48  if ($this->recipientIsChangedUser($recipient)) {
49  return elgg_echo('admin:notification:remove_admin:user:body', [
51  $site->getDisplayName(),
52  $site->getURL(),
53  ], $recipient->getLanguage());
54  } else {
55  $entity = $this->event->getObject();
56 
57  return elgg_echo('admin:notification:remove_admin:admin:body', [
59  $entity->getDisplayName(),
60  $site->getDisplayName(),
61  $entity->getURL(),
62  ], $recipient->getLanguage());
63  }
64  }
65 
69  protected function getNotificationURL(\ElggUser $recipient, string $method): string {
70  if ($this->recipientIsChangedUser($recipient)) {
71  return '';
72  }
73 
74  return elgg_generate_url('admin', ['segments' => 'users/admins']);
75  }
76 
80  protected function addMuteLink(): bool {
81  return false;
82  }
83 
89  public function getSubscriptions(): array {
90  $result = parent::getSubscriptions();
91 
92  /* @var $user \ElggUser */
93  $user = $this->event->getObject();
94 
95  if (_elgg_services()->config->security_notify_user_admin) {
96  // add the user to the subscribers
97  $result[$user->guid] = ['email'];
98  }
99 
100  if (_elgg_services()->config->security_notify_admins) {
101  // add the current site admins to the subscribers
102 
103  $admin_batch = elgg_get_admins([
104  'limit' => false,
105  'wheres' => [
106  function (QueryBuilder $qb, $main_alias) use ($user) {
107  return $qb->compare("{$main_alias}.guid", '!=', $user->guid, ELGG_VALUE_GUID);
108  },
109  ],
110  'batch' => true,
111  ]);
112 
113  foreach ($admin_batch as $admin) {
114  $result[$admin->guid] = ['email'];
115  }
116  }
117 
118  return $result;
119  }
120 
124  public static function isConfigurableByUser(): bool {
125  return false;
126  }
127 }
if(($owner instanceof\ElggGroup||$owner instanceof\ElggUser)&&!in_array($owner->guid, $mute_guids)) $actor
Definition: mute.php:86
$admin
Definition: useradd.php:19
getNotificationBody(\ElggUser $recipient, string $method)
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
const ELGG_VALUE_GUID
Definition: constants.php:113
Database abstraction query builder.
getNotificationSubject(\ElggUser $recipient, string $method)
$site
Definition: icons.php:5
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
getLanguage(string $fallback=null)
Get user language or default to site language.
Definition: ElggUser.php:71
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
$user
Definition: ban.php:7
elgg_get_site_entity()
Get the current site entity.
Definition: entities.php:99
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
$qb
Definition: queue.php:12
$recipient
Definition: mute.php:8
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:314
getNotificationURL(\ElggUser $recipient, string $method)