src/Entity/Blog.php line 29

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 Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. use Symfony\Component\HttpFoundation\File\File;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. /**
  17.  * @ORM\Entity
  18.  * @ORM\Table(name="blog")
  19.  */
  20. class Blog implements BlameableInterfaceTimestampableInterfaceSoftDeletableInterface  {
  21.     use BlameableTrait;
  22.     use TimestampableTrait;
  23.     
  24.     use SoftDeletableTrait;
  25.     
  26. /**
  27.      * @ORM\Id
  28.      * @ORM\Column(type="integer")
  29.      * @ORM\GeneratedValue(strategy="AUTO")
  30.      */
  31.     protected $id;
  32.     /**
  33.      * @var string
  34.      *
  35.      * @ORM\Column(name="title", type="string", length=255, nullable=true)
  36.      */
  37.     private $title;
  38.     /**
  39.      * @ORM\ManyToOne(targetEntity="App\Entity\Language")
  40.      * @ORM\JoinColumn(name="language", referencedColumnName="id")
  41.      */
  42.     protected $language;
  43.     /**
  44.      * @var string  
  45.      *
  46.      * @ORM\Column(name="content", type="text", nullable=true)
  47.      */
  48.     private $content;
  49.     /**
  50.      * @var string
  51.      *
  52.      * @ORM\Column(name="meta_title", type="text", nullable=true)
  53.      */
  54.     private $metaTitle;
  55.     /**
  56.      * @var string
  57.      *
  58.      * @ORM\Column(name="meta_description", type="text", nullable=true)
  59.      */
  60.     private $metaDescription;
  61.     /**
  62.      * @var string
  63.      *
  64.      * @ORM\Column(name="meta_keywords", type="text", nullable=true)
  65.      */
  66.     private $metaKeywords;
  67.     /**
  68.      * @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Product")
  69.      * @Doctrine\ORM\Mapping\JoinTable(name="blog_entry_products")
  70.      */
  71.     private $products;
  72.     /**
  73.      * @var string
  74.      *
  75.      * @ORM\Column(name="alt", type="string", length=255, nullable=true)
  76.      */
  77.     private $alt;
  78.     /**
  79.      * @var string
  80.      *
  81.      * @ORM\Column(name="image_custom_name", type="string", length=255, nullable=true)
  82.      */
  83.     private $imageCustomName;
  84.     /**
  85.      * @return string
  86.      */
  87.     public function getTags()
  88.     {
  89.         return $this->tags;
  90.     }
  91.     /**
  92.      * @param string $tags
  93.      */
  94.     public function setTags($tags)
  95.     {
  96.         $this->tags $tags;
  97.     }
  98.     /**
  99.      * @var string
  100.      *
  101.      * @ORM\Column(name="tags", type="text", nullable=true)
  102.      */
  103.     private $tags;
  104.     /**
  105.      * @var string
  106.      *
  107.      * @ORM\Column(name="slug", type="text", nullable=true)
  108.      */
  109.     private $slug;
  110.     /**
  111.      * @var File $imageFile
  112.      */
  113.     protected $imageFile;
  114.     /**
  115.      * @return mixed
  116.      */
  117.     public function getVisible()
  118.     {
  119.         return $this->visible;
  120.     }
  121.     /**
  122.      * @param mixed $visible
  123.      */
  124.     public function setVisible($visible)
  125.     {
  126.         $this->visible $visible;
  127.     }
  128.     /**
  129.      * @return mixed
  130.      */
  131.     public function getSpecial()
  132.     {
  133.         return $this->special;
  134.     }
  135.     /**
  136.      * @param mixed $special
  137.      */
  138.     public function setSpecial($special)
  139.     {
  140.         $this->special $special;
  141.     }
  142.     /**
  143.      * @Doctrine\ORM\Mapping\Column(type="boolean", nullable=true)
  144.      */
  145.     protected $visible true;
  146.     /**
  147.      * @Doctrine\ORM\Mapping\Column(type="boolean", nullable=true)
  148.      */
  149.     protected $special false;
  150.     /**
  151.      * @ORM\Column(type="string", length=255, name="image_name", nullable=true)
  152.      * @var string $imageName
  153.      */
  154.     protected $imageName;
  155.     public function __construct()
  156.     {
  157.         $this->products = new ArrayCollection();
  158.     }
  159.     
  160.     public function setImageFile(File $image null)
  161.     {
  162.         $this->imageFile $image;
  163.         if ($image) {
  164.             try {
  165.                 $fileName md5(uniqid()).'.'.$image->guessExtension();
  166.                 // Move the file to the directory where brochures are stored
  167.                 $brochuresDir getcwd().'/images/blog/';
  168.                 $image->move($brochuresDir$fileName);
  169.                 // Update the 'brochure' property to store the PDF file name
  170.                 // instead of its contents
  171.                 $this->setImageName($fileName);
  172.                 $this->updatedAt = new \DateTime('now');
  173.             } catch (\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException $e) {
  174.             }
  175.         }
  176.         return $this;
  177.     }
  178.     /**
  179.      * @return File
  180.      */
  181.     public function getImageFile()
  182.     {
  183.         return $this->imageFile;
  184.     }
  185.     /**
  186.      * @param string $imageName
  187.      */
  188.     public function setImageName($imageName)
  189.     {
  190.         $this->imageName $imageName;
  191.     }
  192.     /**
  193.      * @return string
  194.      */
  195.     public function getImageName()
  196.     {
  197.         return $this->imageName;
  198.     }
  199.     /**
  200.      * Get id
  201.      *
  202.      * @return integer
  203.      */
  204.     public function getId()
  205.     {
  206.         return $this->id;
  207.     }
  208.     /**
  209.      * Set title
  210.      *
  211.      * @param string $title
  212.      *
  213.      * @return Blog
  214.      */
  215.     public function setTitle($title)
  216.     {
  217.         $this->title $title;
  218.         return $this;
  219.     }
  220.     /**
  221.      * Get title
  222.      *
  223.      * @return string
  224.      */
  225.     public function getTitle()
  226.     {
  227.         return $this->title;
  228.     }
  229.     /**
  230.      * Set content
  231.      *
  232.      * @param string $content
  233.      *
  234.      * @return Blog
  235.      */
  236.     public function setContent($content)
  237.     {
  238.         $this->content $content;
  239.         return $this;
  240.     }
  241.     /**
  242.      * Get content
  243.      *
  244.      * @return string
  245.      */
  246.     public function getContent()
  247.     {
  248.         return $this->content;
  249.     }
  250.     /**
  251.      * Set slug
  252.      *
  253.      * @param string $slug
  254.      *
  255.      * @return Blog
  256.      */
  257.     public function setSlug($slug)
  258.     {
  259.         $this->slug $slug;
  260.         return $this;
  261.     }
  262.     /**
  263.      * Get slug
  264.      *
  265.      * @return string
  266.      */
  267.     public function getSlug()
  268.     {
  269.         return $this->slug;
  270.     }
  271.     public function getLanguage(): ?Language
  272.     {
  273.         return $this->language;
  274.     }
  275.     public function setLanguage(?Language $language): self
  276.     {
  277.         $this->language $language;
  278.         return $this;
  279.     }
  280.     /**
  281.      * @return Collection|Product[]
  282.      */
  283.     public function getProducts(): Collection
  284.     {
  285.         return $this->products;
  286.     }
  287.     public function addProduct(Product $product): self
  288.     {
  289.         if (!$this->products->contains($product)) {
  290.             $this->products[] = $product;
  291.         }
  292.         return $this;
  293.     }
  294.     public function removeProduct(Product $product): self
  295.     {
  296.         if ($this->products->contains($product)) {
  297.             $this->products->removeElement($product);
  298.         }
  299.         return $this;
  300.     }
  301.     /**
  302.      * @return string
  303.      */
  304.     public function getMetaTitle()
  305.     {
  306.         return $this->metaTitle;
  307.     }
  308.     /**
  309.      * @param string $metaTitle
  310.      */
  311.     public function setMetaTitle($metaTitle)
  312.     {
  313.         $this->metaTitle $metaTitle;
  314.     }
  315.     /**
  316.      * @return string
  317.      */
  318.     public function getMetaDescription()
  319.     {
  320.         return $this->metaDescription;
  321.     }
  322.     /**
  323.      * @param string $metaDescription
  324.      */
  325.     public function setMetaDescription($metaDescription)
  326.     {
  327.         $this->metaDescription $metaDescription;
  328.     }
  329.     /**
  330.      * @return string
  331.      */
  332.     public function getMetaKeywords()
  333.     {
  334.         return $this->metaKeywords;
  335.     }
  336.     /**
  337.      * @param string $metaKeywords
  338.      */
  339.     public function setMetaKeywords($metaKeywords)
  340.     {
  341.         $this->metaKeywords $metaKeywords;
  342.     }
  343.     /**
  344.      * @return string
  345.      */
  346.     public function getAlt()
  347.     {
  348.         return $this->alt;
  349.     }
  350.     /**
  351.      * @param string $alt
  352.      */
  353.     public function setAlt($alt)
  354.     {
  355.         $this->alt $alt;
  356.     }
  357.     /**
  358.      * @return string
  359.      */
  360.     public function getImageCustomName()
  361.     {
  362.         return $this->imageCustomName;
  363.     }
  364.     /**
  365.      * @param string $imageCustomName
  366.      */
  367.     public function setImageCustomName($imageCustomName)
  368.     {
  369.         $this->imageCustomName $imageCustomName;
  370.     }
  371. }