Blog.php 5.21 KB
Newer Older
1
<?php
2

3
4
declare(strict_types=1);

5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
9
10
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
11
 *
12
13
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
16
 * The TYPO3 project - inspiring people to share!
 */
17

18
19
namespace ExtbaseTeam\BlogExample\Domain\Model;

20
use TYPO3\CMS\Extbase\Annotation as Extbase;
21
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
22
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
23
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
24

25
26
27
/**
 * A blog
 */
28
class Blog extends AbstractEntity
29
30
31
32
33
{
    /**
     * The blog's title.
     *
     * @var string
34
     * @Extbase\Validate("StringLength", options={"minimum": 1, "maximum": 80})
35
36
37
     */
    protected $title = '';

38
39
40
41
42
43
44
    /**
     * The blog's subtitle
     *
     * @var string
     */
    protected $subtitle;

45
46
47
48
    /**
     * A short description of the blog
     *
     * @var string
49
     * @Extbase\Validate("StringLength", options={"maximum": 150})
50
51
52
53
54
55
56
57
58
59
60
61
62
     */
    protected $description = '';

    /**
     * A relative path to a logo image
     *
     * @var string
     */
    protected $logo = '';

    /**
     * The posts of this blog
     *
63
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<Post>
64
     * @Extbase\ORM\Lazy
65
     * @Extbase\ORM\Cascade("remove")
66
     */
67
    protected $posts;
68
69

    /**
70
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<Category>
71
     */
72
    protected $categories;
73
74
75
76
77

    /**
     * The blog's administrator
     *
     * @var \ExtbaseTeam\BlogExample\Domain\Model\Administrator
78
     * @Extbase\ORM\Lazy
79
     */
80
    protected $administrator;
81
82
83
84
85
86

    /**
     * Constructs a new Blog
     */
    public function __construct()
    {
87
88
        $this->posts = new ObjectStorage();
        $this->categories = new ObjectStorage();
89
90
    }

91
92
93
    /**
     * @return string
     */
94
    public function getSubtitle(): string
95
96
97
98
    {
        return $this->subtitle;
    }

99
100
101
102
103
    /**
     * Sets this blog's title
     *
     * @param string $title The blog's title
     */
104
    public function setTitle($title): void
105
106
107
108
109
110
111
112
113
    {
        $this->title = $title;
    }

    /**
     * Returns the blog's title
     *
     * @return string The blog's title
     */
114
    public function getTitle(): string
115
116
117
118
119
120
121
    {
        return $this->title;
    }

    /**
     * @param string $logo
     */
122
    public function setLogo($logo): void
123
124
125
126
127
128
129
    {
        $this->logo = $logo;
    }

    /**
     * @return string
     */
130
    public function getLogo(): string
131
132
133
134
135
136
137
138
139
    {
        return $this->logo;
    }

    /**
     * Sets the description for the blog
     *
     * @param string $description
     */
140
    public function setDescription($description): void
141
142
143
144
145
146
147
148
149
    {
        $this->description = $description;
    }

    /**
     * Returns the description
     *
     * @return string
     */
150
    public function getDescription(): string
151
152
153
154
155
156
157
158
159
    {
        return $this->description;
    }

    /**
     * Adds a post to this blog
     *
     * @param Post $post
     */
160
    public function addPost(Post $post): void
161
162
163
164
165
166
167
168
169
    {
        $this->posts->attach($post);
    }

    /**
     * Remove a post from this blog
     *
     * @param Post $postToRemove The post to be removed
     */
170
    public function removePost(Post $postToRemove): void
171
172
173
174
175
176
177
    {
        $this->posts->detach($postToRemove);
    }

    /**
     * Remove all posts from this blog
     */
178
    public function removeAllPosts(): void
179
    {
180
        $this->posts = new ObjectStorage();
181
182
183
184
185
186
187
    }

    /**
     * Returns all posts in this blog
     *
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
     */
188
    public function getPosts(): ObjectStorage
189
190
191
192
193
194
195
    {
        return $this->posts;
    }

    /**
     * Add category to a blog
     *
196
     * @param Category $category
197
     */
198
    public function addCategory(Category $category): void
199
200
201
202
203
204
205
206
207
    {
        $this->categories->attach($category);
    }

    /**
     * Set categories
     *
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories
     */
208
    public function setCategories($categories): void
209
210
211
212
213
214
215
216
217
    {
        $this->categories = $categories;
    }

    /**
     * Get categories
     *
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
     */
218
    public function getCategories(): ObjectStorage
219
220
221
222
223
224
225
    {
        return $this->categories;
    }

    /**
     * Remove category from blog
     *
226
     * @param Category $category
227
     */
228
    public function removeCategory(Category $category): void
229
230
231
232
233
234
235
236
237
    {
        $this->categories->detach($category);
    }

    /**
     * Sets the administrator value
     *
     * @param Administrator $administrator The Administrator of this Blog
     */
238
    public function setAdministrator(Administrator $administrator): void
239
240
241
242
243
244
245
    {
        $this->administrator = $administrator;
    }

    /**
     * Returns the administrator value
     *
246
     * @return Administrator|LazyLoadingProxy|null
247
248
249
250
251
     */
    public function getAdministrator()
    {
        return $this->administrator;
    }
252
253

    /**
254
     * @param string|null $subtitle
255
     */
256
    public function setSubtitle($subtitle): void
257
258
259
    {
        $this->subtitle = $subtitle;
    }
260
}