luoni

Article

Jul 29th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 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", length=255)
  35. */
  36. private $content;
  37.  
  38. /**
  39. * @var \DateTime
  40. *
  41. * @ORM\Column(name="dateAdded", type="datetime")
  42. */
  43. private $dateAdded;
  44.  
  45. /**
  46. * @var string
  47. */
  48.  
  49. private $summary;
  50.  
  51. /**
  52. * @param string@
  53. */
  54.  
  55. public function setSummary()
  56. {
  57. $this->summary = substr($this->getContent(), 0, strlen($this->getContent()) / 2) . "...";
  58. }
  59.  
  60. /**
  61. * return string
  62. */
  63.  
  64. public function getSummary()
  65. {
  66. if ($this->summary === null) {
  67. $this->setSummary();
  68. }
  69. return $this->summary;
  70. }
  71.  
  72. /**
  73. * @var int
  74. * @ORM\Column(name="authorId", type="integer")
  75. */
  76. private $authorId;
  77.  
  78. /**
  79. * @return int
  80. */
  81. public function getAuthorId()
  82. {
  83. return $this->authorId;
  84. }
  85.  
  86. /**
  87. * @param int $authorId
  88. *
  89. * @return Article
  90. */
  91. public function setAuthorId($authorId)
  92. {
  93. $this->authorId = $authorId;
  94. return $this;
  95. }
  96.  
  97. /**
  98. * @var User
  99. *
  100. * @ORM\ManyToOne(targetEntity="SoftUniBlogBundle\Entity\User",inversedBy="articles")
  101. * @ORM\JoinColumn(name="authorId",referencedColumnName="id")
  102. */
  103.  
  104. private $author;
  105.  
  106. /**
  107. * @param \SoftUniBlogBundle\Entity\User $author
  108. *
  109. * @return Article
  110. */
  111. public function setAuthor(User $author = null)
  112. {
  113. $this->author = $author;
  114. return $this;
  115. }
  116.  
  117. /**
  118. * @return \SoftUniBlogBundle\Entity\User
  119. */
  120. public function getAuthor()
  121. {
  122. return $this->author;
  123. }
  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 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 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 dateAdded
  187. *
  188. * @param \DateTime $dateAdded
  189. *
  190. * @return Article
  191. */
  192. public function setDateAdded($dateAdded)
  193. {
  194. $this->dateAdded = $dateAdded;
  195.  
  196. return $this;
  197. }
  198.  
  199. /**
  200. * Get dateAdded
  201. *
  202. * @return \DateTime
  203. */
  204. public function getDateAdded()
  205. {
  206. return $this->dateAdded;
  207. }
  208.  
  209. public function __construct()
  210. {
  211. $this->dateAdded = new \DateTime('now');
  212. }
  213.  
  214. }
Advertisement
Add Comment
Please, Sign In to add comment