File: /var/www/dvpis2025/dvpis.kaunokolegija.lt/src/Repository/LecturerRepository.php
<?php
namespace App\Repository;
use Doctrine\ORM\EntityRepository;
/**
* LecturerRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class LecturerRepository extends EntityRepository
{
public function getAllByEmail()
{
return $this->getEntityManager()
->createQuery("
SELECT l
FROM App:Lecturer l INDEX BY l.email
ORDER BY l.email ASC
")
->getResult();
}
public function getAllByID()
{
return $this->getEntityManager()
->createQuery(
"SELECT l
FROM App:Lecturer l INDEX BY l.id
ORDER BY l.email ASC"
)
->getResult()
;
}
public function getAllBySurnameName()
{
$results = $this->getEntityManager()
->createQuery(
"SELECT l
FROM App:Lecturer l
ORDER BY l.surname, l.name ASC"
)
->getResult();
$return = [];
foreach ($results as $result) {
$return[trim($result->getSurname()) . " " . trim($result->getName())] = $result;
}
return $return;
}
public function getAllWithoutUser()
{
return $this->getEntityManager()
->createQuery(
"SELECT l
FROM App:Lecturer l
LEFT JOIN App:User u WITH l.email = u.email
WHERE u.id IS NULL
ORDER BY l.email ASC"
)
->getResult();
}
public function findAllFilter()
{
return $this->getEntityManager()
->createQuery(
"SELECT l, d , au, lp
FROM App:Lecturer l
JOIN l.department d
JOIN d.academicUnit au
LEFT JOIN l.lecturerPosition lp
ORDER BY l.surname "
)
->getResult();
}
public function findAllByFilter($filter = [])
{
$query = $this->createQueryBuilder('l')
->leftJoin('l.department', 'd')
->join('d.academicUnit', 'au')
->select('l, d, au');
if (!empty($filter)) {
if (!empty($filter->get('academicUnit'))) {
$query->andWhere('au.id = :auid');
$query->setParameter(':auid', $filter->get('academicUnit'));
}
if (!empty($filter->get('department'))) {
$query->andWhere('d.id = :did');
$query->setParameter(':did', $filter->get('department'));
}
}
return $query->getQuery()->getResult();
}
public function deleteAll()
{
return $this->getEntityManager()
->createQuery(
"DELETE App:Lecturer l"
)
->execute();
}
}