src/Entity/Articles.php line 23

Open in your IDE?
  1. <?php
  2. // src//App/Entity/Articles.php
  3. namespace App\Entity;
  4. use App\Entity\Tags as Tags;
  5. use App\Entity\User as User;
  6. use App\Repository\UploadedFile;
  7. use DateTime;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Eko\FeedBundle\Item\Writer\RoutedItemInterface;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. /**
  15.  * Articles
  16.  *
  17.  * @ORM\Table()
  18.  * @ORM\Entity(repositoryClass="App\Repository\ArticlesRepository")
  19.  * @Vich\Uploadable
  20.  */
  21. class Articles implements RoutedItemInterface
  22. {
  23.     /**
  24.      * @var integer
  25.      *
  26.      * @ORM\Column(name="id", type="integer")
  27.      * @ORM\Id
  28.      * @ORM\GeneratedValue(strategy="AUTO")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\ManyToMany(targetEntity="Tags", inversedBy="articles", cascade={"persist"})
  33.      * @ORM\JoinTable(name="articles_tags")
  34.      */
  35.     private $tags;
  36.     public function __construct()
  37.     {
  38.         $this->tags = new ArrayCollection();
  39.     }
  40.     /**
  41.      * @var string
  42.      *
  43.      * @ORM\Column(name="author", type="string", length=255, nullable=true)
  44.      */
  45.     private $author;
  46.     /**
  47.      * @var string
  48.      *
  49.      * @ORM\Column(name="title", type="string", length=255, nullable=true)
  50.      */
  51.     private $title;
  52.     /**
  53.      * @var string
  54.      *
  55.      * @ORM\Column(name="content", type="text", nullable=true)
  56.      */
  57.     private $content;
  58.     /**
  59.      * @var string
  60.      * @Gedmo\Slug(fields={"title"}, updatable=true)
  61.      * @ORM\Column(name="slug", type="string", length=255, unique=true)
  62.      */
  63.     private $slug;
  64.     /**
  65.      * @var boolean
  66.      *
  67.      * @ORM\Column(name="publish", type="boolean", nullable=true)
  68.      */
  69.     private $publish false;
  70.     /**
  71.      * @Gedmo\Timestampable(on="create")
  72.      * @ORM\Column(type="datetime")
  73.      */
  74.     private $created;
  75.     /**
  76.      * @Gedmo\Timestampable(on="update")
  77.      * @ORM\Column(type="datetime")
  78.      */
  79.     private $updated;
  80.     /**
  81.      * @var DateTime $datePublished
  82.      *
  83.      * @ORM\Column(name="datePublished", type="datetime", nullable=true)
  84.      */
  85.     private $datePublished;
  86.     /**
  87.      * @var User $createdBy
  88.      *
  89.      * @Gedmo\Blameable(on="create")
  90.      * @ORM\ManyToOne(targetEntity="User")
  91.      * @ORM\JoinColumn(name="created_by", referencedColumnName="id")
  92.      */
  93.     private $createdBy;
  94.     /**
  95.      * @var User $updatedBy
  96.      *
  97.      * @Gedmo\Blameable(on="update")
  98.      * @ORM\ManyToOne(targetEntity="User")
  99.      * @ORM\JoinColumn(name="updated_by", referencedColumnName="id")
  100.      */
  101.     private $updatedBy;
  102.     /**
  103.      *
  104.      * @Vich\UploadableField(mapping="product_image", fileNameProperty="imageName")
  105.      *
  106.      * @var UploadedFile $imageFile
  107.      */
  108.     protected $imageFile;
  109.     /**
  110.      * @ORM\Column(type="string", length=255, name="image_name", nullable=true)
  111.      *
  112.      * @var string $imageName
  113.      */
  114.     protected $imageName;
  115.     /**
  116.      * @ORM\Column(type="datetime", nullable=true)
  117.      *
  118.      * @var DateTime $updatedAt
  119.      */
  120.     protected $updatedAt;
  121.     /**
  122.      * @var integer
  123.      *
  124.      * @ORM\Column(name="count", type="integer", nullable=true)
  125.      */
  126.     private $count;
  127.     /**
  128.      * Get id
  129.      *
  130.      * @return integer
  131.      */
  132.     public function getId()
  133.     {
  134.         return $this->id;
  135.     }
  136.     /**
  137.      * Set author
  138.      *
  139.      * @param string $author
  140.      * @return Articles
  141.      */
  142.     public function setAuthor($author)
  143.     {
  144.         $this->author $author;
  145.         return $this;
  146.     }
  147.     /**
  148.      * Get author
  149.      *
  150.      * @return string
  151.      */
  152.     public function getAuthor()
  153.     {
  154.         return $this->author;
  155.     }
  156.     /**
  157.      * Set title
  158.      *
  159.      * @param string $title
  160.      * @return Articles
  161.      */
  162.     public function setTitle($title)
  163.     {
  164.         $this->title $title;
  165.         return $this;
  166.     }
  167.     /**
  168.      * Get title
  169.      *
  170.      * @return string
  171.      */
  172.     public function getTitle()
  173.     {
  174.         return $this->title;
  175.     }
  176.     /**
  177.      * Set content
  178.      *
  179.      * @param string $content
  180.      * @return Articles
  181.      */
  182.     public function setContent($content)
  183.     {
  184.         $this->content $content;
  185.         return $this;
  186.     }
  187.     /**
  188.      * Get content
  189.      *
  190.      * @return string
  191.      */
  192.     public function getContent()
  193.     {
  194.         return $this->content;
  195.     }
  196.     public function setSlug($slug)
  197.     {
  198.         $this->slug $slug;
  199.     }
  200.     /**
  201.      * Get slug
  202.      *
  203.      * @return string
  204.      */
  205.     public function getSlug()
  206.     {
  207.         return $this->slug;
  208.     }
  209.     /**
  210.      * Set publish
  211.      *
  212.      * @param boolean $publish
  213.      * @return Articles
  214.      * @throws \Exception
  215.      */
  216.     public function setPublish($publish)
  217.     {
  218.         $pastPublish $this->getPublish();
  219.         $this->publish $publish;
  220.         if (($publish == true) && ($pastPublish <> true)){
  221.             $datePublished = new DateTime();
  222.             $this->setDatePublished($datePublished);
  223.         }
  224.         return $this;
  225.     }
  226.     /**
  227.      * Get publish
  228.      *
  229.      * @return boolean
  230.      */
  231.     public function getPublish()
  232.     {
  233.         return $this->publish;
  234.     }
  235.     /**
  236.      * Set datePublished
  237.      *
  238.      * @param DateTime $datePublished
  239.      * @return Articles
  240.      */
  241.     public function setDatePublished($datePublished)
  242.     {
  243.         $this->datePublished $datePublished;
  244.         return $this;
  245.     }
  246.     /**
  247.      * Get datePublished
  248.      *
  249.      * @return datetime
  250.      */
  251.     public function getDatePublished()
  252.     {
  253.         return $this->datePublished;
  254.     }
  255.     /**
  256.      * Set created
  257.      *
  258.      * @param DateTime $created
  259.      * @return Articles
  260.      */
  261.     public function setCreated($created)
  262.     {
  263.         $this->created $created;
  264.         return $this;
  265.     }
  266.     /**
  267.      * Get created
  268.      *
  269.      * @return DateTime
  270.      */
  271.     public function getCreated()
  272.     {
  273.         return $this->created;
  274.     }
  275.     /**
  276.      * Set updated
  277.      *
  278.      * @param DateTime $updated
  279.      * @return Articles
  280.      */
  281.     public function setUpdated($updated)
  282.     {
  283.         $this->updated $updated;
  284.         return $this;
  285.     }
  286.     /**
  287.      * Get updated
  288.      *
  289.      * @return DateTime
  290.      */
  291.     public function getUpdated()
  292.     {
  293.         return $this->updated;
  294.     }
  295.         /**
  296.      * Get createdBy
  297.      *
  298.      * @return \App\Entity\User
  299.      */
  300.     public function getCreatedBy()
  301.     {
  302.         return $this->createdBy;
  303.     }
  304.     /**
  305.      * Get updatedBy
  306.      *
  307.      * @return \App\Entity\User
  308.      */
  309.     public function getUpdatedBy()
  310.     {
  311.         return $this->updatedBy;
  312.     }
  313.     /**
  314.      * Set createdBy
  315.      *
  316.      * @param \App\Entity\User $createdBy
  317.      *
  318.      * @return Articles
  319.      */
  320.     public function setCreatedBy(\App\Entity\User $createdBy null)
  321.     {
  322.         $this->createdBy $createdBy;
  323.         return $this;
  324.     }
  325.     /**
  326.      * Set updatedBy
  327.      *
  328.      * @param \App\Entity\User $updatedBy
  329.      *
  330.      * @return Articles
  331.      */
  332.     public function setUpdatedBy(\App\Entity\User $updatedBy null)
  333.     {
  334.         $this->updatedBy $updatedBy;
  335.         return $this;
  336.     }
  337.     public function addTag(Tags $tags)
  338.     {
  339.         $this->tags->add($tags);
  340.     }
  341.     public function removeTag(Tags $tags)
  342.     {
  343.         $this->tags->removeElement($tags);
  344.     }
  345.     /**
  346.      * Get tags
  347.      *
  348.      * @return \Doctrine\Common\Collections\Collection
  349.      */
  350.     public function getTags()
  351.     {
  352.         return $this->tags;
  353.     }
  354.     /**
  355.      * Set count
  356.      *
  357.      * @param integer $count
  358.      * @return Articles
  359.      */
  360.     public function setCount($count)
  361.     {
  362.         $this->count $count;
  363.         return $this;
  364.     }
  365.     /**
  366.      * Get count
  367.      *
  368.      * @return integer
  369.      */
  370.     public function getCount()
  371.     {
  372.         return $this->count;
  373.     }
  374.     public function getFeedItemTitle()
  375.     {
  376.         return $this->title;
  377.     }
  378.     public function getFeedItemDescription()
  379.     {
  380.         $content $this->content;
  381.         $content substr(strip_tags($content), 0500);
  382.         return $content;
  383.     }
  384.     public function getFeedItemPubDate()
  385.     {
  386.         return $this->datePublished;
  387.     }
  388.     public function getFeedItemRouteName()
  389.     {
  390.         return 'Blog_Article';
  391.     }
  392.     public function getFeedItemRouteParameters()
  393.     {
  394.         $array = array('slug' => $this->slug'date' => $this->datePublished->format('Ymd'));
  395.         return $array;
  396.     }
  397.     public function getFeedItemUrlAnchor()
  398.     {
  399.         return '';
  400.     }
  401.     /**
  402.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  403.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  404.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  405.      * must be able to accept an instance of 'File' as the bundle will inject one here
  406.      * during Doctrine hydration.
  407.      *
  408.      * @param UploadedFile|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  409.      *
  410.      * @throws \Exception
  411.      */
  412.     public function setImageFile(File $image null)
  413.     {
  414.         $this->imageFile $image;
  415.         if ($image) {
  416.             // It is required that at least one field changes if you are using doctrine
  417.             // otherwise the event listeners won't be called and the file is lost
  418.             $this->updatedAt = new DateTime('now');
  419.         }
  420.     }
  421.     /**
  422.      * @return UploadedFile
  423.      */
  424.     public function getImageFile()
  425.     {
  426.         return $this->imageFile;
  427.     }
  428.     /**
  429.      * @param string $imageName
  430.      */
  431.     public function setImageName($imageName)
  432.     {
  433.         $this->imageName $imageName;
  434.     }
  435.     /**
  436.      * @return string
  437.      */
  438.     public function getImageName()
  439.     {
  440.         return $this->imageName;
  441.     }
  442. }