Elgg  Version 6.1
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->getEventEntity()?->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()]);
31  }
32 
33  return elgg_echo('admin:notification:remove_admin:admin:subject', [elgg_get_site_entity()->getDisplayName()]);
34  }
35 
39  protected function getNotificationBody(\ElggUser $recipient, string $method): string {
40  $actor = $this->getEventActor();
41  if (!$actor instanceof \ElggUser) {
42  return parent::getNotificationBody($recipient, $method);
43  }
44 
46 
47  if ($this->recipientIsChangedUser($recipient)) {
48  return elgg_echo('admin:notification:remove_admin:user:body', [
50  $site->getDisplayName(),
51  $site->getURL(),
52  ]);
53  }
54 
55  $entity = $this->getEventEntity();
56 
57  return elgg_echo('admin:notification:remove_admin:admin:body', [
59  $entity?->getDisplayName(),
60  $site->getDisplayName(),
61  $entity?->getURL(),
62  ]);
63  }
64 
68  protected function getNotificationURL(\ElggUser $recipient, string $method): string {
69  if ($this->recipientIsChangedUser($recipient)) {
70  return '';
71  }
72 
73  return elgg_generate_url('admin', ['segments' => 'users/admins']);
74  }
75 
79  protected function addMuteLink(): bool {
80  return false;
81  }
82 
88  public function getSubscriptions(): array {
89  $result = parent::getSubscriptions();
90 
91  $user = $this->getEventEntity();
92  if ($user instanceof \ElggUser && _elgg_services()->config->security_notify_user_admin) {
93  // add the user to the subscribers
94  $result[$user->guid] = ['email'];
95  }
96 
97  if (_elgg_services()->config->security_notify_admins) {
98  // add the current site admins to the subscribers
99  $admin_batch = elgg_get_admins([
100  'limit' => false,
101  'wheres' => [
102  function (QueryBuilder $qb, $main_alias) use ($user) {
103  return $qb->compare("{$main_alias}.guid", '!=', $user?->guid, ELGG_VALUE_GUID);
104  },
105  ],
106  'batch' => true,
107  ]);
108 
109  foreach ($admin_batch as $admin) {
110  $result[$admin->guid] = ['email'];
111  }
112  }
113 
114  return $result;
115  }
116 
120  public static function isConfigurableByUser(): bool {
121  return false;
122  }
123 }
if(($owner instanceof\ElggGroup||$owner instanceof\ElggUser)&&!in_array($owner->guid, $mute_guids)) $actor
Definition: mute.php:78
$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.
getEventEntity()
Get the entity from the notification event.
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
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
getEventActor()
Get the acting user from the notification event.
$user
Definition: ban.php:7
elgg_get_site_entity()
Get the current site entity.
Definition: entities.php:101
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
$qb
Definition: queue.php:12
$recipient
Definition: mute.php:8
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:306
getNotificationURL(\ElggUser $recipient, string $method)
{}