src/Entity/VPN/Service/Plan.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\VPN\Service;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\Country;
  5. use App\Entity\Telegram\AgentPublicBot\BotPlan;
  6. use App\Repository\VPN\Service\PlanRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  12. #[ORM\Entity(repositoryClassPlanRepository::class)]
  13. class Plan extends BaseEntity
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\Column(type'guid'uniquetrue)]
  17.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  18.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  19.     private ?string $id null;
  20.     #[ORM\Column]
  21.     private ?int $days null;
  22.     #[ORM\Column(length255)]
  23.     private ?string $serviceType null;
  24.     #[ORM\Column(length255)]
  25.     private ?string $protocol null;
  26.     #[ORM\Column(length255)]
  27.     private ?string $size null;
  28.     #[ORM\Column]
  29.     private ?int $users null;
  30.     #[ORM\Column(length255)]
  31.     private ?string $country null;
  32.     #[ORM\Column(typeTypes::BIGINT)]
  33.     private ?string $price null;
  34.     /**
  35.      * @var Collection<int, Service>
  36.      */
  37.     #[ORM\OneToMany(targetEntityService::class, mappedBy'plan')]
  38.     private Collection $services;
  39.     #[ORM\Column]
  40.     private ?bool $hasV2ray null;
  41.     #[ORM\Column]
  42.     private ?bool $hasCisco null;
  43.     #[ORM\Column]
  44.     private ?bool $hasOpenVpn null;
  45.     #[ORM\OneToMany(mappedBy'plan'targetEntityBotPlan::class)]
  46.     private Collection $botPlans;
  47.     public function __construct()
  48.     {
  49.         parent::__construct();
  50.         $this->services = new ArrayCollection();
  51.         $this->botPlans = new ArrayCollection();
  52.     }
  53.     public function formatSizeUnits($bytes): string
  54.     {
  55.         if ($bytes >= 1073741824) {
  56.             $bytes number_format($bytes 10737418242) . ' GB';
  57.         } elseif ($bytes >= 1048576) {
  58.             $bytes number_format($bytes 10485762) . ' MB';
  59.         } elseif ($bytes >= 1024) {
  60.             $bytes number_format($bytes 10242) . ' KB';
  61.         } elseif ($bytes 1) {
  62.             $bytes $bytes ' bytes';
  63.         } elseif ($bytes == 1) {
  64.             $bytes $bytes ' byte';
  65.         } else {
  66.             $bytes '0 bytes';
  67.         }
  68.         return $bytes;
  69.     }
  70.     public function __toString()
  71.     {
  72.         $ltr "\u{200E}"// کاراکتر جهت‌دهی چپ‌به‌راست (LTR)
  73.         $parts = [];
  74.         if ($this->hasOpenVpn) {
  75.             $parts[] = $ltr 'OpenVPN'// اعمال جهت LTR برای کلمات انگلیسی
  76.         }
  77.         if ($this->hasCisco) {
  78.             $parts[] = $ltr 'Cisco';
  79.         }
  80.         if ($this->hasV2ray) {
  81.             $parts[] = $ltr 'V2ray';
  82.         }
  83.         if ($this->serviceType == 'unlimited') {
  84.             $parts[] = 'نامحدود';
  85.         }
  86.         if ($this->serviceType == 'sized') {
  87.             $parts[] = 'محدود حجمی';
  88.         }
  89.         if ($this->getUsers() !== 0) {
  90.             $parts[] = $this->getUsers() . ' کاربره';
  91.         }
  92.         if ($this->getDays() !== 0) {
  93.             $parts[] = $this->getDays() . ' روزه';
  94.         }
  95.         if ($this->serviceType == 'sized') {
  96.             $size $this->getSize();
  97.             $sizeUnit 'گیگ';
  98.             $parts[] = $this->formatSizeUnits($size );
  99.         }
  100.         return implode(' '$parts);
  101.     }
  102.     public function getId(): ?string
  103.     {
  104.         return $this->id;
  105.     }
  106.     public function getDays(): ?int
  107.     {
  108.         return $this->days;
  109.     }
  110.     public function setDays(int $days): static
  111.     {
  112.         $this->days $days;
  113.         return $this;
  114.     }
  115.     public function getServiceType(): ?string
  116.     {
  117.         return $this->serviceType;
  118.     }
  119.     public function setServiceType(string $serviceType): static
  120.     {
  121.         $this->serviceType $serviceType;
  122.         return $this;
  123.     }
  124.     public function getProtocol(): ?string
  125.     {
  126.         return $this->protocol;
  127.     }
  128.     public function setProtocol(string $protocol): static
  129.     {
  130.         $this->protocol $protocol;
  131.         return $this;
  132.     }
  133.     public function getSize(): ?int
  134.     {
  135.         return $this->size;
  136.     }
  137.     public function setSize(int $size): static
  138.     {
  139.         $this->size $size;
  140.         return $this;
  141.     }
  142.     public function getUsers(): ?int
  143.     {
  144.         return $this->users;
  145.     }
  146.     public function setUsers(int $users): static
  147.     {
  148.         $this->users $users;
  149.         return $this;
  150.     }
  151.     public function getCountry(): ?string
  152.     {
  153.         return $this->country;
  154.     }
  155.     public function setCountry(string $country): static
  156.     {
  157.         $this->country $country;
  158.         return $this;
  159.     }
  160.     public function getPrice(): ?string
  161.     {
  162.         return $this->price;
  163.     }
  164.     public function setPrice(string $price): static
  165.     {
  166.         $this->price $price;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection<int, Service>
  171.      */
  172.     public function getServices(): Collection
  173.     {
  174.         return $this->services;
  175.     }
  176.     public function addService(Service $service): static
  177.     {
  178.         if (!$this->services->contains($service)) {
  179.             $this->services->add($service);
  180.             $service->setPlan($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeService(Service $service): static
  185.     {
  186.         if ($this->services->removeElement($service)) {
  187.             // set the owning side to null (unless already changed)
  188.             if ($service->getPlan() === $this) {
  189.                 $service->setPlan(null);
  190.             }
  191.         }
  192.         return $this;
  193.     }
  194.     public function hasV2ray(): ?bool
  195.     {
  196.         return $this->hasV2ray;
  197.     }
  198.     public function setHasV2ray(bool $hasV2ray): static
  199.     {
  200.         $this->hasV2ray $hasV2ray;
  201.         return $this;
  202.     }
  203.     public function hasCisco(): ?bool
  204.     {
  205.         return $this->hasCisco;
  206.     }
  207.     public function setHasCisco(bool $hasCisco): static
  208.     {
  209.         $this->hasCisco $hasCisco;
  210.         return $this;
  211.     }
  212.     public function hasOpenVpn(): ?bool
  213.     {
  214.         return $this->hasOpenVpn;
  215.     }
  216.     public function setHasOpenVpn(bool $hasOpenVpn): static
  217.     {
  218.         $this->hasOpenVpn $hasOpenVpn;
  219.         return $this;
  220.     }
  221.     /**
  222.      * @return Collection<int, BotPlan>
  223.      */
  224.     public function getBotPlans(): Collection
  225.     {
  226.         return $this->botPlans;
  227.     }
  228.     public function addBotPlan(BotPlan $botPlan): static
  229.     {
  230.         if (!$this->botPlans->contains($botPlan)) {
  231.             $this->botPlans->add($botPlan);
  232.             $botPlan->setPlan($this);
  233.         }
  234.         return $this;
  235.     }
  236.     public function removeBotPlan(BotPlan $botPlan): static
  237.     {
  238.         if ($this->botPlans->removeElement($botPlan)) {
  239.             // set the owning side to null (unless already changed)
  240.             if ($botPlan->getPlan() === $this) {
  241.                 $botPlan->setPlan(null);
  242.             }
  243.         }
  244.         return $this;
  245.     }
  246. }