src/Entity/Config/SmartAlternativeConfig.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Config;
  3. use App\Entity\Addon\Installation;
  4. use App\Entity\BaseEntity;
  5. use App\Repository\Config\SmartAlternativeConfigRepository;
  6. use DateTimeInterface;
  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. #[ORM\Entity(repositoryClassSmartAlternativeConfigRepository::class)]
  12. class SmartAlternativeConfig extends BaseEntity
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column()]
  17.     private ?int $id null;
  18.     #[ORM\Column(options: ["default" => true])]
  19.     private bool $isActive true;
  20.     #[ORM\OneToMany(mappedBy'config'targetEntitySmartAlternativeConfigRule::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  21.     private Collection $rules;
  22.     #[ORM\OneToOne(inversedBy'config'cascade: ['persist''remove'])]
  23.     #[ORM\JoinColumn(nullablefalse)]
  24.     private ?Installation $installation null;
  25.     #[ORM\OneToMany(mappedBy'config'targetEntitySmartAlternativeConfigProduct::class, orphanRemovaltrue)]
  26.     private Collection $smartAlternativeConfigProducts;
  27.     #[ORM\Column(options: ["default" => false])]
  28.     private bool $isProductsRetrieved false;
  29.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrueoptions: ["default" => null])]
  30.     private ?\DateTimeInterface $productsExpiry null;
  31.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  32.     private ?string $customHtmlSelector null;
  33.     #[ORM\Column(options: ["default" => false])]
  34.     private bool $deactivateDiscount false;
  35.     public function __construct()
  36.     {
  37.         $this->rules = new ArrayCollection();
  38.         $this->addRule($this->defaultRule());
  39.         $this->smartAlternativeConfigProducts = new ArrayCollection();
  40.     }
  41.     private function defaultRule(): SmartAlternativeConfigRule
  42.     {
  43.         $rule = new SmartAlternativeConfigRule();
  44.         $rule->setConfig($this);
  45.         $rule->setIsGlobal(true);
  46.         return $rule;
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function isIsActive(): ?bool
  53.     {
  54.         return $this->isActive;
  55.     }
  56.     public function setIsActive(bool $isActive): self
  57.     {
  58.         $this->isActive $isActive;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection<int, SmartAlternativeConfigRule>
  63.      */
  64.     public function getRules(): Collection
  65.     {
  66.         return $this->rules;
  67.     }
  68.     public function addRule(SmartAlternativeConfigRule $rule): self
  69.     {
  70.         if (!$this->rules->contains($rule)) {
  71.             $this->rules[] = $rule;
  72.             $rule->setConfig($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removeRule(SmartAlternativeConfigRule $rule): self
  77.     {
  78.         if ($this->rules->removeElement($rule)) {
  79.             // set the owning side to null (unless already changed)
  80.             if ($rule->getConfig() === $this) {
  81.                 $rule->setConfig(null);
  82.             }
  83.         }
  84.         return $this;
  85.     }
  86.     public function getInstallation(): ?Installation
  87.     {
  88.         return $this->installation;
  89.     }
  90.     public function setInstallation(Installation $installation): self
  91.     {
  92.         $this->installation $installation;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return Collection<int, SmartAlternativeConfigProduct>
  97.      */
  98.     public function getSmartAlternativeConfigProducts(): Collection
  99.     {
  100.         return $this->smartAlternativeConfigProducts;
  101.     }
  102.     public function addSmartAlternativeConfigProduct(SmartAlternativeConfigProduct $smartAlternativeConfigProduct): self
  103.     {
  104.         if (!$this->smartAlternativeConfigProducts->contains($smartAlternativeConfigProduct)) {
  105.             $this->smartAlternativeConfigProducts[] = $smartAlternativeConfigProduct;
  106.             $smartAlternativeConfigProduct->setConfig($this);
  107.         }
  108.         return $this;
  109.     }
  110.     public function removeSmartAlternativeConfigProduct(SmartAlternativeConfigProduct $smartAlternativeConfigProduct): self
  111.     {
  112.         if ($this->smartAlternativeConfigProducts->removeElement($smartAlternativeConfigProduct)) {
  113.             // set the owning side to null (unless already changed)
  114.             if ($smartAlternativeConfigProduct->getConfig() === $this) {
  115.                 $smartAlternativeConfigProduct->setConfig(null);
  116.             }
  117.         }
  118.         return $this;
  119.     }
  120.     public function isIsProductsRetrieved(): ?bool
  121.     {
  122.         return $this->isProductsRetrieved;
  123.     }
  124.     public function setIsProductsRetrieved(bool $isProductsRetrieved): self
  125.     {
  126.         $this->isProductsRetrieved $isProductsRetrieved;
  127.         return $this;
  128.     }
  129.     public function getProductsExpiry(): ?DateTimeInterface
  130.     {
  131.         return $this->productsExpiry;
  132.     }
  133.     public function setProductsExpiry(?DateTimeInterface $productsExpiry): self
  134.     {
  135.         $this->productsExpiry $productsExpiry;
  136.         return $this;
  137.     }
  138.     public function willProductsExpire($timeQueryFromNow "+ 1 hour"): bool
  139.     {
  140.         $now = new \DateTime();
  141.         $expiry $this->productsExpiry;
  142.         if (!$expiry) return false;
  143.         $now->modify($timeQueryFromNow);
  144.         return $now >= $expiry;
  145.     }
  146.     public function getCustomHtmlSelector(): ?string
  147.     {
  148.         return $this->customHtmlSelector;
  149.     }
  150.     public function setCustomHtmlSelector(?string $customHtmlSelector): self
  151.     {
  152.         $this->customHtmlSelector $customHtmlSelector;
  153.         return $this;
  154.     }
  155.     public function setDeactivateDiscount(bool $deactivateDiscount): self
  156.     {
  157.         $this->deactivateDiscount $deactivateDiscount;
  158.         return $this;
  159.     }
  160.     public function isDeactivateDiscount(): bool
  161.     {
  162.         return $this->deactivateDiscount;
  163.     }
  164. }