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

namespace App\Entity;

use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * User
 */
#[ORM\Table(name: 'user')]
#[ORM\Entity(repositoryClass: \App\Repository\UserRepository::class)]
#[UniqueEntity(fields: 'email', message: 'This email is already taken')]
#[UniqueEntity(fields: 'username', message: 'This name is already taken')]
class User implements UserInterface, PasswordAuthenticatedUserInterface, EquatableInterface
{
    #[ORM\Column]
    #[ORM\Id]
    #[ORM\GeneratedValue]
    private ?int $id = null;

    #[ORM\Column(name: 'username', type: 'string', length: 255, unique: true)]
    private string $username;

    #[ORM\Column(name: 'email', type: 'string', length: 255, unique: true)]
    #[Assert\Email]
    private string $email;

    #[ORM\Column(type: 'json')]
    private $roles = [];

    #[ORM\Column(type: 'string', length: 255)]
    protected $role;

    #[ORM\Column(name: 'change_passw_hash', type: 'string', length: 255, nullable: true)]
    protected $changePaswHash;

    #[ORM\Column(name: 'change_passw_valid_to', type: 'datetime', nullable: true)]
    protected DateTime $changePaswValidTo;

    #[ORM\Column(name: 'password', type: 'string', length: 255)]
    private string $password;

    #[ORM\Column(name: 'is_active', type: 'boolean')]
    private bool $isActive;

    #[ORM\JoinColumn(name: 'position_id', referencedColumnName: 'id')]
    #[ORM\ManyToOne(targetEntity: Position::class, inversedBy: 'users')]
    private ?Position $position;

    #[ORM\JoinColumn(name: 'academic_unit_id', referencedColumnName: 'id')]
    #[ORM\ManyToOne(targetEntity: AcademicUnit::class, inversedBy: 'users')]
    private ?AcademicUnit $academicUnit;

    #[ORM\JoinColumn(name: 'department_id', referencedColumnName: 'id')]
    #[ORM\ManyToOne(targetEntity: Department::class, inversedBy: 'users')]
    private ?Department $department;

    #[ORM\Column(name: 'google_id', type: 'string', length: 255, nullable: true)]
    protected ?string $googleId;

    #[ORM\Column(name: 'google_access_token', type: 'string', length: 255, nullable: true)]
    protected ?string $googleAccessToken;

    /**
     * @var Collection<int, FiveYearLecturerPlanApproval>
     */
    #[ORM\OneToMany(mappedBy: 'user', targetEntity: FiveYearLecturerPlanApproval::class)]
    private Collection $fiveYearLecturerPlanApprovals;

    public function __construct()
    {
        $this->isActive = true;
        $this->fiveYearLecturerPlanApprovals = new ArrayCollection();
    }

    public function getDepartment(): ?Department
    {
        return $this->department;
    }

    public function setDepartment(?Department $department): static
    {
        $this->department = $department;

        return $this;
    }

    public function getAcademicUnit(): ?AcademicUnit
    {
        return $this->academicUnit;
    }

    public function setAcademicUnit(?AcademicUnit $academicUnit): static
    {
        $this->academicUnit = $academicUnit;

        return $this;
    }

    public function getPosition(): ?Position
    {
        return $this->position;
    }

    public function setPosition(?Position $position): static
    {
        $this->position = $position;

        return $this;
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function setUsername(string $username): static
    {
        $this->username = $username;

        return $this;
    }

    public function getUsername(): ?string
    {
        return $this->username;
    }

    public function setEmail(string $email): static
    {
        $this->email = $email;

        return $this;
    }

    public function getEmail(): ?string
    {
        return $this->email;
    }

    public function setPassword(string $password): static
    {
        $this->password = $password;

        return $this;
    }

    public function getRoles(): array
    {
        return $this->roles;
    }

    public function eraseCredentials()
    {
    }

    public function getPassword(): ?string
    {
        return $this->password;
    }

    public function getSalt()
    {
    }

    public function getRole(): ?string
    {
        return $this->role;
    }

    public function setRole(string $role): static
    {
        $this->role = $role;
        $this->roles = [$role];

        return $this;
    }

    public function getChangePaswHash(): ?string
    {
        return $this->changePaswHash;
    }

    public function getChangePaswValidTo(): ?\DateTimeInterface
    {
        return $this->changePaswValidTo;
    }

    public function setChangePaswHash(?string $changePaswHash): static
    {
        $this->changePaswHash = $changePaswHash;

        return $this;
    }

    public function setChangePaswValidTo(?\DateTimeInterface $changePaswValidTo): static
    {
        $this->changePaswValidTo = $changePaswValidTo;

        return $this;
    }

    public function isAccountNonExpired()
    {
        return true;
    }

    public function isAccountNonLocked()
    {
        return true;
    }

    public function isCredentialsNonExpired()
    {
        return true;
    }

    public function isEnabled()
    {
        return $this->isActive;
    }

    public function getIsActive()
    {
        return $this->isActive;
    }

    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;
        return $this;
    }

    public function getGoogleId(): ?string
    {
        return $this->googleId;
    }

    public function setGoogleId(?string $googleId): static
    {
        $this->googleId = $googleId;

        return $this;
    }

    public function getGoogleAccessToken(): ?string
    {
        return $this->googleAccessToken;
    }

    public function setGoogleAccessToken(?string $googleAccessToken): static
    {
        $this->googleAccessToken = $googleAccessToken;

        return $this;
    }

    /**
     * @inheritDoc
     */
    public function getUserIdentifier(): string
    {
        return $this->email;
    }

    public function setRoles(array $roles): static
    {
        $this->roles = $roles;

        return $this;
    }

    public function isActive(): ?bool
    {
        return $this->isActive;
    }

    public function setActive(bool $isActive): static
    {
        $this->isActive = $isActive;

        return $this;
    }

    /**
     * @return Collection<int, FiveYearLecturerPlanApproval>
     */
    public function getFiveYearLecturerPlanApprovals(): Collection
    {
        return $this->fiveYearLecturerPlanApprovals;
    }

    public function addFiveYearLecturerPlanApproval(FiveYearLecturerPlanApproval $fiveYearLecturerPlanApproval): static
    {
        if (!$this->fiveYearLecturerPlanApprovals->contains($fiveYearLecturerPlanApproval)) {
            $this->fiveYearLecturerPlanApprovals->add($fiveYearLecturerPlanApproval);
            $fiveYearLecturerPlanApproval->setUser($this);
        }

        return $this;
    }

    public function removeFiveYearLecturerPlanApproval(FiveYearLecturerPlanApproval $fiveYearLecturerPlanApproval): static
    {
        if ($this->fiveYearLecturerPlanApprovals->removeElement($fiveYearLecturerPlanApproval)) {
            // set the owning side to null (unless already changed)
            if ($fiveYearLecturerPlanApproval->getUser() === $this) {
                $fiveYearLecturerPlanApproval->setUser(null);
            }
        }

        return $this;
    }

    public function isEqualTo(UserInterface $user): bool
    {
        if (!$user instanceof self) {
            return false;
        }

        if ($this->getPassword() !== $user->getPassword()) {
            return false;
        }

        $currentRoles = array_map('strval', (array) $this->getRoles());

        $newRoles = array_map('strval', (array) $user->getRoles());
        $rolesChanged = \count($currentRoles) !== \count($newRoles) || \count($currentRoles) !== \count(array_intersect($currentRoles, $newRoles));

        if ($rolesChanged) {
            return false;
        }

        if ($this->getUserIdentifier() !== $user->getUserIdentifier()) {
            return false;
        }

        if ($this->isEnabled() !== $user->isEnabled()) {
            return false;
        }

        return true;
    }
}