<?php
namespace App\Entity;
use App\Entity\Traits\CommonTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\ItemRepository")
* @UniqueEntity(fields={"slug"})
* @ORM\Table(name="itm_item")
* @ORM\HasLifecycleCallbacks()
*/
class Item
{
use CommonTrait;
/**
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
*/
private $slug;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(
* min = 10,
* max = 100,
* minMessage = "Tytuł musi zawierać minimalnie {{ limit }} znaków",
* maxMessage = "Tyytł może zawierać maksymalnie {{ limit }} znaków"
* )
* @Assert\NotNull(message="Tytuł nie może być pusty")
*/
private $title;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="items")
* @ORM\JoinColumn(nullable=false)
*/
private $author;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\ItemSpec")
* @ORM\JoinTable(name="itm_item_spec")
*/
private $specs;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ItemCategory", inversedBy="items")
* @ORM\JoinColumn(nullable=true)
*/
private $itemCategory;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ItemPhoto", mappedBy="item", orphanRemoval=true)
*/
private $itemPhotos;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserSaveItem", mappedBy="item", orphanRemoval=true)
*/
private $userSaveItems;
/**
* @ORM\Column(type="decimal", precision=20, scale=2, nullable=true)
*/
private $price;
/**
* @ORM\OneToOne(targetEntity=ItemVideo::class, mappedBy="item", cascade={"persist", "remove"})
*/
private $itemVideo;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $priceType;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $fv;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $location = [];
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $locationName;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isExpired;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $priceNegotiation;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $state;
/**
* @ORM\ManyToMany(targetEntity=ItemPromotion::class)
*/
private $promotions;
/**
* @ORM\OneToMany(targetEntity=PromoPayTransaction::class, mappedBy="item", orphanRemoval=true)
*/
private $promoPayTransactions;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $homePagePromo;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $listBigPromo;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $listShadowPromo;
/**
* @ORM\ManyToOne(targetEntity="Item", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="Item", mappedBy="parent")
*/
private $children;
public function __construct()
{
$this->specs = new ArrayCollection();
$this->itemPhotos = new ArrayCollection();
$this->userSaveItems = new ArrayCollection();
$this->promotions = new ArrayCollection();
$this->promoPayTransactions = new ArrayCollection();
$this->children = new ArrayCollection();
}
public function __toString()
{
if($this->title && strlen($this->title) > 0) {
return $this->title;
}
return '';
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getTitle(): ?string
{
if($this->title && strlen($this->title) > 0) {
return $this->title;
}
return '';
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): self
{
$this->author = $author;
return $this;
}
/**
* @return Collection|ItemSpec[]
*/
public function getSpecs(): Collection
{
return $this->specs;
}
public function addSpec(ItemSpec $spec): self
{
if (!$this->specs->contains($spec)) {
$this->specs[] = $spec;
}
return $this;
}
public function removeSpec(ItemSpec $spec): self
{
if ($this->specs->contains($spec)) {
$this->specs->removeElement($spec);
}
return $this;
}
/**
* @return Item
*/
public function setSpecs($specs)
{
$this->specs = $specs;
return $this;
}
public function getItemCategory(): ?ItemCategory
{
return $this->itemCategory;
}
public function setItemCategory(?ItemCategory $itemCategory): self
{
$this->itemCategory = $itemCategory;
return $this;
}
/**
* @return Collection|ItemPhoto[]
*/
public function getItemPhotos(): Collection
{
return $this->itemPhotos;
}
public function addItemPhoto(ItemPhoto $itemPhoto): self
{
if (!$this->itemPhotos->contains($itemPhoto)) {
$this->itemPhotos[] = $itemPhoto;
$itemPhoto->setItem($this);
}
return $this;
}
public function removeItemPhoto(ItemPhoto $itemPhoto): self
{
if ($this->itemPhotos->contains($itemPhoto)) {
$this->itemPhotos->removeElement($itemPhoto);
// set the owning side to null (unless already changed)
if ($itemPhoto->getItem() === $this) {
$itemPhoto->setItem(null);
}
}
return $this;
}
/**
* @return Collection|UserSaveItem[]
*/
public function getUserSaveItems(): Collection
{
return $this->userSaveItems;
}
public function addUserSaveItem(UserSaveItem $userSaveItem): self
{
if (!$this->userSaveItems->contains($userSaveItem)) {
$this->userSaveItems[] = $userSaveItem;
$userSaveItem->setItem($this);
}
return $this;
}
public function removeUserSaveItem(UserSaveItem $userSaveItem): self
{
if ($this->userSaveItems->contains($userSaveItem)) {
$this->userSaveItems->removeElement($userSaveItem);
// set the owning side to null (unless already changed)
if ($userSaveItem->getItem() === $this) {
$userSaveItem->setItem(null);
}
}
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(string $price): self
{
$this->price = $price;
return $this;
}
public function getItemVideo(): ?ItemVideo
{
return $this->itemVideo;
}
public function setItemVideo(?ItemVideo $itemVideo): self
{
$this->itemVideo = $itemVideo;
// set (or unset) the owning side of the relation if necessary
$newItem = null === $itemVideo ? null : $this;
if ($itemVideo->getItem() !== $newItem) {
$itemVideo->setItem($newItem);
}
return $this;
}
public function getPriceType(): ?string
{
return $this->priceType;
}
public function setPriceType(?string $priceType): self
{
$this->priceType = $priceType;
return $this;
}
public function getFv(): ?string
{
return $this->fv;
}
public function setFv(?string $fv): self
{
$this->fv = $fv;
return $this;
}
public function getLocation(): ?array
{
return $this->location;
}
public function setLocation(?array $location): self
{
$this->location = $location;
return $this;
}
public function getLocationName(): ?string
{
return $this->locationName;
}
public function setLocationName(?string $locationName): self
{
$this->locationName = $locationName;
return $this;
}
public function getIsExpired(): ?bool
{
return $this->isExpired;
}
public function setIsExpired(?bool $isExpired): self
{
$this->isExpired = $isExpired;
return $this;
}
public function getPriceNegotiation(): ?bool
{
return $this->priceNegotiation;
}
public function setPriceNegotiation(?bool $priceNegotiation): self
{
$this->priceNegotiation = $priceNegotiation;
return $this;
}
public function getState(): ?string
{
return $this->state;
}
public function setState(?string $state): self
{
$this->state = $state;
return $this;
}
/**
* @return Collection|ItemPromotion[]
*/
public function getPromotions(): Collection
{
return $this->promotions;
}
public function addPromotion(ItemPromotion $promotion): self
{
if (!$this->promotions->contains($promotion)) {
$this->promotions[] = $promotion;
}
return $this;
}
public function removePromotion(ItemPromotion $promotion): self
{
$this->promotions->removeElement($promotion);
return $this;
}
/**
* @return Collection|PromoPayTransaction[]
*/
public function getPromoPayTransactions(): Collection
{
return $this->promoPayTransactions;
}
public function addPromoPayTransaction(PromoPayTransaction $promoPayTransaction): self
{
if (!$this->promoPayTransactions->contains($promoPayTransaction)) {
$this->promoPayTransactions[] = $promoPayTransaction;
$promoPayTransaction->setItem($this);
}
return $this;
}
public function removePromoPayTransaction(PromoPayTransaction $promoPayTransaction): self
{
if ($this->promoPayTransactions->removeElement($promoPayTransaction)) {
// set the owning side to null (unless already changed)
if ($promoPayTransaction->getItem() === $this) {
$promoPayTransaction->setItem(null);
}
}
return $this;
}
public function getHomePagePromo(): ?bool
{
return $this->homePagePromo;
}
public function setHomePagePromo(?bool $homePagePromo): self
{
$this->homePagePromo = $homePagePromo;
return $this;
}
public function getListBigPromo(): ?bool
{
return $this->listBigPromo;
}
public function setListBigPromo(?bool $listBigPromo): self
{
$this->listBigPromo = $listBigPromo;
return $this;
}
public function getListShadowPromo(): ?bool
{
return $this->listShadowPromo;
}
public function setListShadowPromo(?bool $listShadowPromo): self
{
$this->listShadowPromo = $listShadowPromo;
return $this;
}
public function setParent(Item $parent = null)
{
$this->parent = $parent;
}
public function getParent()
{
return $this->parent;
}
public function getChildren() {
return $this->children;
}
public function addChild(Item $child): self
{
if (!$this->children->contains($child)) {
$this->children->add($child);
$child->setParent($this);
}
return $this;
}
public function removeChild(Item $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
}