HEX
Server: Apache
System: Linux WWW 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64
User: web11 (1011)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/dvpis2025/dvpis.kaunokolegija.lt/src/Repository/LecturerAgreementRepository.php
<?php

namespace App\Repository;

use App\Entity\LecturerAgreement;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 *
 * @method LecturerAgreement|null find($id, $lockMode = null, $lockVersion = null)
 * @method LecturerAgreement|null findOneBy(array $criteria, array $orderBy = null)
// * @method LecturerAgreement[]    findAll()
 * @method LecturerAgreement[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class LecturerAgreementRepository extends EntityRepository
{

    public function findAll(): array
    {
        return $this->getEntityManager()
            ->createQuery("
                SELECT la, l, d, au
                FROM App:LecturerAgreement la
                JOIN la.lecturerPosition lp
                JOIN la.lecturer l
                JOIN l.department d
                JOIN d.academicUnit au
                WHERE lp.isForPlan = 1
                ORDER BY l.name ASC
            ")
            ->getResult()
        ;
    }

    public function findAllFilter(): array
    {
        return $this->getEntityManager()
            ->createQuery("
                SELECT la, l, d, au
                FROM App:LecturerAgreement la
                JOIN la.lecturerPosition lp
                JOIN la.lecturer l
                JOIN l.department d
                JOIN d.academicUnit au
                WHERE lp.isForPlan = 1
                    AND la.contractTo > DATE_ADD(la.contractFrom, 1, 'YEAR')
                ORDER BY l.name ASC
            ")
            ->getResult()
        ;
    }

    public function findAllIndexedById(): array
    {
        $items = $this->findBy([]);
        $indexed = [];
        foreach ($items as $item) {
            $indexed[$item->getId()] = $item;
        }
        return $indexed;
    }

    public function findAllForReport(): array
    {
        return $this->getEntityManager()
            ->createQuery("
                SELECT la, l, d, au
                FROM App:LecturerAgreement la
                JOIN la.lecturerPosition lp
                JOIN la.lecturer l
                JOIN l.department d
                JOIN d.academicUnit au
                
                ORDER BY l.name ASC
            ")
            ->getResult()
        ;
    }

    public function deleteAll()
    {
        return $this->getEntityManager()
            ->createQuery(
                "DELETE App:LecturerAgreement l"
            )
            ->execute();
    }
}