src/Entity/MarkupStrategy.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\MarkupStrategyRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass: MarkupStrategyRepository::class)]
  8. class MarkupStrategy
  9. {
  10.     public const PRODUCT_HOTEL = 1;
  11.     public const PRODUCT_TRANSFER = 2;
  12.     public const PRODUCT_FLIGHT = 3;
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id = null;
  17.     #[ORM\Column(length: 255)]
  18.     private ?string $name = null;
  19.     #[ORM\OneToMany(mappedBy: 'markupStrategy', targetEntity: MarkupRule::class, cascade: ['remove'], orphanRemoval: true)]
  20.     private Collection $rules;
  21.     #[ORM\OneToMany(mappedBy: 'markupStrategy', targetEntity: CustomerXmlApi::class)]
  22.     private Collection $customerXmlApis;
  23.     #[ORM\Column(type: 'integer', nullable: false)]
  24.     private ?int $product = null;
  25.     #[ORM\OneToMany(mappedBy: 'b2cMarkupStrategy', targetEntity: XmlApi::class)]
  26.     private Collection $b2cXmlApis;
  27.     #[ORM\OneToMany(mappedBy: 'b2bMarkupStrategy', targetEntity: XmlApi::class)]
  28.     private Collection $b2bXmlApis;
  29.     // sale rates replacing the default ones for the customers priced by this strategy
  30.     #[ORM\OneToMany(mappedBy: 'markupStrategy', targetEntity: MarkupStrategyExchangeRate::class, cascade: ['remove'], orphanRemoval: true)]
  31.     private Collection $exchangeRates;
  32.     public function __construct()
  33.     {
  34.         $this->rules = new ArrayCollection();
  35.         $this->customerXmlApis = new ArrayCollection();
  36.         $this->b2cXmlApis = new ArrayCollection();
  37.         $this->b2bXmlApis = new ArrayCollection();
  38.         $this->exchangeRates = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getProduct(): ?int
  45.     {
  46.         return $this->product;
  47.     }
  48.     public function setProduct(?int $product): static
  49.     {
  50.         $this->product = $product;
  51.         return $this;
  52.     }
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): static
  58.     {
  59.         $this->name = $name;
  60.         return $this;
  61.     }
  62.     /**
  63.      * @return Collection<int, MarkupRule>
  64.      */
  65.     public function getRules(): Collection
  66.     {
  67.         return $this->rules;
  68.     }
  69.     public function addRule(MarkupRule $rule): static
  70.     {
  71.         if (!$this->rules->contains($rule)) {
  72.             $this->rules->add($rule);
  73.             $rule->setMarkupStrategy($this);
  74.         }
  75.         return $this;
  76.     }
  77.     public function removeRule(MarkupRule $rule): static
  78.     {
  79.         if ($this->rules->removeElement($rule)) {
  80.             // set the owning side to null (unless already changed)
  81.             if ($rule->getMarkupStrategy() === $this) {
  82.                 $rule->setMarkupStrategy(null);
  83.             }
  84.         }
  85.         return $this;
  86.     }
  87.     /**
  88.      * @return Collection<int, CustomerXmlApi>
  89.      */
  90.     public function getCustomerXmlApis(): Collection
  91.     {
  92.         return $this->customerXmlApis;
  93.     }
  94.     public function addCustomerXmlApi(CustomerXmlApi $customerXmlApi): static
  95.     {
  96.         if (!$this->customerXmlApis->contains($customerXmlApi)) {
  97.             $this->customerXmlApis->add($customerXmlApi);
  98.             $customerXmlApi->setMarkupStrategy($this);
  99.         }
  100.         return $this;
  101.     }
  102.     public function removeCustomerXmlApi(CustomerXmlApi $customerXmlApi): static
  103.     {
  104.         if ($this->customerXmlApis->removeElement($customerXmlApi)) {
  105.             // set the owning side to null (unless already changed)
  106.             if ($customerXmlApi->getMarkupStrategy() === $this) {
  107.                 $customerXmlApi->setMarkupStrategy(null);
  108.             }
  109.         }
  110.         return $this;
  111.     }
  112.     public function __toString(): string
  113.     {
  114.         return $this->name ?? ' ';
  115.     }
  116.     public static function getProductStrategies(): array
  117.     {
  118.         return [
  119.             'Hotel' => self::PRODUCT_HOTEL,
  120.             'Transfer' => self::PRODUCT_TRANSFER,
  121.             'Flight' => self::PRODUCT_FLIGHT,
  122.         ];
  123.     }
  124.     public function getProductName(): string
  125.     {
  126.         $productNames = [
  127.             self::PRODUCT_HOTEL => 'Hotel',
  128.             self::PRODUCT_TRANSFER => 'Transfer',
  129.             self::PRODUCT_FLIGHT => 'Flight',
  130.         ];
  131.         return $productNames[$this->product] ?? 'Unknown';
  132.     }
  133.     /**
  134.      * @return Collection<int, XmlApi>
  135.      */
  136.     public function getB2cXmlApis(): Collection
  137.     {
  138.         return $this->b2cXmlApis;
  139.     }
  140.     public function addB2cXmlApi(XmlApi $b2cXmlApi): static
  141.     {
  142.         if (!$this->b2cXmlApis->contains($b2cXmlApi)) {
  143.             $this->b2cXmlApis->add($b2cXmlApi);
  144.             $b2cXmlApi->setB2cMarkupStrategy($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeB2cXmlApi(XmlApi $b2cXmlApi): static
  149.     {
  150.         if ($this->b2cXmlApis->removeElement($b2cXmlApi)) {
  151.             // set the owning side to null (unless already changed)
  152.             if ($b2cXmlApi->getB2cMarkupStrategy() === $this) {
  153.                 $b2cXmlApi->setB2cMarkupStrategy(null);
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return Collection<int, XmlApi>
  160.      */
  161.     public function getB2bXmlApis(): Collection
  162.     {
  163.         return $this->b2bXmlApis;
  164.     }
  165.     public function addB2bXmlApi(XmlApi $b2bXmlApi): static
  166.     {
  167.         if (!$this->b2bXmlApis->contains($b2bXmlApi)) {
  168.             $this->b2bXmlApis->add($b2bXmlApi);
  169.             $b2bXmlApi->setB2bMarkupStrategy($this);
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeB2bXmlApi(XmlApi $b2bXmlApi): static
  174.     {
  175.         if ($this->b2bXmlApis->removeElement($b2bXmlApi)) {
  176.             // set the owning side to null (unless already changed)
  177.             if ($b2bXmlApi->getB2bMarkupStrategy() === $this) {
  178.                 $b2bXmlApi->setB2bMarkupStrategy(null);
  179.             }
  180.         }
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection<int, MarkupStrategyExchangeRate>
  185.      */
  186.     public function getExchangeRates(): Collection
  187.     {
  188.         return $this->exchangeRates;
  189.     }
  190. }