<commit_before><?php

namespace AppBundle\Model;

use AppBundle\Entity\Notification;
use AppBundle\Entity\Episode;
use AppBundle\Entity\Series;
use AppBundle\Entity\Post;

/**
 * creates and sends all notifications in an application.
 * It also sends out emails according to the abonnement settings of an user.
 */
class NotificationService
{
    private $em;
    private $mailer;
    private $livestream_template;
    private $new_episode_template;
    private $new_post_template;
    private $translator;

    public function __construct($em, $mailer, $translator, $livestream_template, $new_post_template, $new_episode_template)
    {
        $this->em = $em;
        $this->mailer = $mailer;
        $this->translator = $translator;
        $this->livestream_template = $livestream_template;
        $this->new_post_template = $new_post_template;
        $this->new_episode_template = $new_episode_template;
    }

    public function createNewEpisodeNotifications(Episode $episode)
    {
        $notifications = [];
        $mails = [];
        foreach ($episode->getSeries()->getAbonnements() as $abonnement) {
            $notification = new Notification();
            $notification->setEpisode($episode);
            $notification->setType(Notification::NEW_EPISODE);
            $abonnement->getUser()->addNotification($notification);
            $notifications[] = $notification;
            if ($abonnement->getSendMails()) {
                $mails[] = $notification;
            }
        }
        $this->sendMails(Notification::NEW_EPISODE, $mails);
        $this->saveNotifications($notifications);
    }

    public function createNewPostNotifications(Post $post)
    {
        if ($post->getOnlineAt() <= new \Datetime()) {
            $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);
        }
    }

    public function createLivestreamNotifications(Series $series)
    {
        $notifications = [];
        $mails = [];<commit_msg>don't send notifications for oktothek posts or inactive ones<commit_after><?php

namespace AppBundle\Model;

use AppBundle\Entity\Notification;
use AppBundle\Entity\Episode;
use AppBundle\Entity\Series;
use AppBundle\Entity\Post;

/**
 * creates and sends all notifications in an application.
 * It also sends out emails according to the abonnement settings of an user.
 */
class NotificationService
{
    private $em;
    private $mailer;
    private $livestream_template;
    private $new_episode_template;
    private $new_post_template;
    private $translator;

    public function __construct($em, $mailer, $translator, $livestream_template, $new_post_template, $new_episode_template)
    {
        $this->em = $em;
        $this->mailer = $mailer;
        $this->translator = $translator;
        $this->livestream_template = $livestream_template;
        $this->new_post_template = $new_post_template;
        $this->new_episode_template = $new_episode_template;
    }

    public function createNewEpisodeNotifications(Episode $episode)
    {
        $notifications = [];
        $mails = [];
        foreach ($episode->getSeries()->getAbonnements() as $abonnement) {
            $notification = new Notification();
            $notification->setEpisode($episode);
            $notification->setType(Notification::NEW_EPISODE);
            $abonnement->getUser()->addNotification($notification);
            $notifications[] = $notification;
            if ($abonnement->getSendMails()) {
                $mails[] = $notification;
            }
        }
        $this->sendMails(Notification::NEW_EPISODE, $mails);
        $this->saveNotifications($notifications);
    }

    public function createNewPostNotifications(Post $post)
    {
        if ($post->getOnlineAt() <= new \Datetime() && $post->getSeries() != null && $post->isActive()) {
            $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);
        }
    }

    public function createLivestreamNotifications(Series $series)
    {
        $notifications = [];
        $mails = [];
{'fraction_non_alphanumeric': 0.12365591397849462, 'fraction_numerical': 0.0, 'mean_word_length': 2.3782091421415155, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1550605', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1432, 'n_words': 267}