<?php

namespace AppBundle\Entity\Education\Repository;

use AppBundle\Entity\AccessAndFunction\Access;
use AppBundle\Entity\Education\Education;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityRepository;

/**
 * Description of EducationNotationRepository
 *
 */
class EducationNotationConfigRepository extends EntityRepository
{
    /**
     * @param Education $education
     * @return mixed
     */
    public function findAllEducationNotationConfigByEducationCurriculum($organization, $educationCurriculumId)
    {
        $queryBuilder =
            $this->createQueryBuilder('education_notation_config');
            $queryBuilder
                ->innerJoin('education_notation_config.educationCurriculums','educationCurriculums')
                ->andWhere('education_notation_config.isActive = :isActive')
                ->andWhere($queryBuilder->expr()->in('educationCurriculums.id', ':education_curriculum_id'))
                ->andWhere('education_notation_config.organization = :organization')
                ->setParameter('isActive', true)
                ->setParameter('education_curriculum_id', $educationCurriculumId)
                ->setParameter('organization', $organization)
            ;

        $query = $queryBuilder->getQuery();
        return $query->getOneOrNullResult();
    }

    /**
     * @param ArrayCollection<Access> $teachers
     * @return mixed
     */
    public function findAllEducationNotationConfigByTeachers($organization, $teachers_id)
    {
        $queryBuilder =
            $this->createQueryBuilder('education_notation_config');
        $queryBuilder
            ->innerJoin('education_notation_config.teachers','teachers')
            ->andWhere('education_notation_config.isActive = :isActive')
            ->andWhere($queryBuilder->expr()->in('teachers.id', ':teachers_id'))
            ->andWhere('education_notation_config.organization = :organization')
            ->setParameter('isActive', true)
            ->setParameter('teachers_id', $teachers_id)
            ->setParameter('organization', $organization)
        ;
        $query = $queryBuilder->getQuery();
        return $query->getOneOrNullResult();
    }
}

?>
