src/Entity/PhoneNumber.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Constants\ActiveConstants;
  4. use App\Constants\OrderStatusConstants;
  5. use App\Constants\PageTypeConstant;
  6. use App\Repository\PhoneNumberRepository;
  7. use App\Traits\ActivityTrait;
  8. use App\Traits\TimeTrackTrait;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\DBAL\Types\Types;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. #[ORM\Entity(repositoryClassPhoneNumberRepository::class)]
  15. #[ORM\HasLifecycleCallbacks]
  16. #[ORM\UniqueConstraint(columns: ['number'])]
  17. class PhoneNumber
  18. {
  19.     use TimeTrackTrait;
  20.     use ActivityTrait;
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column]
  24.     private ?int $id null;
  25.     #[Assert\NotNull]
  26.     #[Assert\NotBlank]
  27.     #[ORM\Column(length191)]
  28.     private ?string $number null;
  29.     #[Assert\NotNull]
  30.     #[Assert\NotBlank]
  31.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  32.     private ?string $iccsd null;
  33.     #[Assert\NotNull]
  34.     #[Assert\NotBlank]
  35.     #[ORM\Column(length191nullabletrue)]
  36.     private ?string $pin null;
  37.     private bool $lockedByUser false;
  38.     #[Assert\NotNull]
  39.     #[Assert\NotBlank]
  40.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  41.     private ?string $qrUrl null;
  42.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  43.     private ?\DateTimeInterface $unfreezeTime null;
  44.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'lockedPhones')]
  45.     #[ORM\JoinColumn(name'id_locked_user'nullabletrueonDelete'SET NULL')]
  46.     private ?User $lockedUser null;
  47.     #[Assert\NotNull]
  48.     #[Assert\NotBlank]
  49.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  50.     private ?\DateTimeInterface $expireDate null;
  51.     #[Assert\NotNull]
  52.     #[ORM\ManyToOne(inversedBy'phoneNumbers')]
  53.     #[ORM\JoinColumn(nullablefalse)]
  54.     private ?Operator $operator null;
  55.     #[ORM\ManyToOne(inversedBy'phoneNumbers')]
  56.     private ?User $user null;
  57.     #[ORM\OneToMany(mappedBy'phoneNumber'targetEntityOrder::class)]
  58.     private $orders;
  59.     #[Assert\NotNull(message'Тариф не знайдено')]
  60.     #[ORM\ManyToOne(targetEntityTariff::class, inversedBy'phoneNumbers')]
  61.     #[ORM\JoinColumn(nullabletrue)]
  62.     private ?Tariff $tariff null;
  63.     public function __construct()
  64.     {
  65.         $this->orders = new ArrayCollection();
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getNumber(): ?string
  72.     {
  73.         return $this->number;
  74.     }
  75.     public function setNumber(string $number): static
  76.     {
  77.         $this->number $number;
  78.         return $this;
  79.     }
  80.     public function getBalance(): ?float
  81.     {
  82.         return $this->balance;
  83.     }
  84.     public function setBalance(float $balance): static
  85.     {
  86.         $this->balance $balance;
  87.         return $this;
  88.     }
  89.     public function getUnfreezeTime(): ?\DateTimeInterface
  90.     {
  91.         return $this->unfreezeTime;
  92.     }
  93.     public function setUnfreezeTime(?\DateTimeInterface $unfreezeTime): static
  94.     {
  95.         $this->unfreezeTime $unfreezeTime;
  96.         return $this;
  97.     }
  98.     public function lockPhoneNumber(User $user$period PageTypeConstant::LOCK_PHONE_NUMBER_PERIOD): static
  99.     {
  100.         $now = new \DateTime();
  101.         $this->setLockedUser($user);
  102.         $now->modify("+{$period} minutes");
  103.         $this->setUnfreezeTime($now);
  104.         return $this;
  105.     }
  106.     public function getOperator(): ?Operator
  107.     {
  108.         return $this->operator;
  109.     }
  110.     public function setOperator(?Operator $operator): static
  111.     {
  112.         $this->operator $operator;
  113.         return $this;
  114.     }
  115.     public function getUser(): ?User
  116.     {
  117.         return $this->user;
  118.     }
  119.     public function setUser(?User $user): static
  120.     {
  121.         $this->user $user;
  122.         return $this;
  123.     }
  124.     /**
  125.      * Set createdAt.
  126.      *
  127.      * @param \DateTime|null $createdAt
  128.      *
  129.      * @return PhoneNumber
  130.      */
  131.     public function setCreatedAt($createdAt null)
  132.     {
  133.         $this->createdAt $createdAt;
  134.         return $this;
  135.     }
  136.     /**
  137.      * Get createdAt.
  138.      *
  139.      * @return \DateTime|null
  140.      */
  141.     public function getCreatedAt()
  142.     {
  143.         return $this->createdAt;
  144.     }
  145.     /**
  146.      * Set updatedAt.
  147.      *
  148.      * @param \DateTime|null $updatedAt
  149.      *
  150.      * @return PhoneNumber
  151.      */
  152.     public function setUpdatedAt($updatedAt null)
  153.     {
  154.         $this->updatedAt $updatedAt;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Get updatedAt.
  159.      *
  160.      * @return \DateTime|null
  161.      */
  162.     public function getUpdatedAt()
  163.     {
  164.         return $this->updatedAt;
  165.     }
  166.     public function getTariff(): ?Tariff
  167.     {
  168.         return $this->tariff;
  169.     }
  170.     public function setTariff(?Tariff $tariff): static
  171.     {
  172.         $this->tariff $tariff;
  173.         return $this;
  174.     }
  175.     public function getPin(): ?string
  176.     {
  177.         return $this->pin;
  178.     }
  179.     public function setPin(string $pin): static
  180.     {
  181.         $this->pin $pin;
  182.         return $this;
  183.     }
  184.     public function getExpireDate(): ?\DateTimeInterface
  185.     {
  186.         return $this->expireDate;
  187.     }
  188.     public function setExpireDate(?\DateTimeInterface $expireDate): static
  189.     {
  190.         $this->expireDate $expireDate;
  191.         return $this;
  192.     }
  193.     public function getQrUrl(): ?string
  194.     {
  195.         return $this->qrUrl;
  196.     }
  197.     public function setQrUrl(string $qr_url): static
  198.     {
  199.         $this->qrUrl $qr_url;
  200.         return $this;
  201.     }
  202.     /**
  203.      * Set active.
  204.      *
  205.      * @param int $active
  206.      *
  207.      * @return PhoneNumber
  208.      */
  209.     public function setActive($active)
  210.     {
  211.         $this->active $active;
  212.         return $this;
  213.     }
  214.     /**
  215.      * Get active.
  216.      *
  217.      * @return int
  218.      */
  219.     public function getActive()
  220.     {
  221.         return $this->active;
  222.     }
  223.     public function getActiveLabel(): string
  224.     {
  225.         return $this->active ActiveConstants::LABEL_YES ActiveConstants::LABEL_NO;
  226.     }
  227.     public function getLockedByUserLabel(): string
  228.     {
  229.         return $this->getLockedByUser() ? ActiveConstants::LABEL_YES ActiveConstants::LABEL_NO;
  230.     }
  231.     public function __toString()
  232.     {
  233.         return $this->getNumber();
  234.     }
  235.     public function getLockedUser(): ?User
  236.     {
  237.         return $this->lockedUser;
  238.     }
  239.     public function setLockedUser(?User $lockedUser): static
  240.     {
  241.         $this->lockedUser $lockedUser;
  242.         return $this;
  243.     }
  244.     /**
  245.      * @return Collection<int, Order>
  246.      */
  247.     public function getOrders(): Collection
  248.     {
  249.         return $this->orders;
  250.     }
  251.     public function addOrder(Order $order): static
  252.     {
  253.         if (!$this->orders->contains($order)) {
  254.             $this->orders->add($order);
  255.             $order->setPhoneNumber($this);
  256.         }
  257.         return $this;
  258.     }
  259.     public function removeOrder(Order $order): static
  260.     {
  261.         if ($this->orders->removeElement($order)) {
  262.             // set the owning side to null (unless already changed)
  263.             if ($order->getPhoneNumber() === $this) {
  264.                 $order->setPhoneNumber(null);
  265.             }
  266.         }
  267.         return $this;
  268.     }
  269.     public function getIccsd(): ?string
  270.     {
  271.         return $this->iccsd;
  272.     }
  273.     public function getLockedByUser(): bool
  274.     {
  275.         $now = new \DateTime();
  276.         if ($now $this->getUnfreezeTime()) {
  277.             return true;
  278.         }
  279.         return false;
  280.     }
  281.     public function setIccsd(string $iccsd): static
  282.     {
  283.         $this->iccsd $iccsd;
  284.         return $this;
  285.     }
  286.     public function getOrderPayed()
  287.     {
  288.         foreach ($this->getOrders() as $order) {
  289.             if ($order->getStatus() == OrderStatusConstants::PAYED) {
  290.                 return $order;
  291.             }
  292.         }
  293.         return null;
  294.     }
  295.     public function getUserPayed()
  296.     {
  297.         foreach ($this->getOrders() as $order) {
  298.             if ($order->getStatus() == OrderStatusConstants::PAYED) {
  299.                 return $order->getUser();
  300.             }
  301.         }
  302.         return null;
  303.     }
  304.     public function getPrice(): ?float
  305.     {
  306.         return $this->price;
  307.     }
  308.     public function setPrice(?float $price): static
  309.     {
  310.         $this->price $price;
  311.         return $this;
  312.     }
  313. }