src/Entity/PortalAdministrator.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PortalAdministratorRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. #[ORM\Entity(repositoryClassPortalAdministratorRepository::class)]
  10. class PortalAdministrator implements UserInterfacePasswordAuthenticatedUserInterface
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length180uniquetrue)]
  17.     private ?string $username null;
  18.     #[ORM\Column]
  19.     private array $roles = [];
  20.     /**
  21.      * @var string The hashed password
  22.      */
  23.     #[ORM\Column]
  24.     private ?string $password null;
  25.     #[ORM\ManyToOne(inversedBy'portalAdministrators')]
  26.     private ?Corporation $corporation null;
  27.     #[ORM\Column]
  28.     private ?bool $mainUser null;
  29.     #[ORM\ManyToOne(inversedBy'portalAdministrators'cascade: ['persist'])]
  30.     private ?Department $department null;
  31.     #[ORM\ManyToOne(inversedBy'portalAdministrators')]
  32.     private ?Portal $portal null;
  33.     #[ORM\Embedded(class: UserInformation::class)]
  34.     private UserInformation $userInformation;
  35.     #[ORM\ManyToMany(targetEntityPortalAdministratorGroup::class, mappedBy'portalAdministrators')]
  36.     private Collection $portalAdministratorGroups;
  37.     #[ORM\OneToMany(mappedBy'portalAdmin'targetEntityCourse::class)]
  38.     private Collection $courses;
  39.     #[ORM\OneToMany(mappedBy'adminSender'targetEntityMessage::class)]
  40.     private Collection $messages;
  41.     public function __construct()
  42.     {
  43.         $this->userInformation = new UserInformation();
  44.         $this->userInformation->setCreatedAt(new \DateTimeImmutable());
  45.         $this->portalAdministratorGroups = new ArrayCollection();
  46.         $this->courses = new ArrayCollection();
  47.         $this->messages = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function __toString(): string
  54.     {
  55.        return $this->getUserInformation()->getFirstName().' '.$this->getUserInformation()->getLastName();
  56.     }
  57.     public function getUsername(): ?string
  58.     {
  59.         return $this->username;
  60.     }
  61.     public function setUsername(string $username): self
  62.     {
  63.         $this->username $username;
  64.         return $this;
  65.     }
  66.     /**
  67.      * A visual identifier that represents this user.
  68.      *
  69.      * @see UserInterface
  70.      */
  71.     public function getUserIdentifier(): string
  72.     {
  73.         return (string)$this->username;
  74.     }
  75.     /**
  76.      * @see UserInterface
  77.      */
  78.     public function getRoles(): array
  79.     {
  80.         $roles $this->roles;
  81.         // guarantee every user at least has ROLE_USER
  82.         $roles[] = 'ROLE_USER';
  83.         return array_unique($roles);
  84.     }
  85.     public function setRoles(array $roles): self
  86.     {
  87.         $this->roles $roles;
  88.         return $this;
  89.     }
  90.     /**
  91.      * @see PasswordAuthenticatedUserInterface
  92.      */
  93.     public function getPassword(): string
  94.     {
  95.         return $this->password;
  96.     }
  97.     public function setPassword(string $password): self
  98.     {
  99.         $this->password $password;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @see UserInterface
  104.      */
  105.     public function eraseCredentials()
  106.     {
  107.         // If you store any temporary, sensitive data on the user, clear it here
  108.         // $this->plainPassword = null;
  109.     }
  110.     public function getCorporation(): ?Corporation
  111.     {
  112.         return $this->corporation;
  113.     }
  114.     public function setCorporation(?Corporation $corporation): self
  115.     {
  116.         $this->corporation $corporation;
  117.         return $this;
  118.     }
  119.     public function isMainUser(): ?bool
  120.     {
  121.         return $this->mainUser;
  122.     }
  123.     public function setMainUser(bool $mainUser): self
  124.     {
  125.         $this->mainUser $mainUser;
  126.         return $this;
  127.     }
  128.     public function getDepartment(): ?Department
  129.     {
  130.         return $this->department;
  131.     }
  132.     public function setDepartment(?Department $department): self
  133.     {
  134.         $this->department $department;
  135.         return $this;
  136.     }
  137.     public function getPortal(): ?Portal
  138.     {
  139.         return $this->portal;
  140.     }
  141.     public function setPortal(?Portal $portal): self
  142.     {
  143.         $this->portal $portal;
  144.         return $this;
  145.     }
  146.     public function getUserInformation(): UserInformation
  147.     {
  148.         return $this->userInformation;
  149.     }
  150.     /**
  151.      * @return Collection<int, PortalAdministratorGroup>
  152.      */
  153.     public function getPortalAdministratorGroups(): Collection
  154.     {
  155.         return $this->portalAdministratorGroups;
  156.     }
  157.     public function addPortalAdministratorGroup(PortalAdministratorGroup $portalAdministratorGroup): self
  158.     {
  159.         if (!$this->portalAdministratorGroups->contains($portalAdministratorGroup)) {
  160.             $this->portalAdministratorGroups->add($portalAdministratorGroup);
  161.             $portalAdministratorGroup->addPortalAdministrator($this);
  162.         }
  163.         return $this;
  164.     }
  165.     public function removePortalAdministratorGroup(PortalAdministratorGroup $portalAdministratorGroup): self
  166.     {
  167.         if ($this->portalAdministratorGroups->removeElement($portalAdministratorGroup)) {
  168.             $portalAdministratorGroup->removePortalAdministrator($this);
  169.         }
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return Collection<int, Course>
  174.      */
  175.     public function getCourses(): Collection
  176.     {
  177.         return $this->courses;
  178.     }
  179.     public function addCourse(Course $course): self
  180.     {
  181.         if (!$this->courses->contains($course)) {
  182.             $this->courses->add($course);
  183.             $course->setPortalAdmin($this);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeCourse(Course $course): self
  188.     {
  189.         if ($this->courses->removeElement($course)) {
  190.             // set the owning side to null (unless already changed)
  191.             if ($course->getPortalAdmin() === $this) {
  192.                 $course->setPortalAdmin(null);
  193.             }
  194.         }
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return Collection<int, Message>
  199.      */
  200.     public function getMessages(): Collection
  201.     {
  202.         return $this->messages;
  203.     }
  204.     public function addMessage(Message $message): self
  205.     {
  206.         if (!$this->messages->contains($message)) {
  207.             $this->messages->add($message);
  208.             $message->setAdminSender($this);
  209.         }
  210.         return $this;
  211.     }
  212.     public function removeMessage(Message $message): self
  213.     {
  214.         if ($this->messages->removeElement($message)) {
  215.             // set the owning side to null (unless already changed)
  216.             if ($message->getAdminSender() === $this) {
  217.                 $message->setAdminSender(null);
  218.             }
  219.         }
  220.         return $this;
  221.     }
  222. }