コード例 #1
0
ファイル: NotificationTrait.php プロジェクト: scalr/scalr
 /**
  * Saves/modifies/deletes notifications
  *
  * @param int   $subjectType Notification subject type
  * @param array $settings    Array of notifications to create/modify
  * @param string $projectId  optional Projects id.
  * @throws \Scalr\Exception\ModelException
  */
 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();
         }
     }
 }
コード例 #2
0
ファイル: Notifications.php プロジェクト: rickb838/scalr
 private function saveNotifications($id, $subjectType, $settings)
 {
     SettingEntity::setValue($id, $settings['enabled']);
     $uuids = array();
     foreach ($settings['items'] as $item) {
         $notification = new NotificationEntity();
         if ($item['uuid']) {
             $notification->findPk($item['uuid']);
         }
         $notification->subjectType = $subjectType;
         $notification->notificationType = $item['notificationType'];
         $notification->threshold = $item['threshold'];
         $notification->recipientType = $item['recipientType'];
         $notification->emails = $item['emails'];
         $notification->save();
         $uuids[] = $notification->uuid;
     }
     foreach (NotificationEntity::findBySubjectType($subjectType) as $notification) {
         if (!in_array($notification->uuid, $uuids)) {
             $notification->delete();
         }
     }
 }
コード例 #3
0
ファイル: Costcenters.php プロジェクト: mheydt/scalr
 /**
  * @param string $ccId
  * @param string $subjectType
  * @param array  $settings
  * @throws \Scalr\Exception\ModelException
  */
 private function saveNotifications($ccId, $subjectType, $settings)
 {
     $uuids = array();
     foreach ($settings['items'] as $item) {
         $notification = new NotificationEntity();
         if ($item['uuid']) {
             $notification->findPk($item['uuid']);
         }
         $notification->subjectType = $subjectType;
         $notification->subjectId = $ccId;
         $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;
     }
     foreach (NotificationEntity::find([['subjectType' => NotificationEntity::SUBJECT_TYPE_CC], ['subjectId' => $ccId]]) as $notification) {
         if (!in_array($notification->uuid, $uuids)) {
             $notification->delete();
         }
     }
 }