Elgg  Version master
MakeAdminUserEventHandler.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:make_admin:user:subject', [elgg_get_site_entity()->getDisplayName()]);
31  }
32 
33  return elgg_echo('admin:notification:make_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:make_admin:user:body', [
50  $site->getDisplayName(),
51  $site->getURL(),
52  ]);
53  }
54 
55  $entity = $this->getEventEntity();
56 
57  return elgg_echo('admin:notification:make_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 elgg_generate_url('admin');
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 
93  if ($user instanceof \ElggUser && _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  $admin_batch = elgg_get_admins([
101  'limit' => false,
102  'wheres' => [
103  function (QueryBuilder $qb, $main_alias) use ($user) {
104  return $qb->compare("{$main_alias}.guid", '!=', $user?->guid, ELGG_VALUE_GUID);
105  },
106  ],
107  'batch' => true,
108  ]);
109 
110  foreach ($admin_batch as $admin) {
111  $result[$admin->guid] = ['email'];
112  }
113  }
114 
115  return $result;
116  }
117 
121  public static function isConfigurableByUser(): bool {
122  return false;
123  }
124 }
if(($owner instanceof\ElggGroup||$owner instanceof\ElggUser)&&!in_array($owner->guid, $mute_guids)) $actor
Definition: mute.php:78
getSubscriptions()
Add the user to the subscribers when changing admin rights.
getNotificationURL(\ElggUser $recipient, string $method)
{}
$admin
Definition: useradd.php:19
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.
recipientIsChangedUser(\ElggUser $recipient)
Tells if the recipient is the user being changed.
Notification Event Handler for &#39;user&#39; &#39;user&#39; &#39;make_admin&#39; action.
$site
Definition: icons.php:5
elgg_get_admins(array $options=[])
Elgg admin functions.
Definition: admin.php:26
Notification Event Handler handles preparation of a notification.
$entity
Definition: reset.php:8
getNotificationBody(\ElggUser $recipient, string $method)
{}
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
getNotificationSubject(\ElggUser $recipient, string $method)
{}
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:351
$qb
Definition: queue.php:12
$recipient
Definition: mute.php:8
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:306