Guest User

Article

a guest
Nov 9th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.99 KB | None | 0 0
  1. <?php
  2.  
  3. namespace SoftUniBlogBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6.  
  7. /**
  8.  * Article
  9.  *
  10.  * @ORM\Table(name="articles")
  11.  * @ORM\Entity(repositoryClass="SoftUniBlogBundle\Repository\ArticleRepository")
  12.  */
  13. class Article
  14. {
  15.     /**
  16.      * @var int
  17.      *
  18.      * @ORM\Column(name="id", type="integer")
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue(strategy="AUTO")
  21.      */
  22.     private $id;
  23.  
  24.     /**
  25.      * @var string
  26.      *
  27.      * @ORM\Column(name="title", type="string", length=255)
  28.      */
  29.     private $title;
  30.  
  31.     /**
  32.      * @var string
  33.      *
  34.      * @ORM\Column(name="content", type="text")
  35.      */
  36.     private $content;
  37.  
  38.     /**
  39.      * @var \DateTime
  40.      *
  41.      * @ORM\Column(name="createdOn", type="datetime")
  42.      */
  43.     private $createdOn;
  44.  
  45.     /**
  46.      * @var string
  47.      */
  48.     private $summary;
  49.  
  50.     /**
  51.      * @param string
  52.      */
  53.     private function setSummary()
  54.     {
  55.         $this->summary = substr($this->getContent(), 0, 255) . "...";
  56.     }
  57.  
  58.     /**
  59.      * @return string
  60.      */
  61.     public function getSummary()
  62.     {
  63.         if ($this->summary === null)
  64.         {
  65.             $this->setSummary();
  66.         }
  67.         return $this->summary;
  68.     }
  69.  
  70.     /**
  71.      * @var int
  72.      *
  73.      * @ORM\Column(name="authorId", type="integer")
  74.      */
  75.     private $authorId;
  76.  
  77.  
  78.     /**
  79.      * @param integer $authorId
  80.      * @return Article
  81.      */
  82.     public function setAuthorId($authorId)
  83.     {
  84.         $this->authorId = $authorId;
  85.  
  86.         return $this;
  87.     }
  88.  
  89.  
  90.     /**
  91.      * @return int
  92.      */
  93.     public function getAuthorId()
  94.     {
  95.         return $this->authorId;
  96.     }
  97.  
  98.     /**
  99.      * @var User
  100.      *
  101.      * @ORM\ManyToOne(targetEntity="SoftUniBlogBundle\Entity\User", inversedBy="articles")
  102.      * @ORM\JoinColumn(name="authorId", referencedColumnName="id")
  103.      */
  104.     private $author;
  105.  
  106.     /**
  107.      * @param \SoftUniBlogBundle\Entity\User $author
  108.      *
  109.      * @return \SoftUniBlogBundle\Entity\Article
  110.      */
  111.     public function setAuthor(User $author = null)
  112.     {
  113.         $this->author = $author;
  114.  
  115.         return $this;
  116.     }
  117.  
  118.     /**
  119.      * @return \SoftUniBlogBundle\Entity\User
  120.      */
  121.     public function getAuthor()
  122.     {
  123.         return $this->author;
  124.     }
  125.  
  126.  
  127.     /**
  128.      * Get id
  129.      *
  130.      * @return int
  131.      */
  132.     public function getId()
  133.     {
  134.         return $this->id;
  135.     }
  136.  
  137.     /**
  138.      * Set title
  139.      *
  140.      * @param string $title
  141.      *
  142.      * @return \SoftUniBlogBundle\Entity\Article
  143.      */
  144.     public function setTitle($title)
  145.     {
  146.         $this->title = $title;
  147.  
  148.         return $this;
  149.     }
  150.  
  151.     /**
  152.      * Get title
  153.      *
  154.      * @return string
  155.      */
  156.     public function getTitle()
  157.     {
  158.         return $this->title;
  159.     }
  160.  
  161.     /**
  162.      * Set content
  163.      *
  164.      * @param string $content
  165.      *
  166.      * @return \SoftUniBlogBundle\Entity\Article
  167.      */
  168.     public function setContent($content)
  169.     {
  170.         $this->content = $content;
  171.  
  172.         return $this;
  173.     }
  174.  
  175.     /**
  176.      * Get content
  177.      *
  178.      * @return string
  179.      */
  180.     public function getContent()
  181.     {
  182.         return $this->content;
  183.     }
  184.  
  185.     /**
  186.      * Set createdOn
  187.      *
  188.      * @param \DateTime $createdOn
  189.      *
  190.      * @return \SoftUniBlogBundle\Entity\Article
  191.      */
  192.     public function setCreatedOn($createdOn)
  193.     {
  194.         $this->createdOn = $createdOn;
  195.  
  196.         return $this;
  197.     }
  198.  
  199.     /**
  200.      * Get createdOn
  201.      *
  202.      * @return \DateTime
  203.      */
  204.     public function getCreatedOn()
  205.     {
  206.         return $this->createdOn;
  207.     }
  208.  
  209.     public function __construct()
  210.     {
  211.         $this->createdOn = new \DateTime('now');
  212.     }
  213.  
  214.     /**
  215.      * @param User|null $authorCandidate
  216.      * @return bool
  217.      */
  218.  
  219.     public function isAuthor(User $authorCandidate = null)
  220.     {
  221.         if ($authorCandidate == null) {
  222.             return false;
  223.         }
  224.  
  225.         return ($this->getAuthorId() == $authorCandidate->getId());
  226.     }
  227. }
Add Comment
Please, Sign In to add comment