Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace SoftUniBlogBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- /**
- * Article
- *
- * @ORM\Table(name="articles")
- * @ORM\Entity(repositoryClass="SoftUniBlogBundle\Repository\ArticleRepository")
- */
- class Article
- {
- /**
- * @var int
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(name="title", type="string", length=255)
- */
- private $title;
- /**
- * @var string
- *
- * @ORM\Column(name="content", type="text")
- */
- private $content;
- /**
- * @var \DateTime
- *
- * @ORM\Column(name="createdOn", type="datetime")
- */
- private $createdOn;
- /**
- * @var string
- */
- private $summary;
- /**
- * @param string
- */
- private function setSummary()
- {
- $this->summary = substr($this->getContent(), 0, 255) . "...";
- }
- /**
- * @return string
- */
- public function getSummary()
- {
- if ($this->summary === null)
- {
- $this->setSummary();
- }
- return $this->summary;
- }
- /**
- * @var int
- *
- * @ORM\Column(name="authorId", type="integer")
- */
- private $authorId;
- /**
- * @param integer $authorId
- * @return Article
- */
- public function setAuthorId($authorId)
- {
- $this->authorId = $authorId;
- return $this;
- }
- /**
- * @return int
- */
- public function getAuthorId()
- {
- return $this->authorId;
- }
- /**
- * @var User
- *
- * @ORM\ManyToOne(targetEntity="SoftUniBlogBundle\Entity\User", inversedBy="articles")
- * @ORM\JoinColumn(name="authorId", referencedColumnName="id")
- */
- private $author;
- /**
- * @param \SoftUniBlogBundle\Entity\User $author
- *
- * @return \SoftUniBlogBundle\Entity\Article
- */
- public function setAuthor(User $author = null)
- {
- $this->author = $author;
- return $this;
- }
- /**
- * @return \SoftUniBlogBundle\Entity\User
- */
- public function getAuthor()
- {
- return $this->author;
- }
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set title
- *
- * @param string $title
- *
- * @return \SoftUniBlogBundle\Entity\Article
- */
- 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 \SoftUniBlogBundle\Entity\Article
- */
- public function setContent($content)
- {
- $this->content = $content;
- return $this;
- }
- /**
- * Get content
- *
- * @return string
- */
- public function getContent()
- {
- return $this->content;
- }
- /**
- * Set createdOn
- *
- * @param \DateTime $createdOn
- *
- * @return \SoftUniBlogBundle\Entity\Article
- */
- public function setCreatedOn($createdOn)
- {
- $this->createdOn = $createdOn;
- return $this;
- }
- /**
- * Get createdOn
- *
- * @return \DateTime
- */
- public function getCreatedOn()
- {
- return $this->createdOn;
- }
- public function __construct()
- {
- $this->createdOn = new \DateTime('now');
- }
- /**
- * @param User|null $authorCandidate
- * @return bool
- */
- public function isAuthor(User $authorCandidate = null)
- {
- if ($authorCandidate == null) {
- return false;
- }
- return ($this->getAuthorId() == $authorCandidate->getId());
- }
- }
Add Comment
Please, Sign In to add comment