src/Entity/Website/VPN/Service/Plan.php line 17

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