Advertisement
hrimar

Entity/Article.php of Blog

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