<?php

namespace AppBundle\Entity\Booking\Repository;

use Doctrine\ORM\EntityRepository;
use Recurr\Rule;
use Recurr\Transformer\ArrayTransformer;
use Recurr\Transformer\Constraint\BetweenConstraint;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Dunglas\ApiBundle\Api\ResourceInterface;
use Symfony\Component\HttpFoundation\Request;

class EducationalProjectRepository extends EntityRepository {

    public function searchByIntervenants($teachersIds, $dateStart, $dateEnd, $organization) {

        $queryBuilder= $this->createQueryBuilder('o')
            ->andWhere('o.organization=:org')
            ->andWhere('(o.datetimeStart BETWEEN :dateStart AND :dateEnd)')
            ->leftjoin('o.public','pub')
            ->addselect('pub')
            ->leftjoin('o.silentPartner','sil')
            ->addselect('sil')
            ->leftjoin('o.intervenants', 'int')
            ->addselect('int')
            ->leftjoin('o.addressPostal', 'add')
            ->addselect('add')
            ->andWhere('int.id IN (:int)')
            ->leftjoin('o.ageDistribution', 'age')
            ->addselect('age')
            ->leftjoin('o.eventRecur', 'er')
            ->addselect('er')
            ->setParameters([
                ':org' => $organization,
                ':int' => $teachersIds,
                ':dateStart'=>new \DateTime($dateStart),
                ':dateEnd'=> new \DateTime($dateEnd)
            ]);

        return $queryBuilder->getQuery()->getResult();
    }
}
