Elgg\Notifications\NotificationsService::sendInstantNotifications PHP Метод

sendInstantNotifications() публичный Метод

Returns an array in the form: [ 25 => [ 'email' => true, 'sms' => false, ], 55 => [], ]
public sendInstantNotifications ( ElggEntity $sender, array $recipients = [], array $params = [] ) : array
$sender ElggEntity Sender of the notification
$recipients array An array of entities to notify
$params array Notification parameters
Результат array
    public function sendInstantNotifications(\ElggEntity $sender, array $recipients = [], array $params = [])
    {
        if (!$sender instanceof \ElggEntity) {
            throw new InvalidArgumentException("Notification sender must be a valid entity");
        }
        $deliveries = [];
        if (!$this->methods) {
            return $deliveries;
        }
        $recipients = array_filter($recipients, function ($e) {
            return $e instanceof \ElggUser;
        });
        $object = elgg_extract('object', $params);
        $action = elgg_extract('action', $params);
        $methods_override = elgg_extract('methods_override', $params);
        unset($params['methods_override']);
        if ($methods_override && !is_array($methods_override)) {
            $methods_override = [$methods_override];
        }
        $event = new InstantNotificationEvent($object, $action, $sender);
        $params['event'] = $event;
        $params['origin'] = Notification::ORIGIN_INSTANT;
        $subscriptions = [];
        foreach ($recipients as $recipient) {
            // Are we overriding delivery?
            $methods = $methods_override;
            if (empty($methods)) {
                $methods = [];
                $user_settings = $recipient->getNotificationSettings();
                foreach ($user_settings as $method => $enabled) {
                    if ($enabled) {
                        $methods[] = $method;
                    }
                }
            }
            $subscriptions[$recipient->guid] = $methods;
        }
        $hook_params = ['event' => $params['event'], 'origin' => $params['origin'], 'methods_override' => $methods_override];
        $subscriptions = $this->hooks->trigger('get', 'subscriptions', $hook_params, $subscriptions);
        $params['subscriptions'] = $subscriptions;
        // return false to stop the default notification sender
        if ($this->hooks->trigger('send:before', 'notifications', $params, true)) {
            $deliveries = $this->sendNotifications($event, $subscriptions, $params);
        }
        $params['deliveries'] = $deliveries;
        $this->hooks->trigger('send:after', 'notifications', $params);
        return $deliveries;
    }