<?PHP
namespace MyBlogBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\HttpFoundation\
File\UploadedFile
;use Doctrine\ORM\Mapping as ORM;
use MyBlogBundle\Admin\BlogAdmin;
/**
* Blog
* @ORM\Table()
* @ORM\Entity(repositoryClass="MyBlogBundle\Entity\BlogRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Blog {
/**
* @var integer
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
* @ORM\Column(name="author", type="string", length=255)
*/
private $author;
/**
* @var string
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string
* @ORM\Column(name="text", type="text")
*/
private $text;
/**
* @var \DateTime
* @ORM\Column(name="createDate", type="datetime")
*/
private $createDate;
/**
* @var \DateTime
* @ORM\Column(name="updateDate", type="datetime")
*/
private $updateDate;
/**
* @var string
* @ORM\Column(name="image", type="string", length=255)
*/
private $image;
/**
* @var string
* @ORM\Column(name="tag", type="string", length=255)
*/
private $tag;
/**
* @ORM\OneToMany(targetEntity="Comment",mappedBy="blog")
*/
private $comment;
/**
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* @param string $author
* @return Blog
*/
public function setAuthor($author) {
$this->author = $author;
return $this;
}
/**
* @return string
*/
public function getAuthor() {
return $this->author;
}
/**
* @param string $title
* @return Blog
*/
public function setTitle($title) {
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* @param string $text
* @return Blog
*/
public function setText($text) {
$this->text = $text;
return $this;
}
/**
* Get text
* @return string
*/
public function getText($count = NULL) { if ($count != NULL) {
$this->text = implode(' ', $arr) . '...'; }
return $this->text;
}
/**
* Set createDate
* @ORM\PrePersist
* @param \DateTime $createDate
* @return Blog
*/
public function setCreateDate() {
$this->createDate = new \DateTime();
return $this;
}
/**
* @return \DateTime
*/
public function getCreateDate() {
return $this->createDate;
}
/**
* @ORM\PreUpdate
* @param \DateTime $updateDate
* @return Blog
*/
public function setUpdateDate() {
$this->updateDate = new \DateTime();
return $this;
}
/**
* @return \DateTime
*/
public function getUpdateDate() {
return $this->updateDate;
}
/**
* @param string $image
* @return Blog
*/
public function setImage($image) {
$this->image = $image;
return $this;
}
/**
* @return string
*/
public function getImage() {
return $this->image;
}
/**
* @param string $tag
* @return Blog
*/
public function setTag($tag) {
$this->tag = $tag;
return $this;
}
/**
* @return string
*/
public function getTag() {
return $this->tag;
}
public function __construct() {
$this->comment = new ArrayCollection();
$this->updateDate = new \DateTime();
}
/**
* @param \MyBlogBundle\Entity\Comment $comment
* @return Blog
*/
public function addComment(\MyBlogBundle\Entity\Comment $comment) {
$this->comment[] = $comment;
return $this;
}
/**
* @param \MyBlogBundle\Entity\Comment $comment
*/
public function removeComment(\MyBlogBundle\Entity\Comment $comment) {
$this->comment->removeElement($comment);
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getComment() {
return $this->comment;
}
const SERVER_PATH_TO_IMAGE_FOLDER = '/web/images';
private $file;
/**
* @param UploadedFile $file
*/
public function setFile(UploadedFile $file = null) {
$this->file = $file;
}
/**
* @return UploadedFile
*/
public function getFile() {
return $this->file;
}
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function upload() {
if (null === $this->getFile()) {
return;
}
$this->getFile()->move(
Blog::SERVER_PATH_TO_IMAGE_FOLDER, $this->getFile()->getClientOriginalName()
);
$this->filename = $this->getFile()->getClientOriginalName();
$this->setFile(null);
}
public function lifecycleFileUpload() {
$this->upload();
}
public function refreshUpdated() {
$this->setUpdated(new \DateTime("now"));
}
}