src/Entity/Shop.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ShopRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ShopRepository::class)
  10.  */
  11. class Shop
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=128)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\Column(type="string", length=128)
  25.      */
  26.     private $country;
  27.     /**
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $wttId;
  31.     /**
  32.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="shops")
  33.      */
  34.     private Collection $users;
  35.     /**
  36.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="shop")
  37.      */
  38.     private $orders;
  39.     /**
  40.      * @ORM\Column(type="string", length=16, nullable=true)
  41.      */
  42.     private $wttName;
  43.     /**
  44.      * @ORM\Column(type="text", length=16, nullable=true)
  45.      */
  46.     private $logo null;
  47.     /**
  48.      * @ORM\OneToMany(targetEntity=Stock::class, mappedBy="shop")
  49.      */
  50.     private $stocks;
  51.     /**
  52.      * @ORM\Column(type="json", nullable=true)
  53.      */
  54.     private $config null;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity=Company::class, mappedBy="shop")
  57.      */
  58.     private $companies;
  59.     /**
  60.      * @ORM\OneToMany(targetEntity=ShopSetting::class, mappedBy="shop", cascade={"persist"})
  61.      */
  62.     private $settings;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity=Imei::class, mappedBy="shop")
  65.      */
  66.     private $imeis;
  67.     /**
  68.      * @ORM\Column(type="string", length=255, nullable=true)
  69.      */
  70.     private $apikey;
  71.     /**
  72.      * @ORM\Column(type="string", length=255,nullable=true)
  73.      */
  74.     private $loginHash;
  75.     /**
  76.      * @ORM\Column(type="string", length=16)
  77.      */
  78.     private $channel;
  79.     /**
  80.      * @ORM\Column(type="text", nullable=true)
  81.      */
  82.     private $mailCopy;
  83.     /**
  84.      * @ORM\OneToMany(targetEntity=Coupon::class, mappedBy="shop")
  85.      */
  86.     private $coupons;
  87.     /**
  88.      * @ORM\ManyToMany(targetEntity=Category::class, inversedBy="shops", cascade={"persist"})
  89.      */
  90.     private Collection $categories;
  91.     /**
  92.      * @ORM\ManyToMany(targetEntity=Option::class, mappedBy="shops", cascade={"persist"})
  93.      */
  94.     private Collection $options;
  95.     /**
  96.      * @ORM\ManyToMany(targetEntity=Status::class, inversedBy="shops", cascade={"persist"})
  97.      */
  98.     private Collection $statuses;
  99.     /**
  100.      * @ORM\Column(type="boolean", nullable=true)
  101.      */
  102.     private $active;
  103.     private $vat;
  104.     public function __construct()
  105.     {
  106.         $this->users = new ArrayCollection();
  107.         $this->orders = new ArrayCollection();
  108.         $this->products = new ArrayCollection();
  109.         $this->stocks = new ArrayCollection();
  110.         $this->companies = new ArrayCollection();
  111.         $this->imeis = new ArrayCollection();
  112.         $this->settings = new ArrayCollection();
  113.         $this->coupons = new ArrayCollection();
  114.         $this->categories = new ArrayCollection();
  115.         $this->options = new ArrayCollection();
  116.         $this->statuses = new ArrayCollection();
  117.     }
  118.     public function __toString() {
  119.         if($this->name!='') {
  120.             return $this->getName();
  121.         }
  122.         return "new shop";
  123.     }
  124.     public function getId(): ?int
  125.     {
  126.         return $this->id;
  127.     }
  128.     public function getName(): ?string
  129.     {
  130.         return $this->name;
  131.     }
  132.     public function setName(string $name): self
  133.     {
  134.         $this->name $name;
  135.         return $this;
  136.     }
  137.     public function getMachineName() {
  138.         $name=str_replace(' ','-',$this->getName());
  139.         return preg_replace("/[^A-Za-z0-9.-]/",'',$name);
  140.     }
  141.     public function getWttId(): ?int
  142.     {
  143.         return $this->wttId;
  144.     }
  145.     public function setWttId(int $wttId): self
  146.     {
  147.         $this->wttId $wttId;
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return Collection<int, User>
  152.      */
  153.     public function getUsers(): Collection
  154.     {
  155.         return $this->users;
  156.     }
  157.     public function addUser(User $user): self
  158.     {
  159.         if (!$this->users->contains($user)) {
  160.             $this->users[] = $user;
  161.             //$user->setShop($this);
  162.             $user->addShop($this);
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeUser(User $user): self
  167.     {
  168.         if ($this->users->removeElement($user)) {
  169.             // set the owning side to null (unless already changed)
  170.             if ($user->getShop() === $this) {
  171.                 //$user->setShop(null);
  172.                 $user->removeShop($this);
  173.             }
  174.         }
  175.         return $this;
  176.     }
  177.     public function addOrder(Order $order): self
  178.     {
  179.         if (!$this->orders->contains($order)) {
  180.             $this->orders[] = $order;
  181.             $order->setShop($this);
  182.         }
  183.         return $this;
  184.     }
  185.     public function removeOrder(Order $order): self
  186.     {
  187.         if ($this->orders->removeElement($order)) {
  188.             // set the owning side to null (unless already changed)
  189.             if ($order->getShop() === $this) {
  190.                 $order->setShop(null);
  191.             }
  192.         }
  193.         return $this;
  194.     }
  195.     public function getWttName(): ?string
  196.     {
  197.         return $this->wttName;
  198.     }
  199.     public function setWttName(string $wttName): self
  200.     {
  201.         $this->wttName $wttName;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return Collection<int, Stock>
  206.      */
  207.     public function getStocks(): Collection
  208.     {
  209.         return $this->stocks;
  210.     }
  211.     public function addStock(Stock $stock): self
  212.     {
  213.         if (!$this->stocks->contains($stock)) {
  214.             $this->stocks[] = $stock;
  215.             $stock->setShop($this);
  216.         }
  217.         return $this;
  218.     }
  219.     public function removeStock(Stock $stock): self
  220.     {
  221.         if ($this->stocks->removeElement($stock)) {
  222.             // set the owning side to null (unless already changed)
  223.             if ($stock->getShop() === $this) {
  224.                 $stock->setShop(null);
  225.             }
  226.         }
  227.         return $this;
  228.     }
  229.     public function getConfig()
  230.     {
  231.         if(is_null($this->config)) {
  232.             return null;
  233.         }
  234.         return reset($this->config);
  235.     }
  236.     public function setConfig$config): self
  237.     {
  238.         $this->config $config;
  239.         return $this;
  240.     }
  241.     /**
  242.      * @return Collection<int, Company>
  243.      */
  244.     public function getCompanies(): Collection
  245.     {
  246.         return $this->companies;
  247.     }
  248.     public function addCompany(Company $company): self
  249.     {
  250.         if (!$this->companies->contains($company)) {
  251.             $this->companies[] = $company;
  252.             $company->setShop($this);
  253.         }
  254.         return $this;
  255.     }
  256.     public function removeCompany(Company $company): self
  257.     {
  258.         if ($this->companies->removeElement($company)) {
  259.             // set the owning side to null (unless already changed)
  260.             if ($company->getShop() === $this) {
  261.                 $company->setShop(null);
  262.             }
  263.         }
  264.         return $this;
  265.     }
  266.     /**
  267.      * @return Collection<int, ShopSetting>
  268.      */
  269.     public function getSettings(): Collection
  270.     {
  271.         return $this->settings;
  272.     }
  273.     public function getSetting($machineName) {
  274.         foreach($this->getSettings() as $setting) {
  275.             if($setting->getSetting()->getMachineName()==$machineName) {
  276.                 if($setting->getValue()=='false') {
  277.                     return false;
  278.                 }
  279.                 return $setting->getValue();
  280.             }
  281.         }
  282.         return false;
  283.     }
  284.     public function addSetting(ShopSetting $setting): void
  285.     {
  286.         $setting->setShop($this);
  287.         $this->settings->add($setting);
  288.         /*if (!$this->settings->contains($setting)) {
  289.             $this->settings[] = $setting;
  290.             $setting->setUser($this);
  291.         }
  292.         return $this;
  293.         */
  294.     }
  295.     public function removeSetting(ShopSetting $setting): void
  296.     {
  297.         /*if ($this->settings->removeElement($setting)) {
  298.             // set the owning side to null (unless already changed)
  299.             if ($setting->getUser() === $this) {
  300.                 $setting->setUser(null);
  301.             }
  302.         }
  303.         return $this;*/
  304.     }
  305.     /**
  306.      * @return Collection<int, Imei>
  307.      */
  308.     public function getImeis(): Collection
  309.     {
  310.         return $this->imeis;
  311.     }
  312.     public function addImei(Imei $imei): self
  313.     {
  314.         if (!$this->imeis->contains($imei)) {
  315.             $this->imeis[] = $imei;
  316.             $imei->setShop($this);
  317.         }
  318.         return $this;
  319.     }
  320.     public function removeImei(Imei $imei): self
  321.     {
  322.         if ($this->imeis->removeElement($imei)) {
  323.             // set the owning side to null (unless already changed)
  324.             if ($imei->getShop() === $this) {
  325.                 $imei->setShop(null);
  326.             }
  327.         }
  328.         return $this;
  329.     }
  330.     public function getApikey(): ?string
  331.     {
  332.         return $this->apikey;
  333.     }
  334.     public function setApikey(string $apikey): self
  335.     {
  336.         $this->apikey $apikey;
  337.         return $this;
  338.     }
  339.     public function getLoginHash(): ?string
  340.     {
  341.         return $this->loginHash;
  342.     }
  343.     public function setLoginHash(string $loginHash): self
  344.     {
  345.         $this->loginHash $loginHash;
  346.         return $this;
  347.     }
  348.     public function getChannel(): ?string
  349.     {
  350.         return $this->channel;
  351.     }
  352.     public function setChannel(string $channel): self
  353.     {
  354.         $this->channel $channel;
  355.         return $this;
  356.     }
  357.     public function getMailCopy(): ?string
  358.     {
  359.         return $this->mailCopy;
  360.     }
  361.     public function setMailCopy(?string $mailCopy): self
  362.     {
  363.         $this->mailCopy $mailCopy;
  364.         return $this;
  365.     }
  366.     /**
  367.      * @return Collection<int, Coupon>
  368.      */
  369.     public function getCoupons(): Collection
  370.     {
  371.         return $this->coupons;
  372.     }
  373.     public function addCoupon(Coupon $coupon): static
  374.     {
  375.         if (!$this->coupons->contains($coupon)) {
  376.             $this->coupons->add($coupon);
  377.             $coupon->setShop($this);
  378.         }
  379.         return $this;
  380.     }
  381.     public function removeCoupon(Coupon $coupon): static
  382.     {
  383.         if ($this->coupons->removeElement($coupon)) {
  384.             // set the owning side to null (unless already changed)
  385.             if ($coupon->getShop() === $this) {
  386.                 $coupon->setShop(null);
  387.             }
  388.         }
  389.         return $this;
  390.     }
  391.     /**
  392.      * @return Collection<int, Order>
  393.      */
  394.     public function getOrders(): Collection
  395.     {
  396.         return $this->orders;
  397.     }
  398.     public function getLogo(): ?string
  399.     {
  400.         return $this->logo;
  401.     }
  402.     public function setLogo(?string $logo): self
  403.     {
  404.         $this->logo $logo;
  405.         return $this;
  406.     }
  407.     public function getCountry(): ?string
  408.     {
  409.         return $this->country;
  410.     }
  411.     public function setCountry(string $country): static
  412.     {
  413.         $this->country $country;
  414.         return $this;
  415.     }
  416.     public function getVat() {
  417.         $this->vat=20;
  418.         if($this->getCountry()=='es') {
  419.             $this->vat=21;
  420.         }
  421.         return $this->vat;
  422.     }
  423.     /**
  424.      * @return Collection<int, Category>
  425.      */
  426.     public function getCategories(): Collection
  427.     {
  428.         return $this->categories;
  429.     }
  430.     public function addCategory(Category $category): static
  431.     {
  432.         if (!$this->categories->contains($category)) {
  433.             $this->categories->add($category);
  434.             $category->addShop($this);
  435.         }
  436.         return $this;
  437.     }
  438.     public function removeCategory(Category $category): static
  439.     {
  440.         if ($this->categories->removeElement($category)) {
  441.             $category->removeShop($this);
  442.         }
  443.         return $this;
  444.     }
  445.     /**
  446.      * @return Collection<int, Option>
  447.      */
  448.     public function getOptions(): Collection
  449.     {
  450.         return $this->options;
  451.     }
  452.     public function addOption(Option $option): static
  453.     {
  454.         if (!$this->options->contains($option)) {
  455.             $this->options->add($option);
  456.             $option->addShop($this);
  457.         }
  458.         return $this;
  459.     }
  460.     public function removeOption(Option $option): static
  461.     {
  462.         if ($this->options->removeElement($option)) {
  463.             $option->removeShop($this);
  464.         }
  465.         return $this;
  466.     }
  467.     /**
  468.      * @return Collection<int, Status>
  469.      */
  470.     public function getStatuses(): Collection
  471.     {
  472.         return $this->statuses;
  473.     }
  474.     public function addStatus(Status $status): static
  475.     {
  476.         if (!$this->statuses->contains($status)) {
  477.             $this->statuses->add($status);
  478.         }
  479.         return $this;
  480.     }
  481.     public function removeStatus(Status $status): static
  482.     {
  483.         $this->statuses->removeElement($status);
  484.         return $this;
  485.     }
  486.     public function getActive():bool
  487.     {
  488.         return $this->active;
  489.     }
  490.     public function setActive(bool $active):self
  491.     {
  492.         $this->active $active;
  493.         return $this;
  494.     }
  495.     public function isActive(): ?bool
  496.     {
  497.         return $this->active;
  498.     }
  499. }