src/Entity/ListingMarker.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  4. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  5. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
  6. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  7. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. /**
  14.  * @Doctrine\ORM\Mapping\Entity
  15.  * @Doctrine\ORM\Mapping\Table(name="listing_marker")
  16.  */
  17. class ListingMarker implements BlameableInterfaceTimestampableInterface  {
  18.     use BlameableTrait;
  19.     use TimestampableTrait;
  20.     const GREEN 'green';
  21.     const RED 'red';
  22.     const YELLOW 'yellow';
  23.     static public function getColors(TranslatorInterface $translator) {
  24.         return [
  25.             $translator->trans(self::GREEN, [], 'admin') => self::GREEN,
  26.             $translator->trans(self::RED, [], 'admin') => self::RED,
  27.             $translator->trans(self::YELLOW, [], 'admin') => self::YELLOW,
  28.         ];
  29.     }
  30.     /**
  31.      * @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Product")
  32.      * @Doctrine\ORM\Mapping\JoinTable(name="listing_marker_product")
  33.      */
  34.     private $products;
  35.     /**
  36.      * @Doctrine\ORM\Mapping\Id
  37.      * @Doctrine\ORM\Mapping\Column(type="integer")
  38.      * @Doctrine\ORM\Mapping\GeneratedValue(strategy="AUTO")
  39.      */
  40.     protected $id;
  41.     /**
  42.      * @Doctrine\ORM\Mapping\Column(type="text", name="content")
  43.      */
  44.     protected $content;
  45.     /**
  46.      * @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\Language")
  47.      * @Doctrine\ORM\Mapping\JoinColumn(name="language", referencedColumnName="id")
  48.      */
  49.     protected $language;
  50.     /**
  51.      * @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\ProductProducer", inversedBy="listingMarkers")
  52.      * @Doctrine\ORM\Mapping\JoinColumn(name="product_producer_id", referencedColumnName="id")
  53.      */
  54.     protected $productProducer;
  55.     /**
  56.      * @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\LandingPage", inversedBy="markers")
  57.      * @Doctrine\ORM\Mapping\JoinColumn(name="landing_page_id", referencedColumnName="id")
  58.      */
  59.     protected $landingPage;
  60.     /**
  61.      * @Doctrine\ORM\Mapping\ManyToOne(targetEntity="App\Entity\Availability")
  62.      * @Doctrine\ORM\Mapping\JoinColumn(name="availability_id", referencedColumnName="id")
  63.      */
  64.     protected $availability;
  65.     /**
  66.      *
  67.      * note This is not a mapped field of entity metadata, just a simple property.
  68.      *
  69.      * @var File $imageFile
  70.      */
  71.     protected $imageFile;
  72.     /**
  73.      * @Doctrine\ORM\Mapping\Column(type="string", length=255, name="image_name", nullable=true)
  74.      * @var string $imageName
  75.      */
  76.     protected $imageName;
  77.     /**
  78.      * @Doctrine\ORM\Mapping\Column(type="string", length=255, name="marker_text", nullable=true)
  79.      */
  80.     protected $text;
  81.     /**
  82.      * @Doctrine\ORM\Mapping\Column(type="string", length=255, name="background_color", nullable=true)
  83.      */
  84.     protected $backgroundColor;
  85.     /**
  86.      * @Doctrine\ORM\Mapping\Column(type="string", length=255, name="text_color", nullable=true)
  87.      */
  88.     protected $textColor;
  89.     /**
  90.      * @Doctrine\ORM\Mapping\Column(name="is_active", type="boolean", options={"default"=0}, nullable=true)
  91.      */
  92.     protected $active;
  93.     /**
  94.      * @return string
  95.      */
  96.     public function getUrl()
  97.     {
  98.         return $this->url;
  99.     }
  100.     /**
  101.      * @param string $url
  102.      */
  103.     public function setUrl($url)
  104.     {
  105.         $this->url $url;
  106.     }
  107.     /**
  108.      * @Doctrine\ORM\Mapping\Column(type="string", length=255, name="url", nullable=true)
  109.      * @var string $url
  110.      */
  111.     protected $url;
  112.     public function setImageFile(File $image null)
  113.     {
  114.         $this->imageFile $image;
  115.         if ($image) {
  116.             $fileName md5(uniqid()).'.'.$image->guessExtension();
  117.             // Move the file to the directory where brochures are stored
  118.             $brochuresDir getcwd().'/images/important/';
  119.             $image->move($brochuresDir$fileName);
  120.             // Update the 'brochure' property to store the PDF file name
  121.             // instead of its contents
  122.             $this->setImageName($fileName);
  123.             $this->updatedAt = new \DateTime('now');
  124.         }
  125.         return $this;
  126.     }
  127.     /**
  128.      * @return File
  129.      */
  130.     public function getImageFile()
  131.     {
  132.         return $this->imageFile;
  133.     }
  134.     /**
  135.      * @param string $imageName
  136.      */
  137.     public function setImageName($imageName)
  138.     {
  139.         $this->imageName $imageName;
  140.     }
  141.     /**
  142.      * @return string
  143.      */
  144.     public function getImageName()
  145.     {
  146.         return $this->imageName;
  147.     }
  148.     public function __construct()
  149.     {
  150.         $this->products = new ArrayCollection();
  151.     }
  152.     public function getId(): ?int
  153.     {
  154.         return $this->id;
  155.     }
  156.     public function getContent(): ?string
  157.     {
  158.         return $this->content;
  159.     }
  160.     public function setContent(string $content): self
  161.     {
  162.         $this->content $content;
  163.         return $this;
  164.     }
  165.     public function getLanguage(): ?Language
  166.     {
  167.         return $this->language;
  168.     }
  169.     public function setLanguage(?Language $language): self
  170.     {
  171.         $this->language $language;
  172.         return $this;
  173.     }
  174.     public function getProductProducer(): ?ProductProducer
  175.     {
  176.         return $this->productProducer;
  177.     }
  178.     public function setProductProducer(?ProductProducer $productProducer): self
  179.     {
  180.         $this->productProducer $productProducer;
  181.         return $this;
  182.     }
  183.     public function getLandingPage(): ?LandingPage
  184.     {
  185.         return $this->landingPage;
  186.     }
  187.     public function setLandingPage(?LandingPage $landingPage): self
  188.     {
  189.         $this->landingPage $landingPage;
  190.         return $this;
  191.     }
  192.     /**
  193.      * @return Collection|Product[]
  194.      */
  195.     public function getProducts(): Collection
  196.     {
  197.         return $this->products;
  198.     }
  199.     public function addProduct(Product $product): self
  200.     {
  201.         if (!$this->products->contains($product)) {
  202.             $this->products[] = $product;
  203.             $product->addMarker($this);
  204.         }
  205.         return $this;
  206.     }
  207.     public function removeProduct(Product $product): self
  208.     {
  209.         if ($this->products->contains($product)) {
  210.             $this->products->removeElement($product);
  211.             $product->removeMarker($this);
  212.         }
  213.         return $this;
  214.     }
  215.     public function getAvailability(): ?Availability
  216.     {
  217.         return $this->availability;
  218.     }
  219.     public function setAvailability(?Availability $availability): self
  220.     {
  221.         $this->availability $availability;
  222.         return $this;
  223.     }
  224.     /**
  225.      * @return mixed
  226.      */
  227.     public function getActive()
  228.     {
  229.         return $this->active;
  230.     }
  231.     /**
  232.      * @param mixed $active
  233.      */
  234.     public function setActive($active): void
  235.     {
  236.         $this->active $active;
  237.     }
  238.     /**
  239.      * @return mixed
  240.      */
  241.     public function getText()
  242.     {
  243.         return $this->text;
  244.     }
  245.     /**
  246.      * @param mixed $text
  247.      */
  248.     public function setText($text)
  249.     {
  250.         $this->text $text;
  251.     }
  252.     /**
  253.      * @return mixed
  254.      */
  255.     public function getBackgroundColor()
  256.     {
  257.         return $this->backgroundColor;
  258.     }
  259.     /**
  260.      * @param mixed $backgroundColor
  261.      */
  262.     public function setBackgroundColor($backgroundColor)
  263.     {
  264.         $this->backgroundColor $backgroundColor;
  265.     }
  266.     /**
  267.      * @return mixed
  268.      */
  269.     public function getTextColor()
  270.     {
  271.         return $this->textColor;
  272.     }
  273.     /**
  274.      * @param mixed $textColor
  275.      */
  276.     public function setTextColor($textColor)
  277.     {
  278.         $this->textColor $textColor;
  279.     }
  280. }