<commit_before><?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace SIWOZ\EguardianBundle\Repository;

use Doctrine\ORM\EntityRepository;
use SIWOZ\EguardianBundle\Entity\SeniorNotification;
use SIWOZ\EguardianBundle\Entity\GuardianNotificationNotification;

/**
 * Description of SeniorNotificationRepository
 *
 * @author Marcin
 */
class SeniorNotificationRepository extends EntityRepository {

    public function addNotification($notification) {
        $em = $this->getEntityManager();
        $em->persist($notification);
        $em->flush();
    }

    public function getNotificationToSend() {
        $query = $this->getEntityManager()
                ->createQuery(
                'SELECT n FROM SIWOZ\EguardianBundle\Entity\SeniorNotification n
                                WHERE n.state=0 and n.sendDate < CURRENT_DATE()'
        );
        try {
            return $query->getResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }
    }

    public function updateNotification($notification) {
        $em = $this->getEntityManager();
        $em->merge($notification);
        $em->flush();
    }

    public function updateSuccesNotification($notification) {
        $em = $this->getEntityManager();
        $notification->setState(1);
        $newDate = $notification->getSendDate()->add(new \DateInterval('PT' . $notification->getEvent()->getInterval() . 'M'));
        if ($newDate < $notification->getEvent()->getEndDate()) {
            $newNotification = new SeniorNotification();
            $newNotification->setEvent($notification->getEvent());
            $newNotification->setRegistrationId($notification->getRegistrationId());
            $newNotification->setState(0);
            $newNotification->setSendDate($newDate);
            $em->persist($newNotification);
        }
        $em->merge($notification);
        $em->flush();
    }

    public function updateFailNotification(SeniorNotification $notification) {
        $em = $this->getEntityManager();
        if ($notification->getTry() == 5) {
            $notification->setState(2);
            $newNotification = new GuardianNotificationNotification();
            $newNotification->setSeniorNotification($notification->getEvent());
            $newNotification->setRegistrationId($notification->getEvent()->getGuardian()->getRegistrationId());
            $newNotification->setState(0);
            $newNotification->setSendDate(new \DateTime());
            $em->persist($newNotification);
        } else {
            $notification->setTry($notification->getTry() + 1);
        }
        $em->merge($notification);
        $em->flush();
    }

    public function getNotificationById($id) {
        $query = $this->getEntityManager()
                        ->createQuery(
                                'SELECT e FROM SIWOZ\EguardianBundle\Entity\Event e
                                WHERE e.id=:id'
                        )->setParameter('id', $id);
        try {
            return $query->getSingleResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            
        }
    }

    public function deleteNotifcationsByEventId($id) {
        $query = $this->getEntityManager()
                        ->createQuery(
                                'DELETE SIWOZ\EguardianBundle\Entity\SeniorNotification n
                                WHERE n.event_id=:id'
                        )->setParameter('id', $id);
        return $query->execute();
    }

}<commit_msg>Poprawka<commit_after><?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace SIWOZ\EguardianBundle\Repository;

use Doctrine\ORM\EntityRepository;
use SIWOZ\EguardianBundle\Entity\SeniorNotification;
use SIWOZ\EguardianBundle\Entity\GuardianNotificationNotification;

/**
 * Description of SeniorNotificationRepository
 *
 * @author Marcin
 */
class SeniorNotificationRepository extends EntityRepository {

    public function addNotification($notification) {
        $em = $this->getEntityManager();
        $em->persist($notification);
        $em->flush();
    }

    public function getNotificationToSend() {
        $query = $this->getEntityManager()
                ->createQuery(
                'SELECT n FROM SIWOZ\EguardianBundle\Entity\SeniorNotification n
                                WHERE n.state=0 and n.sendDate < CURRENT_DATE()'
        );
        try {
            return $query->getResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }
    }

    public function updateNotification($notification) {
        $em = $this->getEntityManager();
        $em->merge($notification);
        $em->flush();
    }

    public function updateSuccesNotification($notification) {
        $em = $this->getEntityManager();
        $notification->setState(1);
        $newDate = $notification->getSendDate()->add(new \DateInterval('PT' . $notification->getEvent()->getInterval() . 'M'));
        if ($newDate < $notification->getEvent()->getEndDate()) {
            $newNotification = new SeniorNotification();
            $newNotification->setEvent($notification->getEvent());
            $newNotification->setRegistrationId($notification->getRegistrationId());
            $newNotification->setState(0);
            $newNotification->setSendDate($newDate);
            $em->persist($newNotification);
        }
        $em->merge($notification);
        $em->flush();
    }

    public function updateFailNotification(SeniorNotification $notification) {
        $em = $this->getEntityManager();
        if ($notification->getTry() == 5) {
            $notification->setState(2);
            $newNotification = new GuardianNotificationNotification();
            $newNotification->setSeniorNotification($notification->getEvent());
            $newNotification->setRegistrationId($notification->getEvent()->getGuardian()->getRegistrationId());
            $newNotification->setState(0);
            $newNotification->setSendDate(new \DateTime());
            $em->persist($newNotification);
        } else {
            $notification->setTry($notification->getTry() + 1);
        }
        $em->merge($notification);
        $em->flush();
    }

    public function getNotificationById($id) {
        $query = $this->getEntityManager()
                        ->createQuery(
                                'SELECT e FROM SIWOZ\EguardianBundle\Entity\Event e
                                WHERE e.id=:id'
                        )->setParameter('id', $id);
        try {
            return $query->getSingleResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            
        }
    }

    public function deleteNotifcationsByEventId($id) {
        $query = $this->getEntityManager()
                        ->createQuery(
                                'DELETE SIWOZ\EguardianBundle\Entity\SeniorNotification n
                                WHERE n.event=:id'
                        )->setParameter('id', $id);
        return $query->execute();
    }

}
{'fraction_non_alphanumeric': 0.12612122859472683, 'fraction_numerical': 0.0019026909486273443, 'mean_word_length': 2.2461402734891927, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2016130', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1813, 'n_words': 332}