<?php

namespace AppBundle\Entity\Education\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * Description of EducationNotationRepository
 *
 */
class EducationNotationRepository extends EntityRepository
{
    public function findAllEducationNotation($organization_id)
    {
        $filter = $this->_em->getFilters()->enable('activity_year');
        $filter->setParameter('disabledFilter', 1);

        $queryBuilder =
            $this->createQueryBuilder('education_notation');
            $queryBuilder
                ->select('education_notation')
                ->innerJoin('education_notation.educationStudent','educationStudent')
                ->innerJoin('educationStudent.access','access')
                ->innerJoin('access.organization','organization')
                ->andWhere('organization.id=:organization_id')
                ->setParameter('organization_id', $organization_id)
        ;

        $query = $queryBuilder->getQuery();
        $results = $query->getResult();

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

        return $results;
    }

    public function findAllEducationNotationByEducationCurriculum($educationCurriculumId){
        $queryBuilder =
            $this->createQueryBuilder('education_notation');
        $queryBuilder
            ->innerJoin('education_notation.educationStudent','educationStudent')
            ->innerJoin('educationStudent.educationCurriculum','educationCurriculum')
            ->andWhere('educationCurriculum.id = :education_curriculum_id')
            ->andWhere('education_notation.criteriaNotationConfig is not null')
            ->setParameter('education_curriculum_id', $educationCurriculumId)
        ;

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

    public function findAllEducationNotationByTeacher($teacherId){
        $queryBuilder =
            $this->createQueryBuilder('education_notation');
        $queryBuilder
            ->innerJoin('education_notation.educationStudent','educationStudent')
            ->innerJoin('educationStudent.teachers','teachers')
            ->andWhere($queryBuilder->expr()->in('teachers.id', ':teachers_id'))
            ->andWhere('education_notation.criteriaNotationConfig is not null')
            ->setParameter('teachers_id', $teacherId)
        ;

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