Advertisement
sivancheva

EntityArticle

Dec 2nd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 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="dateAdded", type="datetime")
  42. */
  43. private $dateAdded;
  44. /**
  45. * @var string
  46. */
  47. private $summary;
  48. /**
  49. * @param string
  50. */
  51. private function setSummary(){
  52. $this -> summary = substr($this -> getContent(),0,strlen($this->getContent()) /2)."...";
  53. }
  54.  
  55. /**
  56. * @return string
  57. */
  58. private function getSummary()
  59. {
  60. if($this -> $summary === null)
  61. {
  62. $this -> setSummary();
  63. }
  64. return $this -> summary;
  65. }
  66.  
  67. /**
  68. * @var int
  69. *
  70. * @ORM\Column(name="authorId", type = "integer")
  71. */
  72.  
  73. private $authorId;
  74.  
  75. /**
  76. * Get id
  77. *
  78. * @return int
  79. */
  80. public function getId()
  81. {
  82. return $this->id;
  83. }
  84. /**
  85. * @param integer $authorId
  86. *
  87. * @return Article
  88. */
  89. public function setAuthorId($authorId)
  90. {
  91. $this->authorId = $authorId;
  92. return $this;
  93. }
  94. /**
  95. * @return int
  96. */
  97. public function getAuthorId()
  98. {
  99. return $this->authorId;
  100. }
  101.  
  102. /**
  103. * Set title
  104. *
  105. * @param string $title
  106. *
  107. * @return Article
  108. */
  109. public function setTitle($title)
  110. {
  111. $this->title = $title;
  112.  
  113. return $this;
  114. }
  115.  
  116. /**
  117. * Get title
  118. *
  119. * @return string
  120. */
  121. public function getTitle()
  122. {
  123. return $this->title;
  124. }
  125.  
  126. /**
  127. * Set content
  128. *
  129. * @param string $content
  130. *
  131. * @return Article
  132. */
  133. public function setContent($content)
  134. {
  135. $this->content = $content;
  136.  
  137. return $this;
  138. }
  139.  
  140. /**
  141. * Get content
  142. *
  143. * @return string
  144. */
  145. public function getContent()
  146. {
  147. return $this->content;
  148. }
  149.  
  150. /**
  151. * Set dateAdded
  152. *
  153. * @param \DateTime $dateAdded
  154. *
  155. * @return Article
  156. */
  157. public function setDateAdded($dateAdded)
  158. {
  159. $this->dateAdded = $dateAdded;
  160.  
  161. return $this;
  162. }
  163. public function __construct()
  164. {
  165. $this->dateAdded = new \DateTime('now');
  166. }
  167. /**
  168. * Get dateAdded
  169. *
  170. * @return \DateTime
  171. */
  172. public function getDateAdded()
  173. {
  174. return $this->dateAdded;
  175. }
  176.  
  177. /**
  178. * @var User
  179. *
  180. * @ORM\ManyToOne(targetEntity="SoftUniBlogBundle\Entity\User", inversedBy="articles")
  181. * @ORM\JoinColumn(name="authorId", referencedColumnName="id")
  182. *
  183. */
  184. private $author;
  185.  
  186.  
  187. /**
  188. *
  189. * @param \SoftUniBlogBundle\Entity\User $author
  190. *
  191. * @return Article
  192. */
  193. public function setAuthor(User $author = null)
  194. {
  195. $this -> author = $author;
  196. return $this;
  197. }
  198.  
  199. /**
  200. * @return \SoftUniBlogBundle\Entity\User
  201. */
  202. public function getAuthor()
  203. {
  204. return $this-> author;
  205.  
  206. }
  207.  
  208.  
  209.  
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement