<?php

namespace AppBundle\Entity\AccessWish\Repository;

use AppBundle\Entity\Education\Education;
use AppBundle\Entity\Education\EducationCurriculum;
use AppBundle\Entity\HasItemQueryBuilderInterface;
use AppBundle\Entity\Organization\Organization;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;

/**
 * Description of EducationStudentWishRepository
 *
 */
class EducationStudentWishRepository extends EntityRepository
{

    public function getEducationStudentByEducation(Education $education,Organization $organization){
//        $education = $educationCurriculum->getEducation();
        $filter = $this->_em->getFilters()->enable('activity_year');
        $filter->setParameter('disabledFilter', 1);
        $queryBuilder = $this->createQueryBuilder('education_student_wish');
        $queryBuilder
            ->leftJoin('education_student_wish.accessWish','accessWish')
            ->leftJoin('education_student_wish.accessWishReregistrations','accessWishReregistrations')
            ->leftJoin('accessWish.organization','organization')
            ->leftJoin('accessWishReregistrations.organization','organization2')
            ->leftJoin('education_student_wish.educationWish','educationWish')
            ->leftJoin('accessWish.accessFamilyWish', 'accessWishAccessFamilyWish')
            ->leftJoin('accessWishReregistrations.accessFamilyWish', 'accessWishAccessFamilyWish2')
            ->andWhere('(educationWish.id=:education and organization.id=:organization and accessWishAccessFamilyWish.registrationCompleted =:registrationCompleted) or (educationWish.id=:education and organization2.id=:organization and accessWishAccessFamilyWish2.registrationCompleted =:registrationCompleted)')
            ->setParameter('organization', $organization)
            ->setParameter('education', $education)
            ->setParameter('registrationCompleted', true);

        $filter->setParameter('disabledFilter', 0);

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

}
