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();
}
}
}