1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the CCDNForum ForumBundle |
5
|
|
|
* |
6
|
|
|
* (c) CCDN (c) CodeConsortium <http://www.codeconsortium.com/> |
7
|
|
|
* |
8
|
|
|
* Available on github <http://www.github.com/codeconsortium/> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace CCDNForum\ForumBundle\Entity; |
15
|
|
|
|
16
|
|
|
use CCDNForum\ForumBundle\Entity\Model\Board as AbstractBoard; |
17
|
|
|
use Symfony\Component\Security\Core\SecurityContextInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
* @category CCDNForum |
22
|
|
|
* @package ForumBundle |
23
|
|
|
* |
24
|
|
|
* @author Reece Fowell <[email protected]> |
25
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
26
|
|
|
* @version Release: 2.0 |
27
|
|
|
* @link https://github.com/codeconsortium/CCDNForumForumBundle |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
class Board extends AbstractBoard |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
* @var integer $id |
35
|
|
|
*/ |
36
|
|
|
protected $id; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
* @var string name |
41
|
|
|
*/ |
42
|
|
|
protected $name; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* |
46
|
|
|
* @var string $description\ |
47
|
|
|
*/ |
48
|
|
|
protected $description; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
* @var integer $cachedTopicCount |
53
|
|
|
*/ |
54
|
|
|
protected $cachedTopicCount = 0; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* |
58
|
|
|
* @var integer $cachedPostCount |
59
|
|
|
*/ |
60
|
|
|
protected $cachedPostCount = 0; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* |
64
|
|
|
* @var integer $listOrderPriority |
65
|
|
|
*/ |
66
|
|
|
protected $listOrderPriority = 0; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* |
70
|
|
|
* @var array $readAuthorisedRoles |
71
|
|
|
*/ |
72
|
|
|
protected $readAuthorisedRoles; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* |
76
|
|
|
* @var array $topicCreateAuthorisedRoles |
77
|
|
|
*/ |
78
|
|
|
protected $topicCreateAuthorisedRoles; |
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* |
82
|
|
|
* @var array $topicReplyAuthorisedRoles |
83
|
|
|
*/ |
84
|
|
|
protected $topicReplyAuthorisedRoles; |
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* |
88
|
|
|
* @access public |
89
|
|
|
*/ |
90
|
|
|
public function __construct() |
91
|
|
|
{ |
92
|
|
|
parent::__construct(); |
93
|
|
|
|
94
|
|
|
// your own logic |
95
|
|
|
$this->readAuthorisedRoles = array(); |
96
|
|
|
$this->topicCreateAuthorisedRoles = array(); |
97
|
|
|
$this->topicReplyAuthorisedRoles = array(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function __toString() |
101
|
|
|
{ |
102
|
|
|
return $this->name; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get id |
107
|
|
|
* |
108
|
|
|
* @return integer |
109
|
|
|
*/ |
110
|
|
|
public function getId() |
111
|
|
|
{ |
112
|
|
|
return $this->id; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get name |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getName() |
121
|
|
|
{ |
122
|
|
|
return $this->name; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set name |
127
|
|
|
* |
128
|
|
|
* @param string $name |
129
|
|
|
* @return Board |
130
|
|
|
*/ |
131
|
|
|
public function setName($name) |
132
|
|
|
{ |
133
|
|
|
$this->name = $name; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get description |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getDescription() |
144
|
|
|
{ |
145
|
|
|
return $this->description; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set description |
150
|
|
|
* |
151
|
|
|
* @param string $description |
152
|
|
|
* @return Board |
153
|
|
|
*/ |
154
|
|
|
public function setDescription($description) |
155
|
|
|
{ |
156
|
|
|
$this->description = $description; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Get list_order_priority |
163
|
|
|
* |
164
|
|
|
* @return integer |
165
|
|
|
*/ |
166
|
|
|
public function getListOrderPriority() |
167
|
|
|
{ |
168
|
|
|
return $this->listOrderPriority; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Set list_order_priority |
173
|
|
|
* |
174
|
|
|
* @param integer $listOrderPriority |
175
|
|
|
* @return Board |
176
|
|
|
*/ |
177
|
|
|
public function setListOrderPriority($listOrderPriority) |
178
|
|
|
{ |
179
|
|
|
$this->listOrderPriority = $listOrderPriority; |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Get cachedTopicCount |
186
|
|
|
* |
187
|
|
|
* @return integer |
188
|
|
|
*/ |
189
|
|
|
public function getCachedTopicCount() |
190
|
|
|
{ |
191
|
|
|
return $this->cachedTopicCount; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Set cachedTopicCount |
196
|
|
|
* |
197
|
|
|
* @param integer $cachedTopicCount |
198
|
|
|
* @return Board |
199
|
|
|
*/ |
200
|
|
|
public function setCachedTopicCount($cachedTopicCount) |
201
|
|
|
{ |
202
|
|
|
$this->cachedTopicCount = $cachedTopicCount; |
203
|
|
|
|
204
|
|
|
return $this; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Get cachedPostCount |
209
|
|
|
* |
210
|
|
|
* @return integer |
211
|
|
|
*/ |
212
|
|
|
public function getCachedPostCount() |
213
|
|
|
{ |
214
|
|
|
return $this->cachedPostCount; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Set cachedPostCount |
219
|
|
|
* |
220
|
|
|
* @param integer $cachedPostCount |
221
|
|
|
* @return Board |
222
|
|
|
*/ |
223
|
|
|
public function setCachedPostCount($cachedPostCount) |
224
|
|
|
{ |
225
|
|
|
$this->cachedPostCount = $cachedPostCount; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return array |
232
|
|
|
*/ |
233
|
|
|
public function getReadAuthorisedRoles() |
234
|
|
|
{ |
235
|
|
|
return $this->readAuthorisedRoles; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param array $roles |
|
|
|
|
240
|
|
|
* @return Board |
241
|
|
|
*/ |
242
|
|
|
public function setReadAuthorisedRoles(array $roles = null) |
243
|
|
|
{ |
244
|
|
|
$this->readAuthorisedRoles = $roles; |
|
|
|
|
245
|
|
|
|
246
|
|
|
return $this; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @param $role |
251
|
|
|
* |
252
|
|
|
* @return bool |
253
|
|
|
*/ |
254
|
|
|
public function hasReadAuthorisedRole($role) |
255
|
|
|
{ |
256
|
|
|
return in_array($role, $this->readAuthorisedRoles); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @param SecurityContextInterface $securityContext |
261
|
|
|
* |
262
|
|
|
* @return bool |
263
|
|
|
*/ |
264
|
|
|
public function isAuthorisedToRead(SecurityContextInterface $securityContext) |
265
|
|
|
{ |
266
|
|
|
if (0 == count($this->readAuthorisedRoles)) { |
267
|
|
|
return true; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
foreach ($this->readAuthorisedRoles as $role) { |
271
|
|
|
if ($securityContext->isGranted($role)) { |
272
|
|
|
return true; |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
return false; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @return array |
281
|
|
|
*/ |
282
|
|
|
public function getTopicCreateAuthorisedRoles() |
283
|
|
|
{ |
284
|
|
|
return $this->topicCreateAuthorisedRoles; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param array $roles |
|
|
|
|
289
|
|
|
* |
290
|
|
|
* @return Board |
291
|
|
|
*/ |
292
|
|
|
public function setTopicCreateAuthorisedRoles(array $roles = null) |
293
|
|
|
{ |
294
|
|
|
$this->topicCreateAuthorisedRoles = $roles; |
|
|
|
|
295
|
|
|
|
296
|
|
|
return $this; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @param $role |
301
|
|
|
* |
302
|
|
|
* @return bool |
303
|
|
|
*/ |
304
|
|
|
public function hasTopicCreateAuthorisedRole($role) |
305
|
|
|
{ |
306
|
|
|
return in_array($role, $this->topicCreateAuthorisedRoles); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @param SecurityContextInterface $securityContext |
311
|
|
|
* |
312
|
|
|
* @return bool |
313
|
|
|
*/ |
314
|
|
|
public function isAuthorisedToCreateTopic(SecurityContextInterface $securityContext) |
315
|
|
|
{ |
316
|
|
|
if (0 == count($this->topicCreateAuthorisedRoles)) { |
317
|
|
|
return true; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
foreach ($this->topicCreateAuthorisedRoles as $role) { |
321
|
|
|
if ($securityContext->isGranted($role)) { |
322
|
|
|
return true; |
323
|
|
|
} |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
return false; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* @return array |
331
|
|
|
*/ |
332
|
|
|
public function getTopicReplyAuthorisedRoles() |
333
|
|
|
{ |
334
|
|
|
return $this->topicReplyAuthorisedRoles; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* @param array $roles |
|
|
|
|
339
|
|
|
* |
340
|
|
|
* @return Board |
341
|
|
|
*/ |
342
|
|
|
public function setTopicReplyAuthorisedRoles(array $roles = null) |
343
|
|
|
{ |
344
|
|
|
$this->topicReplyAuthorisedRoles = $roles; |
|
|
|
|
345
|
|
|
|
346
|
|
|
return $this; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* @param $role |
351
|
|
|
* |
352
|
|
|
* @return bool |
353
|
|
|
*/ |
354
|
|
|
public function hasTopicReplyAuthorisedRole($role) |
355
|
|
|
{ |
356
|
|
|
return in_array($role, $this->topicReplyAuthorisedRoles); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* @param SecurityContextInterface $securityContext |
361
|
|
|
* |
362
|
|
|
* @return bool |
363
|
|
|
*/ |
364
|
|
|
public function isAuthorisedToReplyToTopic(SecurityContextInterface $securityContext) |
365
|
|
|
{ |
366
|
|
|
if (0 == count($this->topicReplyAuthorisedRoles)) { |
367
|
|
|
return true; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
foreach ($this->topicReplyAuthorisedRoles as $role) { |
371
|
|
|
if ($securityContext->isGranted($role)) { |
372
|
|
|
return true; |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
return false; |
377
|
|
|
} |
378
|
|
|
} |
379
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.