<?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 Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @Doctrine\ORM\Mapping\Entity
* @Doctrine\ORM\Mapping\Table(name="listing_marker")
*/
class ListingMarker implements BlameableInterface, TimestampableInterface {
use BlameableTrait;
use TimestampableTrait;
const GREEN = 'green';
const RED = 'red';
const YELLOW = 'yellow';
static public function getColors(TranslatorInterface $translator) {
return [
$translator->trans(self::GREEN, [], 'admin') => self::GREEN,
$translator->trans(self::RED, [], 'admin') => self::RED,
$translator->trans(self::YELLOW, [], 'admin') => self::YELLOW,
];
}
/**
* @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Product")
* @Doctrine\ORM\Mapping\JoinTable(name="listing_marker_product")
*/
private $products;
/**
* @Doctrine\ORM\Mapping\Id
* @Doctrine\ORM\Mapping\Column(type="integer")
* @Doctrine\ORM\Mapping\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Doctrine\ORM\Mapping\Column(type="text", name="content")
*/
protected $content;
/**
* @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\Language")
* @Doctrine\ORM\Mapping\JoinColumn(name="language", referencedColumnName="id")
*/
protected $language;
/**
* @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\ProductProducer", inversedBy="listingMarkers")
* @Doctrine\ORM\Mapping\JoinColumn(name="product_producer_id", referencedColumnName="id")
*/
protected $productProducer;
/**
* @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\LandingPage", inversedBy="markers")
* @Doctrine\ORM\Mapping\JoinColumn(name="landing_page_id", referencedColumnName="id")
*/
protected $landingPage;
/**
* @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\Availability")
* @Doctrine\ORM\Mapping\JoinColumn(name="availability_id", referencedColumnName="id")
*/
protected $availability;
/**
*
* note This is not a mapped field of entity metadata, just a simple property.
*
* @var File $imageFile
*/
protected $imageFile;
/**
* @Doctrine\ORM\Mapping\Column(type="string", length=255, name="image_name", nullable=true)
* @var string $imageName
*/
protected $imageName;
/**
* @Doctrine\ORM\Mapping\Column(type="string", length=255, name="marker_text", nullable=true)
*/
protected $text;
/**
* @Doctrine\ORM\Mapping\Column(type="string", length=255, name="background_color", nullable=true)
*/
protected $backgroundColor;
/**
* @Doctrine\ORM\Mapping\Column(type="string", length=255, name="text_color", nullable=true)
*/
protected $textColor;
/**
* @Doctrine\ORM\Mapping\Column(name="is_active", type="boolean", options={"default"=0}, nullable=true)
*/
protected $active;
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl($url)
{
$this->url = $url;
}
/**
* @Doctrine\ORM\Mapping\Column(type="string", length=255, name="url", nullable=true)
* @var string $url
*/
protected $url;
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/important/';
$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;
}
public function __construct()
{
$this->products = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getLanguage(): ?Language
{
return $this->language;
}
public function setLanguage(?Language $language): self
{
$this->language = $language;
return $this;
}
public function getProductProducer(): ?ProductProducer
{
return $this->productProducer;
}
public function setProductProducer(?ProductProducer $productProducer): self
{
$this->productProducer = $productProducer;
return $this;
}
public function getLandingPage(): ?LandingPage
{
return $this->landingPage;
}
public function setLandingPage(?LandingPage $landingPage): self
{
$this->landingPage = $landingPage;
return $this;
}
/**
* @return Collection|Product[]
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->addMarker($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->contains($product)) {
$this->products->removeElement($product);
$product->removeMarker($this);
}
return $this;
}
public function getAvailability(): ?Availability
{
return $this->availability;
}
public function setAvailability(?Availability $availability): self
{
$this->availability = $availability;
return $this;
}
/**
* @return mixed
*/
public function getActive()
{
return $this->active;
}
/**
* @param mixed $active
*/
public function setActive($active): void
{
$this->active = $active;
}
/**
* @return mixed
*/
public function getText()
{
return $this->text;
}
/**
* @param mixed $text
*/
public function setText($text)
{
$this->text = $text;
}
/**
* @return mixed
*/
public function getBackgroundColor()
{
return $this->backgroundColor;
}
/**
* @param mixed $backgroundColor
*/
public function setBackgroundColor($backgroundColor)
{
$this->backgroundColor = $backgroundColor;
}
/**
* @return mixed
*/
public function getTextColor()
{
return $this->textColor;
}
/**
* @param mixed $textColor
*/
public function setTextColor($textColor)
{
$this->textColor = $textColor;
}
}