Get the \DateTime of the last Notification that has been sent.

@param $recipientId

@return \DateTime
432475
public function getLastNotificationDate($recipientId)
    {
        $qb = $this->getEntityManager()->createQueryBuilder()
            ->select('max(n.sent)')
            ->from("Azine\EmailBundle\Entity\Notification", 'n')
            ->andWhere('n.recipient_id = :recipientId')
            ->setParameter('recipientId', $recipientId);
        $results = $qb->getQuery()->execute();
        if (null === $results[0][1]) {
            // the user has not received any notifications yet ever
            $lastNotification = new \DateTime('@0');
        } else {
            $lastNotification = new \DateTime($results[0][1]);
        }

        return $lastNotification;
    }
247386
public function getBccEmailOfMessage($messageId)
    {
        $message = $this->client->get("inboxes/{$this->config['inbox_id']}/messages/$messageId/body.eml")->getBody();

        if ($message instanceof Stream) {
            $message = $message->getContents();
        }
        $matches = [];
        preg_match('/Bcc:\s[\w.-]+@[\w.-]+\.[a-z]{2,6}/', $message, $matches);

        $bcc = substr(array_shift($matches), 5);

        return $bcc;
    }
468056
public function cancelSubscription($subscriptionId, \DateTime $cancellationDate = null, $cancellationNote = null)
    {
        $requestData = new Cancel\RequestData($subscriptionId);
        $requestData->setCancellationDate($cancellationDate);
        $requestData->setCancellationNote($cancellationNote);

        $request = new Cancel\Request($requestData);

        return $this->sendRequest($request, Cancel\ApiResponse::class);
    }
206942
public function actionRead($id)
    {
        $notification = $this->getNotification($id);

        $notification->seen = 1;
        $notification->save();

        return $notification;
    }
851814
public function getLastVersionNumber($contentId)
    {
        try {
            return $this->innerGateway->getLastVersionNumber($contentId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1318475
public function get($messageId)
    {
        if (!isset($this->messages[$messageId])) {
            return null;
        }

        return new OutboxMessage($messageId, $this->messages[$messageId]->getTransportOperations());
    }
895977
public function getRecipientSpecificNotificationsSubject($contentItems, RecipientInterface $recipient)
    {
        $count = sizeof($contentItems);

        if (1 == $count) {
            // get the content-item out of the boxed associative array => array(array('templateId' => contentItem))
            $onlyItem = current(current($contentItems));
            // get the title out of the notification in the contentItem
            return $onlyItem['notification']->getTitle();
        }

        return $this->translatorService->transChoice('_az.email.notifications.subject.%count%', $count, array('%count%' => $count));
    }
488921
public function getMessage($messageId)
    {
        $rawMessage = $this->plivo->get_message(['record_id' => $messageId]);
        $incomingMessage = $this->createIncomingMessage();
        $this->processReceive($incomingMessage, $rawMessage);

        return $incomingMessage;
    }
1281465
public function getMailParameters(NotificationEntity $notification, UserInfo $recipient)
    {
        $notificationData = $notification->getNotificationData();
        $localeRepository = $this->app->make(LocaleRepository::class);
        if ($notificationData['localeID'] === null) {
            $locale = null;
        } else {
            $locale = $localeRepository->findApproved($notificationData['localeID']);
            if ($locale === null) {
                throw new Exception(t('Unable to find the locale with ID %s', $notificationData['localeID']));
            }
        }
        $commentsRepository = $this->app->make(TranslatableCommentRepository::class);
        $packageVersionRepository = $this->app->make(PackageVersionRepository::class);
        $comments = [];
        $config = $this->app->make('community_translation/config');
        $onlineTranslationPath = $config->get('options.onlineTranslationPath');
        $dh = $this->app->make('date');
        foreach ($notificationData['comments'] as $commentID => $commentInfo) {
            $comment = $commentsRepository->find($commentID);
            if ($comment !== null) {
                $packageVersion = $packageVersionRepository->find($commentInfo['packageVersionID']);
                if ($packageVersion !== null) {
                    $localeForLink = $locale;
                    if ($localeForLink === null) {
                        $localeForLink = $localeRepository->findApproved($commentInfo['whileTranslatingLocaleID']);
                    }
                    if ($localeForLink !== null) {
                        $comments[] = [
                            '_dateSort' => $comment->getPostedOn()->getTimestamp(),
                            'date' => $dh->formatPrettyDateTime($comment->getPostedOn(), true, true, $recipient->getUserTimezone() ?: 'user'),
                            'author' => $comment->getPostedBy(),
                            'translatable' => $comment->getTranslatable()->getText(),
                            'messageHtml' => $this->markdownToHtml($comment->getText()),
                            'link' => ((string) URL::to($onlineTranslationPath, $packageVersion->getID(), $localeForLink->getID())) . '#tid:' . $comment->getTranslatable()->getID(),
                        ];
                    }
                }
            }
        }

        if (empty($comments)) {
            throw new Exception(t('No comment found (have they been deleted?)'));
        }

        usort($comments, function (array $a, array $b) {
            return $a['_dateSort'] - $b['_dateSort'];
        });
        $comments = array_map(
            function (array $comment) {
                unset($comment['_dateSort']);

                return $comment;
            },
            $comments
        );

        return [
            'specificForLocale' => ($locale === null) ? null : $locale->getDisplayName(),
            'comments' => $comments,
        ] + $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;
    }
1284074
public function getMailParameters(NotificationEntity $notification, UserInfo $recipient)
    {
        $notificationData = $notification->getNotificationData();
        $pr = $this->app->make(PackageRepository::class);
        $qb = $pr->createQueryBuilder('p');
        $or = $qb->expr()->orX();
        foreach ($notificationData['packageIDs'] as $packageID) {
            $or->add('p.id = ' . (int) $packageID);
        }
        $packages = [];
        if ($or->count() > 0) {
            foreach ($qb->where($or)->getQuery()->iterate() as $packageRow) {
                $package = $packageRow[0];
                $packageURL = $this->getBlockPageURL('CommunityTranslation Search Packages', 'package/' . $package->getHandle());
                $packages[] = [
                    'url' => $packageURL,
                    'name' => $package->getDisplayName(),
                ];
                $qb->getEntityManager()->detach($package);
            }
        }
        if (count($packages) === 0) {
            throw new Exception(t('Unable to find any package'));
        }

        return [
            'packages' => $packages,
        ] + $this->getCommonMailParameters($notification, $recipient);
    }
860426
public function lastOnlineDate() : ?\DateTime
    {
        $isOnline = $this->info()->presences[0]->onlineStatus == "online";

        // They're online now, so just return the current DateTime.
        if ($isOnline) return new \DateTime();

        // If they don't have a DateTime, just return null.
        // This can happen if the User object was created using the onlineId string and not the profile data.
        // Sony only provides lastOnlineDate on the 'friends/profiles2' endpoint and not the individual userinfo endpoint.
        // This can be a TODO if in the future Sony decides to make that property available for that endpoint.
        // - Tustin 9/29/2018
        if (!isset($this->info()->presences[0]->lastOnlineDate)) return null;
        
        // I guess it's possible for lastOnlineDate to not exist, but that seems very unlikely.
        return new \DateTime($this->info()->presences[0]->lastOnlineDate);
    }
353844
public function getDeliveryThemeId($deliveryId)
    {
        $themeId = $this->getDeliveryThemeIdFromCache($deliveryId);
        if ($themeId === false) {
            $themeId = $this->getDeliveryThemeIdFromDb($deliveryId);
            $this->storeDeliveryThemeIdToCache($deliveryId, $themeId);
        }

        return $themeId;
    }
176994
public function getLastInsertId()
    {
        try {
            $lastInsertId = $this->getConnection()->lastInsertId();
        } catch (DBALException $exception) {
            $exception = $this->convertException($exception);
            $this->handleException($exception);
        } catch (PDOException $exception) {
            $exception = $this->convertException($exception);
            $this->handleException($exception);
        }

        return $lastInsertId;
    }
684951
public function getLastAccessed(): \DateTime
    {
        \clearstatcache();
        if (false === $atime = \fileatime($this->filename)) {
            throw new TimeCanNotBeReadException('Last access time can not be read.');
        }
        return (new \DateTime())->setTimestamp($atime);
    }
1239660
public function lastInsertId()
    {
        if ($this->isConnected()) {
            try {
                return $this->pdo->lastInsertId();
            } catch (PDOException $e) {
                throw new \Exception($e->getMessage());
                return false;
            }
        } else {
            return false;
        }
    }
835149
public function getLastUpdated()
    {
        $packages = Package::get()->limit(1);
        if (!$packages->count()) {
            return '';
        }
        /** @var DBDatetime $datetime */
        $datetime = $packages->first()->dbObject('LastEdited');
        return $datetime->Date() . ' ' . $datetime->Time12();
    }