Get all notifications that should be sent.

@param $recipientId

@return array of Notification
431625
public function getNotificationsToSend($recipientId)
    {
        $qb = $this->createQueryBuilder('n')
            ->andWhere('n.sent is null')
            ->andWhere('n.recipient_id = :recipientId')
            ->setParameter('recipientId', $recipientId)
            ->orderBy('n.importance', 'desc')
            ->orderBy('n.template', 'asc')
            ->orderBy('n.title', 'asc');
        $notifications = $qb->getQuery()->execute();

        return $notifications;
    }
530051
function(recipientsArr) {
  var ret = [];
  for(var i = 0; i < recipientsArr.length; i ++) {
    ret.push(_recipientInfoToAsn1(recipientsArr[i]));
  }
  return ret;
}
436589
static public function sendUserNotification( $userID )
    {
        $ini = eZINI::instance();

        if ( $ini->variable( 'UserSettings', 'EmailRegistrationInfo' ) === "disabled" )
        {
            return array( 'status' => eZModuleOperationInfo::STATUS_CONTINUE );
        }

        eZDebugSetting::writeNotice( 'Sending approval notification to the user.' , 'kernel-user', 'user register' );
        $user = eZUser::fetch( $userID );
        // Send mail
        $tpl = eZTemplate::factory();
        $tpl->setVariable( 'user',  $user );
        $templateResult = $tpl->fetch( 'design:user/registrationapproved.tpl' );

        $mail = new eZMail();
        if ( $tpl->hasVariable( 'content_type' ) )
            $mail->setContentType( $tpl->variable( 'content_type' ) );

        $emailSender = $ini->variable( 'MailSettings', 'EmailSender' );
        if ( $tpl->hasVariable( 'email_sender' ) )
            $emailSender = $tpl->variable( 'email_sender' );
        else if ( !$emailSender )
            $emailSender = $ini->variable( 'MailSettings', 'AdminEmail' );

        if ( $tpl->hasVariable( 'subject' ) )
            $subject = $tpl->variable( 'subject' );
        else
            $subject = ezpI18n::tr( 'kernel/user/register', 'User registration approved' );

        $mail->setSender( $emailSender );
        $receiver = $user->attribute( 'email' );
        $mail->setReceiver( $receiver );
        $mail->setSubject( $subject );
        $mail->setBody( $templateResult );
        $mailResult = eZMailTransport::send( $mail );

        return array( 'status' => eZModuleOperationInfo::STATUS_CONTINUE );
    }
882263
public function getCollectorRecipient($collectorId, $recipientId)
	{
		return $this->sendRequest(
			$this->createRequest('GET', sprintf('collectors/%s/recipients/%s', $collectorId,  $recipientId))
		);
	}
465716
protected function getRecipientIDs(NotificationEntity $notification)
    {
        $notificationData = $notification->getNotificationData();
        $locale = $this->app->make(LocaleRepository::class)->find($notificationData['localeID']);
        if ($locale === null && $locale->isApproved()) {
            // The request has already been approved/refused
            $result = [];
        } else {
            $group = $this->getGroupsHelper()->getGlobalAdministrators();
            $result = $group->getGroupMemberIDs();
        }

        return $result;
    }
716224
public function getSubscriptionById($subscriptionId)
    {
        $subscriptions = $this
            ->getSubscriptions(null, null, null, $subscriptionId)
            ->getResponse()
            ->getSubscriptions();

        return count($subscriptions) ? reset($subscriptions) : null;
    }
590927
public function getNotifications( $jsonDecodePayload = false )
    {
        $output = array();
        while( $notification = $this->getNotification() ) {
            if( $jsonDecodePayload ) {
                $notification['payload'] = json_decode($notification['payload'], true);
            }
            $output[] = $notification;
        }
        return $output;
    }
335878
public function getMailParameters(NotificationEntity $notification, UserInfo $recipient)
    {
        $notificationData = $notification->getNotificationData();
        $locale = $this->app->make(LocaleRepository::class)->find($notificationData['localeID']);
        if ($locale === null) {
            throw new Exception(t('Unable to find the locale with ID %s', $notificationData['localeID']));
        }
        $requestedBy = $locale->getRequestedBy();

        return [
            'requestedBy' => $requestedBy,
            'localeName' => $locale->getDisplayName(),
            'teamsUrl' => $this->getBlockPageURL('CommunityTranslation Team List'),
            'notes' => $notificationData['notes'] ? $this->app->make('helper/text')->makenice($notificationData['notes']) : '',
        ] + $this->getCommonMailParameters($notification, $recipient);
    }
1221291
public function getMessage($messageId)
    {
        $rawMessage = $this->twilio->account->messages->get($messageId);
        $incomingMessage = $this->createIncomingMessage();
        $this->processReceive($incomingMessage, $rawMessage);

        return $incomingMessage;
    }
1012661
protected static function can_contact_user(int $recipientid, int $senderid) : bool {
        if (has_capability('moodle/site:messageanyuser', \context_system::instance(), $senderid) ||
            $recipientid == $senderid) {
            // The sender has the ability to contact any user across the entire site or themselves.
            return true;
        }

        // The initial value of $cancontact is null to indicate that a value has not been determined.
        $cancontact = null;

        if (self::is_blocked($recipientid, $senderid)) {
            // The recipient has specifically blocked this sender.
            $cancontact = false;
        }

        $sharedcourses = null;
        if (null === $cancontact) {
            // There are three user preference options:
            // - Site: Allow anyone not explicitly blocked to contact me;
            // - Course members: Allow anyone I am in a course with to contact me; and
            // - Contacts: Only allow my contacts to contact me.
            //
            // The Site option is only possible when the messagingallusers site setting is also enabled.

            $privacypreference = self::get_user_privacy_messaging_preference($recipientid);
            if (self::MESSAGE_PRIVACY_SITE === $privacypreference) {
                // The user preference is to allow any user to contact them.
                // No need to check anything else.
                $cancontact = true;
            } else {
                // This user only allows their own contacts, and possibly course peers, to contact them.
                // If the users are contacts then we can avoid the more expensive shared courses check.
                $cancontact = self::is_contact($senderid, $recipientid);

                if (!$cancontact && self::MESSAGE_PRIVACY_COURSEMEMBER === $privacypreference) {
                    // The users are not contacts and the user allows course member messaging.
                    // Check whether these two users share any course together.
                    $sharedcourses = enrol_get_shared_courses($recipientid, $senderid, true);
                    $cancontact = (!empty($sharedcourses));
                }
            }
        }

        if (false === $cancontact) {
            // At the moment the users cannot contact one another.
            // Check whether the messageanyuser capability applies in any of the shared courses.
            // This is intended to allow teachers to message students regardless of message settings.

            // Note: You cannot use empty($sharedcourses) here because this may be an empty array.
            if (null === $sharedcourses) {
                $sharedcourses = enrol_get_shared_courses($recipientid, $senderid, true);
            }

            foreach ($sharedcourses as $course) {
                // Note: enrol_get_shared_courses will preload any shared context.
                if (has_capability('moodle/site:messageanyuser', \context_course::instance($course->id), $senderid)) {
                    $cancontact = true;
                    break;
                }
            }
        }

        return $cancontact;
    }
720973
public function notificationSubject($comment, $recipient)
    {
        $subject = $this->owner->config()->default_notification_subject;

        $this->owner->invokeWithExtensions('updateNotificationSubject', $subject, $comment, $recipient);

        return $subject;
    }
793264
public function notificationSender($comment, $recipient)
    {
        $sender = $this->owner->config()->default_notification_sender;

        // Do hostname substitution
        $host = isset($_SERVER['HTTP_HOST'])
            ? preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST'])
            : 'localhost';
        $sender = preg_replace('/{host}/', $host, $sender);

        $this->owner->invokeWithExtensions('updateNotificationSender', $sender, $comment, $recipient);

        return $sender;
    }
413809
public static function get_user_message_preferences($userid = 0) {
        global $CFG, $PAGE;

        $params = self::validate_parameters(
            self::get_user_message_preferences_parameters(),
            array(
                'userid' => $userid,
            )
        );

        $user = self::validate_preferences_permissions($params['userid']);

        // Filter out enabled, available system_configured and user_configured processors only.
        $readyprocessors = array_filter(get_message_processors(), function($processor) {
            return $processor->enabled &&
                $processor->configured &&
                $processor->object->is_user_configured() &&
                // Filter out processors that don't have and message preferences to configure.
                $processor->object->has_message_preferences();
        });

        $providers = array_filter(message_get_providers_for_user($user->id), function($provider) {
            return $provider->component === 'moodle';
        });
        $preferences = \core_message\api::get_all_message_preferences($readyprocessors, $providers, $user);
        $notificationlistoutput = new \core_message\output\preferences\message_notification_list($readyprocessors,
            $providers, $preferences, $user);

        $renderer = $PAGE->get_renderer('core_message');

        $entertosend = get_user_preferences('message_entertosend', $CFG->messagingdefaultpressenter, $user);

        $result = array(
            'warnings' => array(),
            'preferences' => $notificationlistoutput->export_for_template($renderer),
            'blocknoncontacts' => \core_message\api::get_user_privacy_messaging_preference($user->id),
            'entertosend' => $entertosend
        );
        return $result;
    }
326876
public function sendNotifications(array &$failedAddresses)
    {
        // get all recipientIds with pending notifications in the database, that are due to be sent
        $recipientIds = $this->getNotificationRecipientIds();

        // get vars that are the same for all recipients of this notification-mail-batch
        $params = $this->getVarsForNotificationsEmail();

        $notificationsTemplate = $this->configParameter[AzineEmailExtension::TEMPLATES.'_'.AzineEmailExtension::NOTIFICATIONS_TEMPLATE];

        $sentCount = 0;
        foreach ($recipientIds as $recipientId) {
            // send the mail for this recipient
            $failedAddress = $this->sendNotificationsFor($recipientId, $notificationsTemplate, $params);
            if (null !== $failedAddress && strlen($failedAddress) > 0) {
                $failedAddresses[] = $failedAddress;
            } else {
                ++$sentCount;
            }
        }

        return $sentCount;
    }
1287105
public void forwardNotifications(Collection<Notification> notifications, Collection<Recipient> recipients,
                                     String comment) {
        List<String> lst1 = new ArrayList<>();

        for (Notification notification : notifications) {
            lst1.add(notification.getAlertId());
        }

        List<Long> lst2 = prepareRecipients(recipients);

        if (!lst1.isEmpty() && !lst2.isEmpty()) {
            broker.callRPC("RGCWXQ FORWARD", lst1, lst2, comment);
        }
    }
894099
public function getIds($notifications)
    {
        return array_map(function($notification) {
            if ($notification instanceof NotificationContract) {
                return $notification->getKey();
            } else {
                return $notification;
            }
        }, $notifications);
    }
1153681
public function getThreadSubscription(int $id): array
    {
        return $this->getApi()->request($this->getApi()
                                             ->sprintf('/notifications/threads/:id/subscription', (string)$id));
    }