public function createNewPostNotifications(Post $post) { if ($post->getOnlineAt() <= new \Datetime() && $post->getSeries() != null && $post->getIsActive()) { $notifications = []; $mails = []; foreach ($post->getSeries()->getAbonnements() as $abonnement) { if ($abonnement->getNewPost()) { $notification = new Notification(); $notification->setUser($abonnement->getUser()); $notification->setPost($post); $notification->setType(Notification::NEW_POST); $notifications[] = $notification; if ($abonnement->getSendMails()) { $mails[] = $notification; } } } $this->sendMails(Notification::NEW_POST, $mails); $this->saveNotifications($notifications); } }