src/Entity/Role.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use DateTimeInterface;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation as SA;
  7. /**
  8.  * Role
  9.  *
  10.  * @ORM\Table(name="roles", indexes={@ORM\Index(name="user_id", columns={"user_id", "status"}), @ORM\Index(name="IDX_B192D4EEA76ED395", columns={"user_id"}), @ORM\Index(name="IDX_B192D4EE9B6B5FBA", columns={"account_id"})})
  11.  * @ORM\Entity
  12.  */
  13. class Role extends Entity
  14. {
  15.     public const ROLES = [
  16.         'owner' => 'owner'
  17.     ];
  18.     /**
  19.      * @var int
  20.      *
  21.      * @SA\Ignore
  22.      * @ORM\Column(name="id", type="bigint", nullable=false, options={"unsigned"=true})
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue(strategy="IDENTITY")
  25.      * @SA\Groups({"read", "list"})
  26.      */
  27.     private $id;
  28.     /**
  29.      * @var string
  30.      *
  31.      * @ORM\Column(name="type", type="string", length=255, nullable=false)
  32.      * @SA\Groups({"read", "list"})
  33.      */
  34.     private $type;
  35.     /**
  36.      * @var DateTime
  37.      *
  38.      * @ORM\Column(name="created", type="datetime", nullable=false, options={"default"="CURRENT_TIMESTAMP"})
  39.      * @SA\Groups({"read", "list"})
  40.      */
  41.     private $created null;
  42.     /**
  43.      * @var string
  44.      *
  45.      * @ORM\Column(name="status", type="string", length=0, nullable=false, options={"default"="inactive"})
  46.      * @SA\Ignore()
  47.      */
  48.     private $status self::STATUS['inactive'];
  49.     /**
  50.      * @var User
  51.      *
  52.      * @ORM\ManyToOne(targetEntity="User", inversedBy="roles")
  53.      * @ORM\JoinColumns({
  54.      *   @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  55.      * })
  56.      * @SA\Ignore()
  57.      */
  58.     private $user;
  59.     /**
  60.      * @var Account
  61.      *
  62.      * @ORM\ManyToOne(targetEntity="Account", inversedBy="roles")
  63.      * @ORM\JoinColumns({
  64.      *   @ORM\JoinColumn(name="account_id", referencedColumnName="id")
  65.      * })
  66.      * @SA\Ignore()
  67.      */
  68.     private $account;
  69.     public function __construct(Account $accountUser $user, ?string $type null, ?string $status null)
  70.     {
  71.         $this->created = new DateTime();
  72.         $account->addRole($this);
  73.         $user->addRole($this);
  74.         $this->type $type ?? self::ROLES['owner'];
  75.         $this->status $status ?? self::STATUS['active'];
  76.     }
  77.     public function getId(): ?int
  78.     {
  79.         return $this->id;
  80.     }
  81.     public function getType(): ?string
  82.     {
  83.         return $this->type;
  84.     }
  85.     public function setType(string $type): self
  86.     {
  87.         $this->type $type;
  88.         return $this;
  89.     }
  90.     public function getCreated(): ?DateTimeInterface
  91.     {
  92.         return $this->created;
  93.     }
  94.     public function setCreated(DateTimeInterface $created): self
  95.     {
  96.         $this->created $created;
  97.         return $this;
  98.     }
  99.     public function getStatus(): ?string
  100.     {
  101.         return $this->status;
  102.     }
  103.     public function setStatus(string $status): self
  104.     {
  105.         $this->status $status;
  106.         return $this;
  107.     }
  108.     public function getUser(): ?User
  109.     {
  110.         return $this->user;
  111.     }
  112.     public function setUser(?User $user): self
  113.     {
  114.         $this->user $user;
  115.         return $this;
  116.     }
  117.     public function getAccount(): ?Account
  118.     {
  119.         return $this->account;
  120.     }
  121.     public function setAccount(?Account $account): self
  122.     {
  123.         $this->account $account;
  124.         return $this;
  125.     }
  126. }