<commit_before><?php

namespace RcmEventCalenderCore\Model;

use \RcmEventCalenderCore\Entity\Event,
    \RcmEventCalenderCore\Entity\Category,
    \RcmEventCalenderCore\Exception\InvalidArgumentException;

class Calender
{
    /**
     * @var \Doctrine\ORM\EntityManager entity manager
     */
    protected $entityMgr;

    protected $eventRepo;

    protected $categoryRepo;
    /**
     * @param \Doctrine\ORM\EntityManager $entityMgr
     */
    function __construct(\Doctrine\ORM\EntityManager $entityMgr){
        $this->entityMgr = $entityMgr;

        $this->eventRepo = $this->entityMgr
            ->getRepository('RcmEventCalenderCore\Entity\Event');

        $this->categoryRepo  = $this->entityMgr
            ->getRepository('RcmEventCalenderCore\Entity\Category');
    }

    /**
     * @param integer $categoryId
     *
     * @return array
     */
    function getEvents($categoryId=null, $includeExpired=false){

        $join = null;
        $categoryClaus = null;
        if($categoryId){
            $join = 'JOIN e.category c';
            $categoryClaus = 'AND c.categoryId=:categoryId';
        }

        $nonExpiredClause = 'AND e.endDate >= CURRENT_DATE()';
        if($includeExpired){
            $nonExpiredClause = null;
        }

        $query = $this->entityMgr->createQuery(
            "
                SELECT e FROM RcmEventCalenderCore\Entity\Event e
                $join
                WHERE TRUE = TRUE
                $nonExpiredClause
                $categoryClaus
                ORDER BY e.startDate
            "
        );

        if($categoryId){
            $query->setParameter('categoryId', $categoryId);
        }
        return $query->getResult();
    }

    function getEvent($eventId){
        return $this->eventRepo->findOneByEventId($eventId);
    }

    function createEvent(
        $categoryId, $title, $text, $startDate, $endDate, $mapAddress
    ) {

        $category = $this->categoryRepo->findOneByCategoryId($categoryId);
        if(!$category){
            throw new InvalidArgumentException(
                "Category #$categoryId not found"
            );
        }

        $event = new Event();
        $event->setCategory($category);
        $event->setTitle($title);
        $event->setText($text);
        $event->setMapAddress($mapAddress);
        $event->setStartDateFromString($startDate);
        $event->setEndDateFromString($endDate);

        $this->entityMgr->persist($event);
        $this->entityMgr->flush();

        return $event->getEventId();
    }

    function updateEvent(
        $eventId, $categoryId, $title, $text, $startDate, $endDate, $mapAddress
    ) {

        $category = $this->categoryRepo->findOneByCategoryId($categoryId);
        if(!$category){
            throw new InvalidArgumentException(
                "Category #$categoryId not found"
            );
        }

        $event = $this->eventRepo->findOneByEventId($eventId);
        if(!$event){
            throw new InvalidArgumentException(
                "Event #$eventId not found"
            );
        }

        $event->setCategory($category);
        $event->setTitle($title);
        $event->setText($text);
        $event->setStartDateFromString($startDate);
        $event->setEndDateFromString($endDate);
        $event->setMapAddress($mapAddress);

        $this->entityMgr->flush();
    }

    function deleteEvent($eventId){
        $this->entityMgr->remove($this->eventRepo->findOneByEventId($eventId));
        $this->entityMgr->flush();
    }

    function getCategories(){
        return $this->categoryRepo->findAll();
    }

    function getCategory($categoryId){
        return $this->categoryRepo->findOneByCategoryId($categoryId);
    }

    function createCategory($name){

        $category = new Category();
        $category->setName($name);

        $this->entityMgr->persist($category);
        $this->entityMgr->flush();

        return $category->getCategoryId();
    }

    function deleteCategory($categoryId){
        $this->entityMgr->remove(
            $this->categoryRepo->findOneByCategoryId($categoryId)
        );
        $this->entityMgr->flush();
    }
}<commit_msg>fix doc blocks<commit_after><?php

namespace RcmEventCalenderCore\Model;

use \RcmEventCalenderCore\Entity\Event,
    \RcmEventCalenderCore\Entity\Category,
    \RcmEventCalenderCore\Exception\InvalidArgumentException;

class Calender
{
    /**
     * @var \Doctrine\ORM\EntityManager entity manager
     */
    protected $entityMgr;

    protected $eventRepo;

    protected $categoryRepo;
    /**
     * @param \Doctrine\ORM\EntityManager $entityMgr
     */
    function __construct(\Doctrine\ORM\EntityManager $entityMgr){
        $this->entityMgr = $entityMgr;

        $this->eventRepo = $this->entityMgr
            ->getRepository('RcmEventCalenderCore\Entity\Event');

        $this->categoryRepo  = $this->entityMgr
            ->getRepository('RcmEventCalenderCore\Entity\Category');
    }

    /**
     * @param null $categoryId
     * @param bool $includeExpired
     *
     * @return array
     */
    function getEvents($categoryId=null, $includeExpired=false){

        $join = null;
        $categoryClaus = null;
        if($categoryId){
            $join = 'JOIN e.category c';
            $categoryClaus = 'AND c.categoryId=:categoryId';
        }

        $nonExpiredClause = 'AND e.endDate >= CURRENT_DATE()';
        if($includeExpired){
            $nonExpiredClause = null;
        }

        $query = $this->entityMgr->createQuery(
            "
                SELECT e FROM RcmEventCalenderCore\Entity\Event e
                $join
                WHERE TRUE = TRUE
                $nonExpiredClause
                $categoryClaus
                ORDER BY e.startDate
            "
        );

        if($categoryId){
            $query->setParameter('categoryId', $categoryId);
        }
        return $query->getResult();
    }

    /**
     * @param $eventId
     *
     * @return mixed
     */
    function getEvent($eventId){
        return $this->eventRepo->findOneByEventId($eventId);
    }

    /**
     * @param $categoryId
     * @param $title
     * @param $text
     * @param $startDate
     * @param $endDate
     * @param $mapAddress
     *
     * @return int
     * @throws \RcmEventCalenderCore\Exception\InvalidArgumentException
     */
    function createEvent(
        $categoryId, $title, $text, $startDate, $endDate, $mapAddress
    ) {

        $category = $this->categoryRepo->findOneByCategoryId($categoryId);
        if(!$category){
            throw new InvalidArgumentException(
                "Category #$categoryId not found"
            );
        }

        $event = new Event();
        $event->setCategory($category);
        $event->setTitle($title);
        $event->setText($text);
        $event->setMapAddress($mapAddress);
        $event->setStartDateFromString($startDate);
        $event->setEndDateFromString($endDate);

        $this->entityMgr->persist($event);
        $this->entityMgr->flush();

        return $event->getEventId();
    }

    /**
     * @param $eventId
     * @param $categoryId
     * @param $title
     * @param $text
     * @param $startDate
     * @param $endDate
     * @param $mapAddress
     *
     * @throws \RcmEventCalenderCore\Exception\InvalidArgumentException
     */
    function updateEvent(
        $eventId, $categoryId, $title, $text, $startDate, $endDate, $mapAddress
    ) {

        $category = $this->categoryRepo->findOneByCategoryId($categoryId);
        if(!$category){
            throw new InvalidArgumentException(
                "Category #$categoryId not found"
            );
        }

        $event = $this->eventRepo->findOneByEventId($eventId);
        if(!$event){
            throw new InvalidArgumentException(
                "Event #$eventId not found"
            );
        }

        $event->setCategory($category);
        $event->setTitle($title);
        $event->setText($text);
        $event->setStartDateFromString($startDate);
        $event->setEndDateFromString($endDate);
        $event->setMapAddress($mapAddress);

        $this->entityMgr->flush();
    }

    /**
     * @param $eventId
     */
    function deleteEvent($eventId){
        $this->entityMgr->remove($this->eventRepo->findOneByEventId($eventId));
        $this->entityMgr->flush();
    }

    /**
     * @return array
     */
    function getCategories(){
        return $this->categoryRepo->findAll();
    }

    /**
     * @param $categoryId
     *
     * @return mixed
     */
    function getCategory($categoryId){
        return $this->categoryRepo->findOneByCategoryId($categoryId);
    }

    /**
     * @param $name
     *
     * @return int
     */
    function createCategory($name){

        $category = new Category();
        $category->setName($name);

        $this->entityMgr->persist($category);
        $this->entityMgr->flush();

        return $category->getCategoryId();
    }

    /**
     * @param $categoryId
     */
    function deleteCategory($categoryId){
        $this->entityMgr->remove(
            $this->categoryRepo->findOneByCategoryId($categoryId)
        );
        $this->entityMgr->flush();
    }
}
{'fraction_non_alphanumeric': 0.1342281879194631, 'fraction_numerical': 0.0, 'mean_word_length': 2.1425170068027213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 125, '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': '4440883', 'n_tokens_mistral': 2647, 'n_tokens_neox': 2611, 'n_words': 413}