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/UserRepository.php
<?php

namespace App\Repository;

use App\Entity\User;
use DateTime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * UserRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class UserRepository extends ServiceEntityRepository implements UserLoaderInterface
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, User::class);
    }

    /**
     * @throws NonUniqueResultException
     */
    public function loadUserByUsername($username)
    {
        return $this->createQueryBuilder('u')
                        ->where('u.username = :username OR u.email = :email')
                        ->setParameter(':username', $username)
                        ->setParameter(':email', $username)
                        ->getQuery()
                        ->getOneOrNullResult();
    }

    /**
     * @throws NonUniqueResultException
     */
    public function loadUserByHash($hash)
    {
        $date = new DateTime();
        return $this->createQueryBuilder('u')
                        ->where('u.changePaswHash = :hash AND u.changePaswValidTo >= :datetime')
                        ->setParameter(':hash', $hash)
                        ->setParameter(':datetime', $date)
                        ->getQuery()
                        ->getOneOrNullResult();
    }

    public function getDepartmentLecturers($department)
    {
        $newerCriteria = Criteria::create()
                ->where(Criteria::expr()->gt("department", $department));

        return $this->getDepartment()->getLecturers()->matching($newerCriteria);
    }

    /**
     * @inheritDoc
     * @throws NonUniqueResultException
     */
    public function loadUserByIdentifier(string $identifier): ?UserInterface
    {
        $entityManager = $this->getEntityManager();

        return $entityManager->createQuery(
            'SELECT u
                FROM App\Entity\User u
                WHERE u.username = :query
                OR u.email = :query'
        )
            ->setParameter('query', $identifier)
            ->getOneOrNullResult()
        ;
    }
}