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/dvpis2026/dvpis.kaunokolegija.lt/src/Doctrine/LecturerFilter.php
<?php

namespace App\Doctrine;

use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Filter\SQLFilter;

class LecturerFilter extends SQLFilter
{
    private $column = 'id';

    public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias): string
    {

        if (!$this->checkEntityValid($targetEntity->getReflectionClass()->name)) {
            return '';
        }

        $notApproved = '';
        //2024-11-11 made changes, no idea why
//        if ($this->hasParameter('not_approved_plan')) {
//            $notApproved = $targetTableAlias . '.' . $this->column . ' NOT IN (
//            SELECT DISTINCT lecturer_id FROM lecturer_approved_activities WHERE isApproved = 1
//            ) AND ';
//        }

        if ($this->hasParameter('lecturer_id')) {
            return $notApproved . sprintf('%s.%s = %s', $targetTableAlias, $this->column, $this->getParameter('lecturer_id'));
        }

        if ($this->hasParameter('department_lecturer_id') && $this->hasParameter('department_id')) {
            return $notApproved . '(
                    SELECT l.id FROM lecturer l
                    WHERE 
                        l.id = ' . $targetTableAlias . '.' . $this->column . '
                        AND (l.department_id = ' . $this->getParameter('department_id') . ' OR l.id = ' . $this->getParameter('department_lecturer_id') . ')
                ) IS NOT NULL
            ';
        }

        if ($this->hasParameter('department_id')) {
//            return sprintf('%s.department_id = %s', $targetTableAlias, $this->getParameter('department_id'));
            return $notApproved . '(
                    SELECT l.id FROM lecturer l
                    WHERE l.id = ' . $targetTableAlias . '.' . $this->column . '
                    AND l.department_id = ' . $this->getParameter('department_id') . '
                ) IS NOT NULL
            ';
        }

        if ($this->hasParameter('academic_unit_id')) {
            return $notApproved . '(
                    SELECT l.id FROM lecturer l
                    INNER JOIN department dep ON l.department_id = dep.id
                    WHERE l.id = ' . $targetTableAlias . '.' . $this->column . '
                    AND dep.academic_unit_id = ' . $this->getParameter('academic_unit_id') . '
                ) IS NOT NULL
            ';
        }

        return '';
    }

    private function checkEntityValid($targetEntity)
    {

        switch ($targetEntity) {

            case 'App\Entity\KvmLecturer':
            case 'App\Entity\MeovLecturer':
            case 'App\Entity\TmmvLecturer':
            case 'App\Entity\Poll\AnswerRow':
                $this->column = 'lecturer_id';

                return true;
            case 'App\Entity\Lecturer':
                $this->column = 'id';

                return true;
        }

        return false;
    }
}