src/Entity/Item.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\CommonTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\ItemRepository")
  11.  * @UniqueEntity(fields={"slug"})
  12.  * @ORM\Table(name="itm_item")
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class Item
  16. {
  17.     use CommonTrait;
  18.     /**
  19.      * @ORM\Column(type="string", length=255, nullable=true, unique=true)
  20.      */
  21.     private $slug;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      * @Assert\Length(
  25.      *      min = 10,
  26.      *      max = 100,
  27.      *      minMessage = "Tytuł musi zawierać minimalnie {{ limit }} znaków",
  28.      *      maxMessage = "Tyytł może zawierać maksymalnie {{ limit }} znaków"
  29.      * )
  30.      * @Assert\NotNull(message="Tytuł nie może być pusty")
  31.      */
  32.     private $title;
  33.     /**
  34.      * @ORM\Column(type="text", nullable=true)
  35.      */
  36.     private $description;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="items")
  39.      * @ORM\JoinColumn(nullable=false)
  40.      */
  41.     private $author;
  42.     /**
  43.      * @ORM\ManyToMany(targetEntity="App\Entity\ItemSpec")
  44.      * @ORM\JoinTable(name="itm_item_spec")
  45.      */
  46.     private $specs;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity="App\Entity\ItemCategory", inversedBy="items")
  49.      * @ORM\JoinColumn(nullable=true)
  50.      */
  51.     private $itemCategory;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity="App\Entity\ItemPhoto", mappedBy="item", orphanRemoval=true)
  54.      */
  55.     private $itemPhotos;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity="App\Entity\UserSaveItem", mappedBy="item", orphanRemoval=true)
  58.      */
  59.     private $userSaveItems;
  60.     /**
  61.      * @ORM\Column(type="decimal", precision=20, scale=2, nullable=true)
  62.      */
  63.     private $price;
  64.     /**
  65.      * @ORM\OneToOne(targetEntity=ItemVideo::class, mappedBy="item", cascade={"persist", "remove"})
  66.      */
  67.     private $itemVideo;
  68.     /**
  69.      * @ORM\Column(type="string", length=255, nullable=true)
  70.      */
  71.     private $priceType;
  72.     /**
  73.      * @ORM\Column(type="string", length=255, nullable=true)
  74.      */
  75.     private $fv;
  76.     /**
  77.      * @ORM\Column(type="json", nullable=true)
  78.      */
  79.     private $location = [];
  80.     /**
  81.      * @ORM\Column(type="string", length=255, nullable=true)
  82.      */
  83.     private $locationName;
  84.     /**
  85.      * @ORM\Column(type="boolean", nullable=true)
  86.      */
  87.     private $isExpired;
  88.     /**
  89.      * @ORM\Column(type="boolean", nullable=true)
  90.      */
  91.     private $priceNegotiation;
  92.     /**
  93.      * @ORM\Column(type="string", length=255, nullable=true)
  94.      */
  95.     private $state;
  96.     /**
  97.      * @ORM\ManyToMany(targetEntity=ItemPromotion::class)
  98.      */
  99.     private $promotions;
  100.     /**
  101.      * @ORM\OneToMany(targetEntity=PromoPayTransaction::class, mappedBy="item", orphanRemoval=true)
  102.      */
  103.     private $promoPayTransactions;
  104.     /**
  105.      * @ORM\Column(type="boolean", nullable=true)
  106.      */
  107.     private $homePagePromo;
  108.     /**
  109.      * @ORM\Column(type="boolean", nullable=true)
  110.      */
  111.     private $listBigPromo;
  112.     /**
  113.      * @ORM\Column(type="boolean", nullable=true)
  114.      */
  115.     private $listShadowPromo;
  116.     /**
  117.      * @ORM\ManyToOne(targetEntity="Item", inversedBy="children")
  118.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
  119.      */
  120.     private $parent;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity="Item", mappedBy="parent")
  123.      */
  124.     private $children;
  125.     public function __construct()
  126.     {
  127.         $this->specs = new ArrayCollection();
  128.         $this->itemPhotos = new ArrayCollection();
  129.         $this->userSaveItems = new ArrayCollection();
  130.         $this->promotions = new ArrayCollection();
  131.         $this->promoPayTransactions = new ArrayCollection();
  132.         $this->children = new ArrayCollection();
  133.     }
  134.     public function __toString()
  135.     {
  136.         if($this->title && strlen($this->title) > 0) {
  137.             return $this->title;
  138.         }
  139.         return '';
  140.     }
  141.     public function getSlug(): ?string
  142.     {
  143.         return $this->slug;
  144.     }
  145.     public function setSlug(?string $slug): self
  146.     {
  147.         $this->slug $slug;
  148.         return $this;
  149.     }
  150.     public function getTitle(): ?string
  151.     {
  152.         if($this->title && strlen($this->title) > 0) {
  153.             return $this->title;
  154.         }
  155.         return '';
  156.     }
  157.     public function setTitle(string $title): self
  158.     {
  159.         $this->title $title;
  160.         return $this;
  161.     }
  162.     public function getDescription(): ?string
  163.     {
  164.         return $this->description;
  165.     }
  166.     public function setDescription(?string $description): self
  167.     {
  168.         $this->description $description;
  169.         return $this;
  170.     }
  171.     public function getAuthor(): ?User
  172.     {
  173.         return $this->author;
  174.     }
  175.     public function setAuthor(?User $author): self
  176.     {
  177.         $this->author $author;
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return Collection|ItemSpec[]
  182.      */
  183.     public function getSpecs(): Collection
  184.     {
  185.         return $this->specs;
  186.     }
  187.     public function addSpec(ItemSpec $spec): self
  188.     {
  189.         if (!$this->specs->contains($spec)) {
  190.             $this->specs[] = $spec;
  191.         }
  192.         return $this;
  193.     }
  194.     public function removeSpec(ItemSpec $spec): self
  195.     {
  196.         if ($this->specs->contains($spec)) {
  197.             $this->specs->removeElement($spec);
  198.         }
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return Item
  203.      */
  204.     public function setSpecs($specs)
  205.     {
  206.         $this->specs $specs;
  207.         return $this;
  208.     }
  209.     public function getItemCategory(): ?ItemCategory
  210.     {
  211.         return $this->itemCategory;
  212.     }
  213.     public function setItemCategory(?ItemCategory $itemCategory): self
  214.     {
  215.         $this->itemCategory $itemCategory;
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return Collection|ItemPhoto[]
  220.      */
  221.     public function getItemPhotos(): Collection
  222.     {
  223.         return $this->itemPhotos;
  224.     }
  225.     public function addItemPhoto(ItemPhoto $itemPhoto): self
  226.     {
  227.         if (!$this->itemPhotos->contains($itemPhoto)) {
  228.             $this->itemPhotos[] = $itemPhoto;
  229.             $itemPhoto->setItem($this);
  230.         }
  231.         return $this;
  232.     }
  233.     public function removeItemPhoto(ItemPhoto $itemPhoto): self
  234.     {
  235.         if ($this->itemPhotos->contains($itemPhoto)) {
  236.             $this->itemPhotos->removeElement($itemPhoto);
  237.             // set the owning side to null (unless already changed)
  238.             if ($itemPhoto->getItem() === $this) {
  239.                 $itemPhoto->setItem(null);
  240.             }
  241.         }
  242.         return $this;
  243.     }
  244.     /**
  245.      * @return Collection|UserSaveItem[]
  246.      */
  247.     public function getUserSaveItems(): Collection
  248.     {
  249.         return $this->userSaveItems;
  250.     }
  251.     public function addUserSaveItem(UserSaveItem $userSaveItem): self
  252.     {
  253.         if (!$this->userSaveItems->contains($userSaveItem)) {
  254.             $this->userSaveItems[] = $userSaveItem;
  255.             $userSaveItem->setItem($this);
  256.         }
  257.         return $this;
  258.     }
  259.     public function removeUserSaveItem(UserSaveItem $userSaveItem): self
  260.     {
  261.         if ($this->userSaveItems->contains($userSaveItem)) {
  262.             $this->userSaveItems->removeElement($userSaveItem);
  263.             // set the owning side to null (unless already changed)
  264.             if ($userSaveItem->getItem() === $this) {
  265.                 $userSaveItem->setItem(null);
  266.             }
  267.         }
  268.         return $this;
  269.     }
  270.     public function getPrice(): ?string
  271.     {
  272.         return $this->price;
  273.     }
  274.     public function setPrice(string $price): self
  275.     {
  276.         $this->price $price;
  277.         return $this;
  278.     }
  279.     public function getItemVideo(): ?ItemVideo
  280.     {
  281.         return $this->itemVideo;
  282.     }
  283.     public function setItemVideo(?ItemVideo $itemVideo): self
  284.     {
  285.         $this->itemVideo $itemVideo;
  286.         // set (or unset) the owning side of the relation if necessary
  287.         $newItem null === $itemVideo null $this;
  288.         if ($itemVideo->getItem() !== $newItem) {
  289.             $itemVideo->setItem($newItem);
  290.         }
  291.         return $this;
  292.     }
  293.     public function getPriceType(): ?string
  294.     {
  295.         return $this->priceType;
  296.     }
  297.     public function setPriceType(?string $priceType): self
  298.     {
  299.         $this->priceType $priceType;
  300.         return $this;
  301.     }
  302.     public function getFv(): ?string
  303.     {
  304.         return $this->fv;
  305.     }
  306.     public function setFv(?string $fv): self
  307.     {
  308.         $this->fv $fv;
  309.         return $this;
  310.     }
  311.     public function getLocation(): ?array
  312.     {
  313.         return $this->location;
  314.     }
  315.     public function setLocation(?array $location): self
  316.     {
  317.         $this->location $location;
  318.         return $this;
  319.     }
  320.     public function getLocationName(): ?string
  321.     {
  322.         return $this->locationName;
  323.     }
  324.     public function setLocationName(?string $locationName): self
  325.     {
  326.         $this->locationName $locationName;
  327.         return $this;
  328.     }
  329.     public function getIsExpired(): ?bool
  330.     {
  331.         return $this->isExpired;
  332.     }
  333.     public function setIsExpired(?bool $isExpired): self
  334.     {
  335.         $this->isExpired $isExpired;
  336.         return $this;
  337.     }
  338.     public function getPriceNegotiation(): ?bool
  339.     {
  340.         return $this->priceNegotiation;
  341.     }
  342.     public function setPriceNegotiation(?bool $priceNegotiation): self
  343.     {
  344.         $this->priceNegotiation $priceNegotiation;
  345.         return $this;
  346.     }
  347.     public function getState(): ?string
  348.     {
  349.         return $this->state;
  350.     }
  351.     public function setState(?string $state): self
  352.     {
  353.         $this->state $state;
  354.         return $this;
  355.     }
  356.     /**
  357.      * @return Collection|ItemPromotion[]
  358.      */
  359.     public function getPromotions(): Collection
  360.     {
  361.         return $this->promotions;
  362.     }
  363.     public function addPromotion(ItemPromotion $promotion): self
  364.     {
  365.         if (!$this->promotions->contains($promotion)) {
  366.             $this->promotions[] = $promotion;
  367.         }
  368.         return $this;
  369.     }
  370.     public function removePromotion(ItemPromotion $promotion): self
  371.     {
  372.         $this->promotions->removeElement($promotion);
  373.         return $this;
  374.     }
  375.     /**
  376.      * @return Collection|PromoPayTransaction[]
  377.      */
  378.     public function getPromoPayTransactions(): Collection
  379.     {
  380.         return $this->promoPayTransactions;
  381.     }
  382.     public function addPromoPayTransaction(PromoPayTransaction $promoPayTransaction): self
  383.     {
  384.         if (!$this->promoPayTransactions->contains($promoPayTransaction)) {
  385.             $this->promoPayTransactions[] = $promoPayTransaction;
  386.             $promoPayTransaction->setItem($this);
  387.         }
  388.         return $this;
  389.     }
  390.     public function removePromoPayTransaction(PromoPayTransaction $promoPayTransaction): self
  391.     {
  392.         if ($this->promoPayTransactions->removeElement($promoPayTransaction)) {
  393.             // set the owning side to null (unless already changed)
  394.             if ($promoPayTransaction->getItem() === $this) {
  395.                 $promoPayTransaction->setItem(null);
  396.             }
  397.         }
  398.         return $this;
  399.     }
  400.     public function getHomePagePromo(): ?bool
  401.     {
  402.         return $this->homePagePromo;
  403.     }
  404.     public function setHomePagePromo(?bool $homePagePromo): self
  405.     {
  406.         $this->homePagePromo $homePagePromo;
  407.         return $this;
  408.     }
  409.     public function getListBigPromo(): ?bool
  410.     {
  411.         return $this->listBigPromo;
  412.     }
  413.     public function setListBigPromo(?bool $listBigPromo): self
  414.     {
  415.         $this->listBigPromo $listBigPromo;
  416.         return $this;
  417.     }
  418.     public function getListShadowPromo(): ?bool
  419.     {
  420.         return $this->listShadowPromo;
  421.     }
  422.     public function setListShadowPromo(?bool $listShadowPromo): self
  423.     {
  424.         $this->listShadowPromo $listShadowPromo;
  425.         return $this;
  426.     }
  427.     public function setParent(Item $parent null)
  428.     {
  429.         $this->parent $parent;
  430.     }
  431.     public function getParent()
  432.     {
  433.         return $this->parent;
  434.     }
  435.     public function getChildren() {
  436.         return $this->children;
  437.     }
  438.     public function addChild(Item $child): self
  439.     {
  440.         if (!$this->children->contains($child)) {
  441.             $this->children->add($child);
  442.             $child->setParent($this);
  443.         }
  444.         return $this;
  445.     }
  446.     public function removeChild(Item $child): self
  447.     {
  448.         if ($this->children->removeElement($child)) {
  449.             // set the owning side to null (unless already changed)
  450.             if ($child->getParent() === $this) {
  451.                 $child->setParent(null);
  452.             }
  453.         }
  454.         return $this;
  455.     }
  456. }