<?php
namespace App\Entity;
use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
use AppBundle\Entity\Article;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity
* @ORM\Table(name="product_producer")
*/
class ProductProducer implements BlameableInterface, TimestampableInterface, SoftDeletableInterface {
use BlameableTrait;
use TimestampableTrait;
use SoftDeletableTrait;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="responsible_entity", type="string", length=1024, nullable=true)
*/
private $responsibleEntity;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\Marker", mappedBy="productProducer", cascade={"persist"})
*/
protected $markers;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ListingMarker", mappedBy="productProducer", cascade={"persist"})
*/
protected $listingMarkers;
/**
* Landing page do redirectu, gdy klikamy logo
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\LandingPage")
* @Doctrine\ORM\Mapping\JoinTable(name="producer_landing_page",
* joinColumns={@Doctrine\ORM\Mapping\JoinColumn(name="landing_page_id", referencedColumnName="id")},
* inverseJoinColumns={@Doctrine\ORM\Mapping\JoinColumn(name="product_producer_id", referencedColumnName="id")}
* )
**/
protected $redirectLadingPages;
/**
* Wersje językowe, gdzie logo ma być widoczne
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Language")
* @Doctrine\ORM\Mapping\JoinTable(name="product_producer_languages",
* joinColumns={@Doctrine\ORM\Mapping\JoinColumn(name="product_producer_id", referencedColumnName="id")},
* inverseJoinColumns={@Doctrine\ORM\Mapping\JoinColumn(name="language_id", referencedColumnName="id")}
* )
**/
protected $languages;
/**
* @Doctrine\ORM\Mapping\OneToMany(targetEntity="App\Entity\ProductProducerPriceChange", mappedBy="productProducer", cascade={"persist"})
*/
protected $priceChanges;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return ProductProducer
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
*
* note This is not a mapped field of entity metadata, just a simple property.
*
* @var File $imageFile
*/
protected $imageFile;
/**
* @ORM\Column(type="string", length=255, name="image_name", nullable=true)
* @var string $imageName
*/
protected $imageName;
public function __construct()
{
$this->markers = new ArrayCollection();
$this->redirectLadingPages = new ArrayCollection();
$this->listingMarkers = new ArrayCollection();
$this->languages = new \Doctrine\Common\Collections\ArrayCollection();
$this->priceChanges = new ArrayCollection();
}
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
$fileName = md5(uniqid()).'.'.$image->guessExtension();
// Move the file to the directory where brochures are stored
$brochuresDir = getcwd().'/images/producer/';
$image->move($brochuresDir, $fileName);
// Update the 'brochure' property to store the PDF file name
// instead of its contents
$this->setImageName($fileName);
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @return File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param string $imageName
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
}
/**
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
/**
* @return Collection|Marker[]
*/
public function getMarkers(): Collection
{
return $this->markers;
}
public function addMarker(Marker $marker): self
{
if (!$this->markers->contains($marker)) {
$this->markers[] = $marker;
$marker->setProductProducer($this);
}
return $this;
}
public function removeMarker(Marker $marker): self
{
if ($this->markers->contains($marker)) {
$this->markers->removeElement($marker);
// set the owning side to null (unless already changed)
if ($marker->getProductProducer() === $this) {
$marker->setProductProducer(null);
}
}
return $this;
}
/**
* @return Collection|LandingPage[]
*/
public function getRedirectLadingPages(): Collection
{
return $this->redirectLadingPages;
}
public function addRedirectLadingPage(LandingPage $redirectLadingPage): self
{
if (!$this->redirectLadingPages->contains($redirectLadingPage)) {
$this->redirectLadingPages[] = $redirectLadingPage;
}
return $this;
}
public function removeRedirectLadingPage(LandingPage $redirectLadingPage): self
{
if ($this->redirectLadingPages->contains($redirectLadingPage)) {
$this->redirectLadingPages->removeElement($redirectLadingPage);
}
return $this;
}
/**
* @return Collection|ListingMarker[]
*/
public function getListingMarkers(): Collection
{
return $this->listingMarkers;
}
public function addListingMarker(ListingMarker $listingMarker): self
{
if (!$this->listingMarkers->contains($listingMarker)) {
$this->listingMarkers[] = $listingMarker;
$listingMarker->setProductProducer($this);
}
return $this;
}
public function removeListingMarker(ListingMarker $listingMarker): self
{
if ($this->listingMarkers->contains($listingMarker)) {
$this->listingMarkers->removeElement($listingMarker);
// set the owning side to null (unless already changed)
if ($listingMarker->getProductProducer() === $this) {
$listingMarker->setProductProducer(null);
}
}
return $this;
}
/**
* @return Collection|ProductProducerPriceChange[]
*/
public function getPriceChanges(): Collection
{
return $this->priceChanges;
}
public function addPriceChange(ProductProducerPriceChange $priceChange): self
{
if (!$this->priceChanges->contains($priceChange)) {
$this->priceChanges[] = $priceChange;
$priceChange->setProductProducer($this);
}
return $this;
}
public function removePriceChange(ProductProducerPriceChange $priceChange): self
{
if ($this->priceChanges->removeElement($priceChange)) {
// set the owning side to null (unless already changed)
if ($priceChange->getProductProducer() === $this) {
$priceChange->setProductProducer(null);
}
}
return $this;
}
/**
* Add language
*
* @param \App\Entity\Language $language
*
* @return ProductProducer
*/
public function addLanguage(\App\Entity\Language $language)
{
$this->languages[] = $language;
return $this;
}
/**
* Remove language
*
* @param \App\Entity\Language $language
*/
public function removeLanguage(\App\Entity\Language $language)
{
$this->languages->removeElement($language);
}
/**
* Get languages
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getLanguages()
{
return $this->languages;
}
/**
* @return string
*/
public function getResponsibleEntity()
{
return $this->responsibleEntity;
}
/**
* @param string $responsibleEntity
*/
public function setResponsibleEntity($responsibleEntity)
{
$this->responsibleEntity = $responsibleEntity;
}
}