<?php
// src//App/Entity/Articles.php
namespace App\Entity;
use App\Entity\Tags as Tags;
use App\Entity\User as User;
use App\Repository\UploadedFile;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Eko\FeedBundle\Item\Writer\RoutedItemInterface;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* Articles
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="App\Repository\ArticlesRepository")
* @Vich\Uploadable
*/
class Articles implements RoutedItemInterface
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity="Tags", inversedBy="articles", cascade={"persist"})
* @ORM\JoinTable(name="articles_tags")
*/
private $tags;
public function __construct()
{
$this->tags = new ArrayCollection();
}
/**
* @var string
*
* @ORM\Column(name="author", type="string", length=255, nullable=true)
*/
private $author;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255, nullable=true)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="content", type="text", nullable=true)
*/
private $content;
/**
* @var string
* @Gedmo\Slug(fields={"title"}, updatable=true)
* @ORM\Column(name="slug", type="string", length=255, unique=true)
*/
private $slug;
/**
* @var boolean
*
* @ORM\Column(name="publish", type="boolean", nullable=true)
*/
private $publish = false;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $created;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updated;
/**
* @var DateTime $datePublished
*
* @ORM\Column(name="datePublished", type="datetime", nullable=true)
*/
private $datePublished;
/**
* @var User $createdBy
*
* @Gedmo\Blameable(on="create")
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="created_by", referencedColumnName="id")
*/
private $createdBy;
/**
* @var User $updatedBy
*
* @Gedmo\Blameable(on="update")
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="updated_by", referencedColumnName="id")
*/
private $updatedBy;
/**
*
* @Vich\UploadableField(mapping="product_image", fileNameProperty="imageName")
*
* @var UploadedFile $imageFile
*/
protected $imageFile;
/**
* @ORM\Column(type="string", length=255, name="image_name", nullable=true)
*
* @var string $imageName
*/
protected $imageName;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @var DateTime $updatedAt
*/
protected $updatedAt;
/**
* @var integer
*
* @ORM\Column(name="count", type="integer", nullable=true)
*/
private $count;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set author
*
* @param string $author
* @return Articles
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* @return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set title
*
* @param string $title
* @return Articles
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set content
*
* @param string $content
* @return Articles
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* @return string
*/
public function getContent()
{
return $this->content;
}
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set publish
*
* @param boolean $publish
* @return Articles
* @throws \Exception
*/
public function setPublish($publish)
{
$pastPublish = $this->getPublish();
$this->publish = $publish;
if (($publish == true) && ($pastPublish <> true)){
$datePublished = new DateTime();
$this->setDatePublished($datePublished);
}
return $this;
}
/**
* Get publish
*
* @return boolean
*/
public function getPublish()
{
return $this->publish;
}
/**
* Set datePublished
*
* @param DateTime $datePublished
* @return Articles
*/
public function setDatePublished($datePublished)
{
$this->datePublished = $datePublished;
return $this;
}
/**
* Get datePublished
*
* @return datetime
*/
public function getDatePublished()
{
return $this->datePublished;
}
/**
* Set created
*
* @param DateTime $created
* @return Articles
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* @return DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* @param DateTime $updated
* @return Articles
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* @return DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Get createdBy
*
* @return \App\Entity\User
*/
public function getCreatedBy()
{
return $this->createdBy;
}
/**
* Get updatedBy
*
* @return \App\Entity\User
*/
public function getUpdatedBy()
{
return $this->updatedBy;
}
/**
* Set createdBy
*
* @param \App\Entity\User $createdBy
*
* @return Articles
*/
public function setCreatedBy(\App\Entity\User $createdBy = null)
{
$this->createdBy = $createdBy;
return $this;
}
/**
* Set updatedBy
*
* @param \App\Entity\User $updatedBy
*
* @return Articles
*/
public function setUpdatedBy(\App\Entity\User $updatedBy = null)
{
$this->updatedBy = $updatedBy;
return $this;
}
public function addTag(Tags $tags)
{
$this->tags->add($tags);
}
public function removeTag(Tags $tags)
{
$this->tags->removeElement($tags);
}
/**
* Get tags
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getTags()
{
return $this->tags;
}
/**
* Set count
*
* @param integer $count
* @return Articles
*/
public function setCount($count)
{
$this->count = $count;
return $this;
}
/**
* Get count
*
* @return integer
*/
public function getCount()
{
return $this->count;
}
public function getFeedItemTitle()
{
return $this->title;
}
public function getFeedItemDescription()
{
$content = $this->content;
$content = substr(strip_tags($content), 0, 500);
return $content;
}
public function getFeedItemPubDate()
{
return $this->datePublished;
}
public function getFeedItemRouteName()
{
return 'Blog_Article';
}
public function getFeedItemRouteParameters()
{
$array = array('slug' => $this->slug, 'date' => $this->datePublished->format('Ymd'));
return $array;
}
public function getFeedItemUrlAnchor()
{
return '';
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param UploadedFile|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*
* @throws \Exception
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTime('now');
}
}
/**
* @return UploadedFile
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param string $imageName
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
}
/**
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
}