<commit_before><?php

namespace Tisseo\EndivBundle\Services;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Persistence\ObjectManager;
use Tisseo\EndivBundle\Entity\GridCalendar;
use Tisseo\EndivBundle\Entity\LineVersion;

class LineVersionManager extends SortManager
{
    private $om = null;
    /** @var \Doctrine\ORM\EntityRepository $repository */
    private $repository = null;
    private $calendarManager = null;

    public function __construct(ObjectManager $om, CalendarManager $calendarManager)
    {
        $this->om = $om;
        $this->repository = $om->getRepository('TisseoEndivBundle:LineVersion');
        $this->calendarManager = $calendarManager;
    }

    public function findAll()
    {
        return $this->repository->findAll();
    }

    public function find($lineVersionId)
    {
        return empty($lineVersionId) ? null : $this->repository->find($lineVersionId);
    }

    public function findAllSortedByLineNumber()
    {
        return $this->sortLineVersionsByNumber($this->repository->findAll());
    }

    /**
     * findLastLineVersionOfLine
     *
     * @param int $lineId
     *
     * @return LineVersion or null
     *
     * Return the last version of LineVersion associated to the Line
     */
    public function findLastLineVersionOfLine($lineId)
    {
        $finalResult = null;

        if ($lineId == null) {<commit_msg>refs #30679 - add method for search LineVersion<commit_after><?php

namespace Tisseo\EndivBundle\Services;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Persistence\ObjectManager;
use Tisseo\EndivBundle\Entity\GridCalendar;
use Tisseo\EndivBundle\Entity\LineVersion;

class LineVersionManager extends SortManager
{
    private $om = null;
    /** @var \Doctrine\ORM\EntityRepository $repository */
    private $repository = null;
    private $calendarManager = null;

    public function __construct(ObjectManager $om, CalendarManager $calendarManager)
    {
        $this->om = $om;
        $this->repository = $om->getRepository('TisseoEndivBundle:LineVersion');
        $this->calendarManager = $calendarManager;
    }

    public function findAll()
    {
        return $this->repository->findAll();
    }

    public function find($lineVersionId)
    {
        return empty($lineVersionId) ? null : $this->repository->find($lineVersionId);
    }

    public function findAllSortedByLineNumber()
    {
        return $this->sortLineVersionsByNumber($this->repository->findAll());
    }

    /**
     * Find the line versions who are active during $date (month)
     * @param \Datetime $date
     * @return mixed
     */
    public function findLineVersionSortedByLineNumber(\Datetime $date = null)
    {
        if (is_null($date)) {
            $date = new \DateTime('now');
        }

        $endDate = clone $date;
        $endDate->modify('+1 month -1 day');

        $qb = $this->repository->createQueryBuilder('lv');

        $query = $qb->select('lv')
            ->where(':startDate >=  lv.startDate')
            ->andWhere(':endDate <= coalesce(lv.endDate, lv.plannedEndDate)')
            ->setParameter('startDate', $date->format('Y-m-d'))
            ->setParameter('endDate', $endDate->format('Y-m-d'))
            ->getQuery();

        try {
            $lineVersions = $query->getResult();
        } catch (\Exception $e) {
            return null;
        }

        return $this->sortLineVersionsByNumber($lineVersions);
    }

    /**
     * findLastLineVersionOfLine
     *
     * @param int $lineId
     *
     * @return LineVersion or null
     *
     * Return the last version of LineVersion associated to the Line
     */
    public function findLastLineVersionOfLine($lineId)
    {
        $finalResult = null;

        if ($lineId == null) {
{'fraction_non_alphanumeric': 0.12187417741510924, 'fraction_numerical': 0.0018425901553040273, 'mean_word_length': 2.8, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 39, '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': '1531834', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1079, 'n_words': 226}