<?php
namespace App\Entity\Otpusk;
use App\Repository\Otpusk\SelectionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=SelectionRepository::class)
* @Vich\Uploadable()
*/
class Selection implements TranslatableInterface
{
use TimestampableEntity;
use TranslatableTrait;
private $imgFolder = '/upload/';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=1024)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @Vich\UploadableField(mapping="images", fileNameProperty="image")
*/
private $imageFile;
/**
* @ORM\Column(type="boolean", options={"default": 1})
*/
private $published = true;
/**
* @ORM\Column(type="boolean", options={"default": 0})
*/
private $showHP;
/**
* @var integer
* @Gedmo\SortablePosition
* @ORM\Column(name="priority", type="integer", options={"default":0}, nullable=true)
*/
private $position = 0;
/**
* @var Collection|SelectionCriteria[]
* @ORM\OneToMany(targetEntity="App\Entity\Otpusk\SelectionCriteria", mappedBy="selection")
*/
private $criteries;
/**
* @var \DateTime
* @ORM\Column(type="datetime", nullable=true)
*/
protected $cronUpdatedAt;
/**
* @ORM\Column(type="boolean", options={"default": 0})
*/
private $needUpdate;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Otpusk\Market", inversedBy="selections")
* @ORM\JoinTable(
* name="SelectionMarket",
* joinColumns={@ORM\JoinColumn(name="selection_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="market_id", referencedColumnName="id")}
* )
*/
private $markets;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Otpusk\Selection", inversedBy="selections")
* @ORM\JoinTable(
* name="SelectionAlternative",
* joinColumns={@ORM\JoinColumn(name="selection_source_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="selection_target_id", referencedColumnName="id")}
* )
*/
private $alternativeSelections;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Otpusk\Selection", mappedBy="alternativeSelections")
* @ORM\JoinTable(
* name="SelectionAlternative",
* joinColumns={@ORM\JoinColumn(name="selection_target_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="selection_source_id", referencedColumnName="id")}
* )
*/
private $selections;
public function __construct()
{
$this->markets = new ArrayCollection();
$this->alternativeSelections = new ArrayCollection();
$this->selections = new ArrayCollection();
$this->criteries = new ArrayCollection();
$this->updatedAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return mixed
*/
public function getImage()
{
return $this->image;
}
/**
* @param mixed $image
*/
public function setImage($image): void
{
$this->image = $image;
}
public function getLinkImage()
{
return (!is_null($this->getImage())) ? $this->imgFolder.$this->getImage() : '#';
}
/**
* @return mixed
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param mixed $imageFile
*/
public function setImageFile($imageFile = null): void
{
$this->imageFile = $imageFile;
if ($imageFile) {
$this->updatedAt = new \DateTime();
}
}
public function getPublished(): ?bool
{
return $this->published;
}
public function setPublished(bool $published): self
{
$this->published = $published;
return $this;
}
public function getShowHP(): ?bool
{
return $this->showHP;
}
public function setShowHP(bool $showHP): self
{
$this->showHP = $showHP;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): self
{
$this->position = (!is_null($position))?$position:0;
return $this;
}
/**
* @return Collection|SelectionCriteria[]
*/
public function getCriteries(): Collection
{
return $this->criteries;
}
public function addCriteria(SelectionCriteria $criteria): self
{
if (!$this->criteries->contains($criteria)) {
$this->criteries[] = $criteria;
$criteria->setSelection($this);
}
return $this;
}
public function removeCriteria(SelectionCriteria $criteria): self
{
if ($this->criteries->contains($criteria)) {
$this->criteries->removeElement($criteria);
if ($criteria->getSelection() === $this) {
$criteria->setSelection(null);
}
}
return $this;
}
public function setCronUpdatedAt(?\DateTime $cronUpdatedAt)
{
$this->cronUpdatedAt = $cronUpdatedAt;
return $this;
}
public function getCronUpdatedAt(): ?\DateTime
{
return $this->cronUpdatedAt;
}
public function getNeedUpdate(): ?bool
{
return $this->needUpdate;
}
public function setNeedUpdate(bool $needUpdate): self
{
$this->needUpdate = $needUpdate;
return $this;
}
/**
* @return Collection|Market[]
*/
public function getMarkets(): Collection
{
return $this->markets;
}
public function getMarketsName()
{
$markets = [];
foreach ($this->markets as $market) {
$markets[] = $market->getName();
}
return $markets;
}
public function addMarket(Market $market): self
{
if (!$this->markets->contains($market)) {
$this->markets[] = $market;
}
if (!$market->getSelections()->contains($this)) {
$market->getSelections()->add($this);
}
return $this;
}
public function removeMarket(Market $market): self
{
if ($this->markets->contains($market)) {
$this->markets->removeElement($market);
}
if ($market->getSelections()->contains($this)) {
$market->getSelections()->removeElement($this);
}
return $this;
}
/**
* @return Collection|Selection[]
*/
public function getAlternativeSelections(): Collection
{
return $this->alternativeSelections;
}
public function getAlternativeSelectionsName()
{
$alternativeSelections = [];
foreach ($this->alternativeSelections as $alternativeSelection) {
$alternativeSelections[] = $alternativeSelection->getName();
}
return $alternativeSelections;
}
public function addAlternativeSelection(Selection $alternativeSelection): self
{
if (!$this->alternativeSelections->contains($alternativeSelection)) {
$this->alternativeSelections[] = $alternativeSelection;
}
if (!$alternativeSelection->getAlternativeSelections()->contains($this)) {
$alternativeSelection->getAlternativeSelections()->add($this);
}
return $this;
}
public function removeAlternativeSelection(Selection $alternativeSelection): self
{
if ($this->alternativeSelections->contains($alternativeSelection)) {
$this->alternativeSelections->removeElement($alternativeSelection);
}
if ($alternativeSelection->getAlternativeSelections()->contains($this)) {
$alternativeSelection->getAlternativeSelections()->removeElement($this);
}
return $this;
}
/**
* @return Collection|Selection[]
*/
public function getSelections()
{
return $this->selections;
}
public function __toString()
{
return $this->getId() . '. ' . $this->getName();
}
}