title = $title; $notification_content->body = $body; if (!$notification_content->save()) { throw new RecordNotValid($notification_content); } foreach (User::find()->andWhere(['id' => $user_ids])->batch($this->batch_size) as $users) { foreach ($users as $user) { try { $notification = new Notification(); $notification->category = $this->category; $notification->receiver_id = $user->id; $notification->notification_content_id = $notification_content->id; $notification->sender_id = $this->sender_id; if (!$notification->save()) { throw new RecordNotValid($notification); } $this->linkFiles($notification, $files); $result[] = $notification->id; } catch (Throwable $e) { Yii::error($e->getMessage(), 'POPUP_NOTIFIER'); } } } return $result; } protected function linkFiles($notification, array $stored_files) { foreach ($stored_files as $stored_file) { $attachment = new NotificationAttachment(); $attachment->notification_id = $notification->id; if (!$attachment->save()) { throw new RecordNotValid($attachment); } $attachment->LinkFile($stored_file); } } }