src/Database/Domain/Entity/Sessions/ActiveSessions/ActiveSession.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Database\Domain\Entity\Sessions\ActiveSessions;
  3. use App\Database\Domain\Entity\AbstractEntity;
  4. use App\Database\Domain\Entity\User\User;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity()
  10.  */
  11. class ActiveSession extends AbstractEntity
  12. {
  13.     /**
  14.      * @ORM\OneToOne(targetEntity="App\Database\Domain\Entity\User\User")
  15.      *
  16.      * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="write_rare")
  17.      *
  18.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  19.      */
  20.     private User $user;
  21.     /**
  22.      * @ORM\OneToMany(targetEntity="App\Database\Domain\Entity\Sessions\ActiveSessions\ActiveDevice", mappedBy="session", fetch="EXTRA_LAZY", cascade={"all"})
  23.      *
  24.      * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="write_rare")
  25.      *
  26.      * @var Collection<int, ActiveDevice>
  27.      */
  28.     private Collection $devices;
  29.     public function __construct($idUser $user)
  30.     {
  31.         $this->id $id;
  32.         $this->user $user;
  33.         $this->devices = new ArrayCollection();
  34.     }
  35.     public function getUser(): User
  36.     {
  37.         return $this->user;
  38.     }
  39.     /**
  40.      * @return ActiveDevice[]
  41.      */
  42.     public function getDevices(): Collection
  43.     {
  44.         return $this->devices;
  45.     }
  46.     public function addDevice(ActiveDevice $device): void
  47.     {
  48.         if (!$this->devices->contains($device)) {
  49.             $this->devices->add($device);
  50.         }
  51.     }
  52. }