TYPO3 CMS  TYPO3_7-6
Post.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
25  protected $blog = null;
26 
31  protected $title = '';
32 
36  protected $date = null;
37 
41  protected $author = null;
42 
47  protected $content = '';
48 
52  protected $tags = null;
53 
57  protected $categories = null;
58 
64  protected $comments = null;
65 
70  protected $relatedPosts = null;
71 
75  public function __construct()
76  {
77  $this->tags = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
78  $this->categories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
79  $this->comments = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
80  $this->relatedPosts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
81  $this->date = new \DateTime();
82  }
83 
90  public function setBlog(\ExtbaseTeam\BlogExample\Domain\Model\Blog $blog)
91  {
92  $this->blog = $blog;
93  }
94 
100  public function getBlog()
101  {
102  return $this->blog;
103  }
104 
111  public function setTitle($title)
112  {
113  $this->title = $title;
114  }
115 
121  public function getTitle()
122  {
123  return $this->title;
124  }
125 
132  public function setDate(\DateTime $date)
133  {
134  $this->date = $date;
135  }
136 
143  public function getDate()
144  {
145  return $this->date;
146  }
147 
154  public function setTags(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $tags)
155  {
156  $this->tags = $tags;
157  }
158 
165  public function addTag(Tag $tag)
166  {
167  $this->tags->attach($tag);
168  }
169 
176  public function removeTag(Tag $tag)
177  {
178  $this->tags->detach($tag);
179  }
180 
186  public function removeAllTags()
187  {
188  $this->tags = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
189  }
190 
197  public function getTags()
198  {
199  return clone $this->tags;
200  }
201 
207  public function addCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
208  {
209  $this->categories->attach($category);
210  }
211 
217  public function setCategories($categories)
218  {
219  $this->categories = $categories;
220  }
221 
227  public function getCategories()
228  {
229  return $this->categories;
230  }
231 
237  public function removeCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
238  {
239  $this->categories->detach($category);
240  }
241 
248  public function setAuthor(\ExtbaseTeam\BlogExample\Domain\Model\Person $author)
249  {
250  $this->author = $author;
251  }
252 
258  public function getAuthor()
259  {
260  return $this->author;
261  }
262 
269  public function setContent($content)
270  {
271  $this->content = $content;
272  }
273 
279  public function getContent()
280  {
281  return $this->content;
282  }
283 
290  public function setComments(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $comments)
291  {
292  $this->comments = $comments;
293  }
294 
301  public function addComment(Comment $comment)
302  {
303  $this->comments->attach($comment);
304  }
305 
312  public function removeComment(Comment $commentToDelete)
313  {
314  $this->comments->detach($commentToDelete);
315  }
316 
322  public function removeAllComments()
323  {
324  $comments = clone $this->comments;
325  $this->comments->removeAll($comments);
326  }
327 
333  public function getComments()
334  {
335  return $this->comments;
336  }
337 
344  public function setRelatedPosts(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $relatedPosts)
345  {
346  $this->relatedPosts = $relatedPosts;
347  }
348 
355  public function addRelatedPost(Post $post)
356  {
357  $this->relatedPosts->attach($post);
358  }
359 
365  public function removeAllRelatedPosts()
366  {
368  $this->relatedPosts->removeAll($relatedPosts);
369  }
370 
376  public function getRelatedPosts()
377  {
378  return $this->relatedPosts;
379  }
380 
386  public function __toString()
387  {
388  return $this->title . chr(10) .
389  ' written on ' . $this->date->format('Y-m-d') . chr(10) .
390  ' by ' . $this->author->getFullName() . chr(10) .
391  wordwrap($this->content, 70, chr(10)) . chr(10) .
392  implode(', ', $this->tags->toArray());
393  }
394 }
removeTag(Tag $tag)
Definition: Post.php:176
getBlog()
Definition: Post.php:100
__construct()
Definition: Post.php:75
removeAllComments()
Definition: Post.php:322
$title
Definition: Post.php:31
setAuthor(\ExtbaseTeam\BlogExample\Domain\Model\Person $author)
Definition: Post.php:248
setBlog(\ExtbaseTeam\BlogExample\Domain\Model\Blog $blog)
Definition: Post.php:90
$author
Definition: Post.php:41
getAuthor()
Definition: Post.php:258
getRelatedPosts()
Definition: Post.php:376
$content
Definition: Post.php:47
$blog
Definition: Post.php:25
getTitle()
Definition: Post.php:121
removeAllRelatedPosts()
Definition: Post.php:365
setTags(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $tags)
Definition: Post.php:154
removeComment(Comment $commentToDelete)
Definition: Post.php:312
$comments
Definition: Post.php:64
getCategories()
Definition: Post.php:227
getContent()
Definition: Post.php:279
removeCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
Definition: Post.php:237
addComment(Comment $comment)
Definition: Post.php:301
__toString()
Definition: Post.php:386
getComments()
Definition: Post.php:333
getDate()
Definition: Post.php:143
addCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category)
Definition: Post.php:207
setRelatedPosts(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $relatedPosts)
Definition: Post.php:344
$tags
Definition: Post.php:52
Definition: Post.php:20
setCategories($categories)
Definition: Post.php:217
$date
Definition: Post.php:36
addTag(Tag $tag)
Definition: Post.php:165
setComments(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $comments)
Definition: Post.php:290
getTags()
Definition: Post.php:197
removeAllTags()
Definition: Post.php:186
setDate(\DateTime $date)
Definition: Post.php:132
setContent($content)
Definition: Post.php:269
setTitle($title)
Definition: Post.php:111
$relatedPosts
Definition: Post.php:70
$categories
Definition: Post.php:57
addRelatedPost(Post $post)
Definition: Post.php:355