src/Entity/PointConversionRate.php line 21

Open in your IDE?
  1. <?php
  2.     namespace App\Entity;
  3.     use App\Repository\PointConversionRateRepository;
  4.     use App\Traits\DateTrait;
  5.     use Doctrine\Common\Collections\ArrayCollection;
  6.     use Doctrine\Common\Collections\Collection;
  7.     use Doctrine\ORM\Mapping as ORM;
  8.     use JMS\Serializer\Annotation as Serializer;
  9.     use JMS\Serializer\Annotation\Expose;
  10.     use JMS\Serializer\Annotation\Groups;
  11.     use JMS\Serializer\Annotation\SerializedName;
  12.     use JMS\Serializer\Annotation\VirtualProperty;
  13.     /**
  14.      * @ORM\Entity(repositoryClass=PointConversionRateRepository::class)
  15.      * @ORM\HasLifecycleCallbacks()
  16.      * @Serializer\ExclusionPolicy("ALL")
  17.      */
  18.     class PointConversionRate
  19.     {
  20.         /**
  21.          * @ORM\Id
  22.          * @ORM\GeneratedValue
  23.          * @ORM\Column(type="integer")
  24.          *
  25.          * @Expose
  26.          * @Groups({"point_conversion_rate"})
  27.          */
  28.         private ?int $id NULL;
  29.         /**
  30.          * @ORM\Column(type="string", length=128)
  31.          *
  32.          * @Expose
  33.          * @Groups({"point_conversion_rate"})
  34.          */
  35.         private ?string $label NULL;
  36.         /**
  37.          * @ORM\Column(type="float")
  38.          *
  39.          * @Expose
  40.          * @Groups({"point_conversion_rate"})
  41.          */
  42.         private ?float $rate NULL;
  43.         /**
  44.          * @ORM\ManyToOne(targetEntity=User::class, inversedBy="ownerPointConversionRates")
  45.          * @ORM\JoinColumn(nullable=false)
  46.          *
  47.          * @Expose
  48.          * @Groups({"point_conversion_rate"})
  49.          */
  50.         private ?User $owner NULL;
  51.         /**
  52.          * @ORM\OneToMany(targetEntity=User::class, mappedBy="pointConversionRate")
  53.          */
  54.         private Collection $users;
  55.         use DateTrait;
  56.         public function __construct()
  57.         {
  58.             $this->users = new ArrayCollection();
  59.         }
  60.         public function getId(): ?int
  61.         {
  62.             return $this->id;
  63.         }
  64.         public function getLabel(): ?string
  65.         {
  66.             return $this->label;
  67.         }
  68.         public function setLabel(string $label): self
  69.         {
  70.             $this->label $label;
  71.             return $this;
  72.         }
  73.         public function getRate(): ?float
  74.         {
  75.             return $this->rate;
  76.         }
  77.         public function setRate(float $rate): self
  78.         {
  79.             $this->rate $rate;
  80.             return $this;
  81.         }
  82.         public function getOwner(): ?User
  83.         {
  84.             return $this->owner;
  85.         }
  86.         public function setOwner(?User $owner): self
  87.         {
  88.             $this->owner $owner;
  89.             return $this;
  90.         }
  91.         /**
  92.          * @return Collection<int, User>
  93.          */
  94.         public function getUsers(): Collection
  95.         {
  96.             return $this->users;
  97.         }
  98.         public function addUser(User $user): self
  99.         {
  100.             if (!$this->users->contains($user)) {
  101.                 $this->users[] = $user;
  102.                 $user->setPointConversionRate($this);
  103.             }
  104.             return $this;
  105.         }
  106.         public function removeUser(User $user): self
  107.         {
  108.             if ($this->users->removeElement($user)) {
  109.                 // set the owning side to null (unless already changed)
  110.                 if ($user->getPointConversionRate() === $this) {
  111.                     $user->setPointConversionRate(NULL);
  112.                 }
  113.             }
  114.             return $this;
  115.         }
  116.         /**
  117.          * @return int
  118.          *
  119.          * @VirtualProperty
  120.          * @SerializedName("count_users")
  121.          *
  122.          * @Expose
  123.          * @Groups({"point_conversion_rate"})
  124.          */
  125.         public function countUsers(): int
  126.         {
  127.             return count($this->users);
  128.         }
  129.     }