<?php
declare(strict_types=1);

namespace App\Repository\Education;

use App\Entity\Education\EducationNotation;
use App\Entity\Organization\Organization;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

class EducationNotationRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, EducationNotation::class);
    }

    /**
     * Permet de récupérer toutes les évaluations d'une structure sans tenir compte de l'année des education student
     * @param Organization $organization
     * @return array|int|mixed|string
     */
    public function findAllEducationNotation(Organization $organization){
        $this->_em->getFilters()->disable('activity_year_filter');

        $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->getId())
        ;

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

        $this->_em->getFilters()->enable('activity_year_filter');
        return $results;
    }
}