src/Entity/Otpusk/Selection.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Otpusk;
  3. use App\Repository\Otpusk\SelectionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  9. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. /**
  13.  * @ORM\Entity(repositoryClass=SelectionRepository::class)
  14.  * @Vich\Uploadable()
  15.  */
  16. class Selection implements TranslatableInterface
  17. {
  18.     use TimestampableEntity;
  19.     use TranslatableTrait;
  20.     private $imgFolder '/upload/';
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=1024)
  29.      */
  30.     private $name;
  31.     /**
  32.      * @ORM\Column(type="string", length=255)
  33.      */
  34.     private $slug;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private $image;
  39.     /**
  40.      * @Vich\UploadableField(mapping="images", fileNameProperty="image")
  41.      */
  42.     private $imageFile;
  43.     /**
  44.      * @ORM\Column(type="boolean", options={"default": 1})
  45.      */
  46.     private $published true;
  47.     /**
  48.      * @ORM\Column(type="boolean", options={"default": 0})
  49.      */
  50.     private $showHP;
  51.     /**
  52.      * @var integer
  53.      * @Gedmo\SortablePosition
  54.      * @ORM\Column(name="priority", type="integer", options={"default":0}, nullable=true)
  55.      */
  56.     private $position 0;
  57.     /**
  58.      * @var Collection|SelectionCriteria[]
  59.      * @ORM\OneToMany(targetEntity="App\Entity\Otpusk\SelectionCriteria", mappedBy="selection")
  60.      */
  61.     private $criteries;
  62.     /**
  63.      * @var \DateTime
  64.      * @ORM\Column(type="datetime", nullable=true)
  65.      */
  66.     protected $cronUpdatedAt;
  67.     /**
  68.      * @ORM\Column(type="boolean", options={"default": 0})
  69.      */
  70.     private $needUpdate;
  71.     /**
  72.      * @ORM\ManyToMany(targetEntity="App\Entity\Otpusk\Market", inversedBy="selections")
  73.      * @ORM\JoinTable(
  74.      *     name="SelectionMarket",
  75.      *     joinColumns={@ORM\JoinColumn(name="selection_id", referencedColumnName="id")},
  76.      *     inverseJoinColumns={@ORM\JoinColumn(name="market_id", referencedColumnName="id")}
  77.      * )
  78.      */
  79.     private $markets;
  80.     /**
  81.      * @ORM\ManyToMany(targetEntity="App\Entity\Otpusk\Selection", inversedBy="selections")
  82.      * @ORM\JoinTable(
  83.      *     name="SelectionAlternative",
  84.      *     joinColumns={@ORM\JoinColumn(name="selection_source_id", referencedColumnName="id")},
  85.      *     inverseJoinColumns={@ORM\JoinColumn(name="selection_target_id", referencedColumnName="id")}
  86.      * )
  87.      */
  88.     private $alternativeSelections;
  89.     /**
  90.      * @ORM\ManyToMany(targetEntity="App\Entity\Otpusk\Selection", mappedBy="alternativeSelections")
  91.      * @ORM\JoinTable(
  92.      *     name="SelectionAlternative",
  93.      *     joinColumns={@ORM\JoinColumn(name="selection_target_id", referencedColumnName="id")},
  94.      *     inverseJoinColumns={@ORM\JoinColumn(name="selection_source_id", referencedColumnName="id")}
  95.      * )
  96.      */
  97.     private $selections;
  98.     public function __construct()
  99.     {
  100.         $this->markets = new ArrayCollection();
  101.         $this->alternativeSelections = new ArrayCollection();
  102.         $this->selections = new ArrayCollection();
  103.         $this->criteries = new ArrayCollection();
  104.         $this->updatedAt = new \DateTime();
  105.     }
  106.     public function getId(): ?int
  107.     {
  108.         return $this->id;
  109.     }
  110.     public function getName(): ?string
  111.     {
  112.         return $this->name;
  113.     }
  114.     public function setName(string $name): self
  115.     {
  116.         $this->name $name;
  117.         return $this;
  118.     }
  119.     public function getSlug(): ?string
  120.     {
  121.         return $this->slug;
  122.     }
  123.     public function setSlug(string $slug): self
  124.     {
  125.         $this->slug $slug;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return mixed
  130.      */
  131.     public function getImage()
  132.     {
  133.         return $this->image;
  134.     }
  135.     /**
  136.      * @param mixed $image
  137.      */
  138.     public function setImage($image): void
  139.     {
  140.         $this->image $image;
  141.     }
  142.     public function getLinkImage()
  143.     {
  144.         return (!is_null($this->getImage())) ? $this->imgFolder.$this->getImage() : '#';
  145.     }
  146.     /**
  147.      * @return mixed
  148.      */
  149.     public function getImageFile()
  150.     {
  151.         return $this->imageFile;
  152.     }
  153.     /**
  154.      * @param mixed $imageFile
  155.      */
  156.     public function setImageFile($imageFile null): void
  157.     {
  158.         $this->imageFile $imageFile;
  159.         if ($imageFile) {
  160.             $this->updatedAt = new \DateTime();
  161.         }
  162.     }
  163.     public function getPublished(): ?bool
  164.     {
  165.         return $this->published;
  166.     }
  167.     public function setPublished(bool $published): self
  168.     {
  169.         $this->published $published;
  170.         return $this;
  171.     }
  172.     public function getShowHP(): ?bool
  173.     {
  174.         return $this->showHP;
  175.     }
  176.     public function setShowHP(bool $showHP): self
  177.     {
  178.         $this->showHP $showHP;
  179.         return $this;
  180.     }
  181.     public function getPosition(): ?int
  182.     {
  183.         return $this->position;
  184.     }
  185.     public function setPosition(?int $position): self
  186.     {
  187.         $this->position = (!is_null($position))?$position:0;
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return Collection|SelectionCriteria[]
  192.      */
  193.     public function getCriteries(): Collection
  194.     {
  195.         return $this->criteries;
  196.     }
  197.     public function addCriteria(SelectionCriteria $criteria): self
  198.     {
  199.         if (!$this->criteries->contains($criteria)) {
  200.             $this->criteries[] = $criteria;
  201.             $criteria->setSelection($this);
  202.         }
  203.         return $this;
  204.     }
  205.     public function removeCriteria(SelectionCriteria $criteria): self
  206.     {
  207.         if ($this->criteries->contains($criteria)) {
  208.             $this->criteries->removeElement($criteria);
  209.             if ($criteria->getSelection() === $this) {
  210.                 $criteria->setSelection(null);
  211.             }
  212.         }
  213.         return $this;
  214.     }
  215.     public function setCronUpdatedAt(?\DateTime $cronUpdatedAt)
  216.     {
  217.         $this->cronUpdatedAt $cronUpdatedAt;
  218.         return $this;
  219.     }
  220.     public function getCronUpdatedAt(): ?\DateTime
  221.     {
  222.         return $this->cronUpdatedAt;
  223.     }
  224.     public function getNeedUpdate(): ?bool
  225.     {
  226.         return $this->needUpdate;
  227.     }
  228.     public function setNeedUpdate(bool $needUpdate): self
  229.     {
  230.         $this->needUpdate $needUpdate;
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return Collection|Market[]
  235.      */
  236.     public function getMarkets(): Collection
  237.     {
  238.         return $this->markets;
  239.     }
  240.     public function getMarketsName()
  241.     {
  242.         $markets = [];
  243.         foreach ($this->markets as $market) {
  244.             $markets[] = $market->getName();
  245.         }
  246.         return $markets;
  247.     }
  248.     public function addMarket(Market $market): self
  249.     {
  250.         if (!$this->markets->contains($market)) {
  251.             $this->markets[] = $market;
  252.         }
  253.         if (!$market->getSelections()->contains($this)) {
  254.             $market->getSelections()->add($this);
  255.         }
  256.         return $this;
  257.     }
  258.     public function removeMarket(Market $market): self
  259.     {
  260.         if ($this->markets->contains($market)) {
  261.             $this->markets->removeElement($market);
  262.         }
  263.         if ($market->getSelections()->contains($this)) {
  264.             $market->getSelections()->removeElement($this);
  265.         }
  266.         return $this;
  267.     }
  268.     /**
  269.      * @return Collection|Selection[]
  270.      */
  271.     public function getAlternativeSelections(): Collection
  272.     {
  273.         return $this->alternativeSelections;
  274.     }
  275.     public function getAlternativeSelectionsName()
  276.     {
  277.         $alternativeSelections = [];
  278.         foreach ($this->alternativeSelections as $alternativeSelection) {
  279.             $alternativeSelections[] = $alternativeSelection->getName();
  280.         }
  281.         return $alternativeSelections;
  282.     }
  283.     public function addAlternativeSelection(Selection $alternativeSelection): self
  284.     {
  285.         if (!$this->alternativeSelections->contains($alternativeSelection)) {
  286.             $this->alternativeSelections[] = $alternativeSelection;
  287.         }
  288.         if (!$alternativeSelection->getAlternativeSelections()->contains($this)) {
  289.             $alternativeSelection->getAlternativeSelections()->add($this);
  290.         }
  291.         return $this;
  292.     }
  293.     public function removeAlternativeSelection(Selection $alternativeSelection): self
  294.     {
  295.         if ($this->alternativeSelections->contains($alternativeSelection)) {
  296.             $this->alternativeSelections->removeElement($alternativeSelection);
  297.         }
  298.         if ($alternativeSelection->getAlternativeSelections()->contains($this)) {
  299.             $alternativeSelection->getAlternativeSelections()->removeElement($this);
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return Collection|Selection[]
  305.      */
  306.     public function getSelections()
  307.     {
  308.         return $this->selections;
  309.     }
  310.     public function __toString()
  311.     {
  312.         return $this->getId() . '. ' $this->getName();
  313.     }
  314. }