Scalr\UI\Controller\Admin\Analytics\NotificationTrait::saveNotifications PHP Method

saveNotifications() protected method

Saves/modifies/deletes notifications
protected saveNotifications ( integer $subjectType, array $settings, string $projectId = null )
$subjectType integer Notification subject type
$settings array Array of notifications to create/modify
$projectId string optional Projects id.
    protected function saveNotifications($subjectType, $settings, $projectId = null)
    {
        $uuids = [];
        foreach ($settings['items'] as $item) {
            $notification = new NotificationEntity();
            if ($item['uuid']) {
                $notification->findPk($item['uuid']);
                if (!$notification->hasAccessPermissions($this->getUser())) {
                    continue;
                }
            }
            $notification->subjectType = $subjectType;
            $notification->subjectId = $item['subjectId'] ? $item['subjectId'] : null;
            $notification->notificationType = $item['notificationType'];
            $notification->threshold = $item['threshold'];
            $notification->recipientType = $item['recipientType'];
            $notification->emails = $item['emails'];
            $notification->status = $item['status'];
            $notification->save();
            $uuids[] = $notification->uuid;
        }
        $criteria = [['subjectType' => $subjectType], ['accountId' => null]];
        if ($projectId) {
            $criteria[] = ['subjectId' => $projectId];
        }
        foreach (NotificationEntity::find($criteria) as $notification) {
            /* @var $notification NotificationEntity */
            if (!in_array($notification->uuid, $uuids) && $notification->hasAccessPermissions($this->getUser())) {
                $notification->delete();
            }
        }
    }