Runs notification events.

@param array $notification
187508
protected function listenNotificationsEvents(array $notification)
    {
        $events = Arr::get($notification, 'event');

        if($events === null && isset($notification['classname'])) {
            $events = app()->make($notification['classname'])->getEvents();
        }

        foreach ((array) $events as $event) {
            $this->runNotificationListener($event, $notification);
        }
    }
373340
public function send(Notification $notification)
    {
        $message = $this->composeMessage($notification);
        $message->send($this->mailer);
    }
584023
public function sendNotification($notification)
    {
        if (!$notification instanceof DeviceNotification && !$notification instanceof TopicNotification) {
            throw new \InvalidArgumentException('Notification must be of type DeviceNotification or TopicNotification');
        }

        $message = (new Message())
            ->setNotification($notification)
            ->setData($notification->getData())
            ->setPriority($notification->getPriority())
            ->setJsonData($notification->getJsonData())
            ->setContentAvailable($notification->getContentAvailable())
            ->setCollapseKey($notification->getCollapseKey());

        // Check for the type of Notification
        if($notification instanceof DeviceNotification){
            foreach ($notification->getDeviceTokens() as $deviceToken) {
                $message->addRecipient(new Device($deviceToken));
            }
        } else if ($notification instanceof TopicNotification) {
            $message->addRecipient(new Topic($notification->getTopic()));
        }

        return $this->client->send($message);
    }
1100611
protected function cron_notify(array $notifications) {
        global $CFG;

        if (empty($notifications)) {
            $this->cron_mtrace('nothing to notify about. ', '');
            return;
        }

        $admins = get_admins();

        if (empty($admins)) {
            return;
        }

        $this->cron_mtrace('sending notifications ... ', '');

        $text = get_string('updatenotifications', 'core_admin') . PHP_EOL;
        $html = html_writer::tag('h1', get_string('updatenotifications', 'core_admin')) . PHP_EOL;

        $coreupdates = array();
        $pluginupdates = array();

        foreach ($notifications as $notification) {
            if ($notification->component == 'core') {
                $coreupdates[] = $notification;
            } else {
                $pluginupdates[] = $notification;
            }
        }

        if (!empty($coreupdates)) {
            $text .= PHP_EOL . get_string('updateavailable', 'core_admin') . PHP_EOL;
            $html .= html_writer::tag('h2', get_string('updateavailable', 'core_admin')) . PHP_EOL;
            $html .= html_writer::start_tag('ul') . PHP_EOL;
            foreach ($coreupdates as $coreupdate) {
                $html .= html_writer::start_tag('li');
                if (isset($coreupdate->release)) {
                    $text .= get_string('updateavailable_release', 'core_admin', $coreupdate->release);
                    $html .= html_writer::tag('strong', get_string('updateavailable_release', 'core_admin', $coreupdate->release));
                }
                if (isset($coreupdate->version)) {
                    $text .= ' '.get_string('updateavailable_version', 'core_admin', $coreupdate->version);
                    $html .= ' '.get_string('updateavailable_version', 'core_admin', $coreupdate->version);
                }
                if (isset($coreupdate->maturity)) {
                    $text .= ' ('.get_string('maturity'.$coreupdate->maturity, 'core_admin').')';
                    $html .= ' ('.get_string('maturity'.$coreupdate->maturity, 'core_admin').')';
                }
                $text .= PHP_EOL;
                $html .= html_writer::end_tag('li') . PHP_EOL;
            }
            $text .= PHP_EOL;
            $html .= html_writer::end_tag('ul') . PHP_EOL;

            $a = array('url' => $CFG->wwwroot.'/'.$CFG->admin.'/index.php');
            $text .= get_string('updateavailabledetailslink', 'core_admin', $a) . PHP_EOL;
            $a = array('url' => html_writer::link($CFG->wwwroot.'/'.$CFG->admin.'/index.php', $CFG->wwwroot.'/'.$CFG->admin.'/index.php'));
            $html .= html_writer::tag('p', get_string('updateavailabledetailslink', 'core_admin', $a)) . PHP_EOL;

            $text .= PHP_EOL . get_string('updateavailablerecommendation', 'core_admin') . PHP_EOL;
            $html .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin')) . PHP_EOL;
        }

        if (!empty($pluginupdates)) {
            $text .= PHP_EOL . get_string('updateavailableforplugin', 'core_admin') . PHP_EOL;
            $html .= html_writer::tag('h2', get_string('updateavailableforplugin', 'core_admin')) . PHP_EOL;

            $html .= html_writer::start_tag('ul') . PHP_EOL;
            foreach ($pluginupdates as $pluginupdate) {
                $html .= html_writer::start_tag('li');
                $text .= get_string('pluginname', $pluginupdate->component);
                $html .= html_writer::tag('strong', get_string('pluginname', $pluginupdate->component));

                $text .= ' ('.$pluginupdate->component.')';
                $html .= ' ('.$pluginupdate->component.')';

                $text .= ' '.get_string('updateavailable', 'core_plugin', $pluginupdate->version);
                $html .= ' '.get_string('updateavailable', 'core_plugin', $pluginupdate->version);

                $text .= PHP_EOL;
                $html .= html_writer::end_tag('li') . PHP_EOL;
            }
            $text .= PHP_EOL;
            $html .= html_writer::end_tag('ul') . PHP_EOL;

            $a = array('url' => $CFG->wwwroot.'/'.$CFG->admin.'/plugins.php');
            $text .= get_string('updateavailabledetailslink', 'core_admin', $a) . PHP_EOL;
            $a = array('url' => html_writer::link($CFG->wwwroot.'/'.$CFG->admin.'/plugins.php', $CFG->wwwroot.'/'.$CFG->admin.'/plugins.php'));
            $html .= html_writer::tag('p', get_string('updateavailabledetailslink', 'core_admin', $a)) . PHP_EOL;
        }

        $a = array('siteurl' => $CFG->wwwroot);
        $text .= PHP_EOL . get_string('updatenotificationfooter', 'core_admin', $a) . PHP_EOL;
        $a = array('siteurl' => html_writer::link($CFG->wwwroot, $CFG->wwwroot));
        $html .= html_writer::tag('footer', html_writer::tag('p', get_string('updatenotificationfooter', 'core_admin', $a),
            array('style' => 'font-size:smaller; color:#333;')));

        foreach ($admins as $admin) {
            $message = new \core\message\message();
            $message->courseid          = SITEID;
            $message->component         = 'moodle';
            $message->name              = 'availableupdate';
            $message->userfrom          = get_admin();
            $message->userto            = $admin;
            $message->subject           = get_string('updatenotificationsubject', 'core_admin', array('siteurl' => $CFG->wwwroot));
            $message->fullmessage       = $text;
            $message->fullmessageformat = FORMAT_PLAIN;
            $message->fullmessagehtml   = $html;
            $message->smallmessage      = get_string('updatenotifications', 'core_admin');
            $message->notification      = 1;
            message_send($message);
        }
    }
351873
public function render(array $notifications)
    {
        $alerts = '';

        foreach ($notifications as $notification) {
            $message = $this->generateMessage($notification);

            $alerts .= "alert('{$message}');\n";
        }

        return $this->renderOutput($alerts);
    }
861075
public function display_notices() {
        // Go through all notices
        foreach( $this->active as $id=>$count ) {

            // If there is a call-able function, execute it
            if ( is_callable( $this->notices[$id]['cond_func'] ) ) {
                $cond = call_user_func( $this->notices[$id]['cond_func'] );
            } else {
                $cond = true;
            }

            // Print the notification
            if ( $cond ) {
                $this->print_notification( $this->notices[$id] );
            }

            // If only 1 count is available, unset the notice
            if ( $count === 1 ) {
                unset( $this->active[$id] );
            }

            // Decrease the notice counts
            if ( $count > 1 ) {
                $this->active[$id] = $count - 1;
            }
        }

        $this->save();
    }
101194
public function markAsUnread($notifications)
    {
        if ( ! is_array($notifications)) {
            $notifications = func_get_args();
        }

        $notifications = $this->store->markAsUnread($notifications);

        foreach ($notifications as $notification) {
            event(new NotificationUnread($notification));
        }

        return count($notifications) == 1 ? $notifications[0] : $notifications;
    }
808491
public function show(Notification $notification)
    {
        $this->authorize('view', $notification);

        $notification->markAsRead();

        return view('laralum_notifications::show', ['notification' => $notification]);
    }
772851
public function sendNotification(NotificationInterface $notification)
    {
        $uri = $notification->buildUri($this->endpoint, $this->hubPath).self::API_VERSION;

        $token = $this->generateSasToken($uri);
        $headers = array_merge(['Authorization: '.$token], $notification->getHeaders());

        $this->request(self::METHOD_POST, $uri, $headers, $notification->getPayload());
    }
531461
public function push($notification, $notifiable)
    {
        if ( ! is_array($notifiable) && ! $notifiable instanceof Traversable) {
            $notifiable = [$notifiable];
        }

        foreach ($notifiable as $toBeNotified) {
            if ( ! $toBeNotified instanceof Notifiable && !$toBeNotified instanceof NotifiableGroup) {
                throw new NotNotifiableException("The notifiable members must implement the notifiable interface.");
            }
        }

        $notification = is_string($notification) ? ['body' => $notification] : $notification;

        foreach ($notifiable as $toBeNotified) {
            $this->pushNotification($notification, $toBeNotified);
        }
    }
340123
protected function prepareNotification(Notification $notification, $params = array())
    {
        $data = array_filter($notification->toArray());
        // Prevent from duplicating context items
        unset($data['context']);

        $params += array('origin' => php_sapi_name() == 'cli' ? 'cli' : 'http');
        $params += array('reported_at' => new \DateTime());
        $params += array('server' => $this->getServerName());

        $mergedData = array_merge($data, $params);

        $notification->hydrate($mergedData);

        return $notification;
    }
36957
public function execute($options = array())
    {
        $message = $options['message'];
        $receivers = isset($options['attributes']) ? $options['attributes'] : array();
        foreach ($receivers as $receiver) {
            $this->sendNotification($receiver, $message->getBody());
        }
    }
504345
protected function registerNotification(array $notification)
    {
        $view = $this->getView();

        $options = Json::encode(ArrayHelper::merge($this->getClientOptions(), $notification));
        $view->registerJs("new PNotify({$options});");
    }
325807
public void publish(final Notification notification) {
        LOGGER.debug("Dispatching notification: " + notification.getClass().toString());
        final ArrayList<Subscription> subscriptions = SUBSCRIPTION_MAP.get(notification.getClass());
        if (subscriptions == null) {
            LOGGER.debug("No subscribers to inform from notification: " + notification.getClass().getName());
            return;
        }
        for (final Subscription subscription: subscriptions) {
            if (subscription.getScope() != null && subscription.getGroup() != null && subscription.getLevel() != null) { // subscription was the most specific
                if (subscription.getScope().equals(notification.getScope()) && subscription.getGroup().equals(notification.getGroup()) && subscription.getLevel() == notification.getLevel()) {
                    alertSubscriber(notification, subscription.getSubscriber());
                }
            } else if (subscription.getGroup() != null && subscription.getLevel() != null) { // subscription was very specific
                if (subscription.getGroup().equals(notification.getGroup()) && subscription.getLevel() == notification.getLevel()) {
                    alertSubscriber(notification, subscription.getSubscriber());
                }
            } else if (subscription.getGroup() != null) { // subscription was somewhat specific
                if (subscription.getGroup().equals(notification.getGroup())) {
                    alertSubscriber(notification, subscription.getSubscriber());
                }
            } else if (subscription.getLevel() != null) { // subscription was somewhat specific
                if (subscription.getLevel() == notification.getLevel()) {
                    alertSubscriber(notification, subscription.getSubscriber());
                }
            } else { // subscription was not specific
                alertSubscriber(notification, subscription.getSubscriber());
            }
        }
    }
806584
public static function notice(...$messages): void
    {
        static::init();

        if (!static::isTemporaryDisabled('notice')) {
            foreach (static::$adapters as $adapter) {
                /* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
                if ($adapter->isLevelEnabled(self::NOTICE)) {
                    $adapter->notice((new Message(self::NOTICE))->setMessages($messages));
                }
            }
        }
    }
1119164
public function send($notification, array $channels = null){
        if($channels === null){
            $channels = array_keys($this->channels);
        }

        foreach ((array)$channels as $id) {
            $channel = $this->getChannel($id);
            if(!$notification->shouldSend($channel)){
                continue;
            }

            $handle = 'to'.ucfirst($id);
            try {
                if($notification->hasMethod($handle)){
                    call_user_func([clone $notification, $handle], $channel);
                }
                else {
                    $channel->send(clone $notification);
                }
            } catch (\Exception $e) {
                Yii::warning("Notification sended by channel '$id' has failed: " . $e->getMessage(), __METHOD__);
            }
        }
    }
210019
public function markAsRead(array $notifications)
    {
        $ids = $this->getIds($notifications);

        $this->whereIn($this->getKeyName(), $ids)->update(['read' => true, 'read_at' => new Carbon()]);

        return $this->whereIn($this->getKeyName(), $ids)->get()->all();
    }