Scalr\Stats\CostAnalytics\Entity\NotificationEntity::hasAccessPermissions PHP Méthode

hasAccessPermissions() public méthode

See also: AccessPermissionsInterface::hasAccessPermissions()
public hasAccessPermissions ( $user, $environment = null, $modify = null )
    public function hasAccessPermissions($user, $environment = null, $modify = null)
    {
        switch ($this->getScope()) {
            case static::SCOPE_ACCOUNT:
                return $this->accountId == $user->accountId;
            case static::SCOPE_SCALR:
                return $this->accountId === null;
            default:
                return false;
        }
    }

Usage Example

Exemple #1
0
 /**
  * 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();
         }
     }
 }