<commit_before><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace BrBundle\Repository;

use BrBundle\Entity\Collaborator as CollaboratorEntity,
    BrBundle\Entity\Company as CompanyEntity,
    CommonBundle\Component\Doctrine\ORM\EntityRepository;

/**
 * Contract
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class Contract extends EntityRepository
{
    /**
     * @param  int $id
     * @return int
     */
    public function findCurrentVersionNb($id)
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $highestVersionNb = $query->select('MAX(e.version)')
            ->from('BrBundle\Entity\Contract', 'c')
            ->innerjoin('c.contractEntries','e')
            ->where(
                $query->expr()->eq('c.id', ':id')
            )
            ->getQuery()
            ->setParameter('id', $id)
            ->getSingleScalarResult();

        return $highestVersionNb;
    }

    /**
     * @param  CollaboratorEntity $collaborator
     * @return int
     */
    public function findNextContractNbByCollaborator(CollaboratorEntity $collaborator)
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $highestContractNb = $query->select('MAX(c.contractNb)')
            ->from('BrBundle\Entity\Contract', 'c')
            ->innerjoin('c.order','o')
            ->where(
                $query->expr()->andX(
                    $query->expr()->eq('c.author', ':person'),
                    $query->expr()->eq('o.old', 'false')
                )
            )
            ->setParameter('person', $collaborator)
            ->getQuery()
            ->getSingleScalarResult();

        return (int) ++$highestContractNb;
    }

    /**
     * @param  CollaboratorEntity                           $person
     * @return \Doctrine\Common\Collections\ArrayCollection
     */
    public function findAllNewOrSignedByPerson(CollaboratorEntity $person)
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $result = $query->select('c')
            ->from('BrBundle\Entity\Contract', 'c')
            ->innerjoin('c.order','o')
            ->where(<commit_msg>small fix<commit_after><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace BrBundle\Repository;

use BrBundle\Entity\Collaborator as CollaboratorEntity,
    BrBundle\Entity\Company as CompanyEntity,
    CommonBundle\Component\Doctrine\ORM\EntityRepository;

/**
 * Contract
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class Contract extends EntityRepository
{
    /**
     * @param  int $id
     * @return int
     */
    public function findCurrentVersionNb($id)
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $highestVersionNb = $query->select('MAX(e.version)')
            ->from('BrBundle\Entity\Contract', 'c')
            ->innerjoin('c.contractEntries','e')
            ->where(
                $query->expr()->eq('c.id', ':id')
            )
            ->getQuery()
            ->setParameter('id', $id)
            ->getSingleScalarResult();

        return $highestVersionNb;
    }

    /**
     * @param  CollaboratorEntity $collaborator
     * @return int
     */
    public function findNextContractNbByCollaborator(CollaboratorEntity $collaborator)
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $highestContractNb = $query->select('MAX(c.contractNb)')
            ->from('BrBundle\Entity\Contract', 'c')
            ->innerjoin('c.order','o')
            ->where(
                $query->expr()->eq('c.author', ':person')
            )
            ->setParameter('person', $collaborator)
            ->getQuery()
            ->getSingleScalarResult();

        return (int) ++$highestContractNb;
    }

    /**
     * @param  CollaboratorEntity                           $person
     * @return \Doctrine\Common\Collections\ArrayCollection
     */
    public function findAllNewOrSignedByPerson(CollaboratorEntity $person)
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $result = $query->select('c')
            ->from('BrBundle\Entity\Contract', 'c')
            ->innerjoin('c.order','o')
            ->where(
{'fraction_non_alphanumeric': 0.15758384146341464, 'fraction_numerical': 0.0, 'mean_word_length': 2.406229720960415, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 129, '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': '3002456', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1517, 'n_words': 325}