Node::setDescendantCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace AppBundle\Entity;
3
4
use DateTime;
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * Node
9
 */
10
class Node extends AbstractEntity
11
{
12
    const SYSTEM_ACCESS_CRYPTO      = 'crypto';
13
    const SYSTEM_ACCESS_CUBE        = 'cube';
14
    const SYSTEM_ACCESS_MODERATED   = 'moderated';
15
    const SYSTEM_ACCESS_PRIVATE     = 'private';
16
    const SYSTEM_ACCESS_PUBLIC      = 'public';
17
18
    const EXTERNAL_ACCESS_NO    = 'no';
19
    const EXTERNAL_ACCESS_YES   = 'yes';
20
21
    const EXTERNAL_LINK_FRIEND  = 'session://friend';
22
    const EXTERNAL_LINK_USER    = 'db://user';
23
24
    //region Column properties
25
26
    /** @var integer */
27
    protected $id;
28
29
    /** @var integer */
30
    protected $parentId = 0;
31
32
    /** @var string */
33
    protected $name;
34
35
    /** @var integer */
36
    protected $type = 1;
37
38
    /** @var integer */
39
    protected $templateId;
40
41
    /** @var string */
42
    protected $systemAccess = self::SYSTEM_ACCESS_PUBLIC;
43
44
    /** @var string */
45
    protected $externalAccess = self::EXTERNAL_ACCESS_NO;
46
47
    /** @var integer */
48
    protected $childrenCount = 0;
49
50
    /** @var integer */
51
    protected $descendantCount;
52
53
    /** @var integer */
54
    protected $k = 0;
55
56
    /** @var integer */
57
    protected $views;
58
59
    /** @var string */
60
    protected $externalLink;
61
62
    /** @var string */
63
    protected $vector;
64
65
    /** @var integer */
66
    protected $level3 = 0;
67
68
    /** @var string */
69
    protected $content;
70
71
    /** @var boolean */
72
    protected $nl2br = true;
73
74
    /** @var \DateTime */
75
    protected $createdAt;
76
77
    /** @var integer */
78
    protected $createdBy;
79
80
    /** @var integer */
81
    protected $parentCreatedBy;
82
83
    /** @var \DateTime */
84
    protected $updatedAt;
85
86
    /** @var \DateTime */
87
    protected $lastChildCreatedAt = 'CURRENT_TIMESTAMP';
88
89
    /** @var \DateTime */
90
    protected $lastDescendantCreatedAt;
91
92
    //endregion
93
94
    //region Association properties
95
96
    /** @var Node */
97
    protected $parent;
98
99
    /** @var Node[] */
100
    protected $children;
101
102
    /** @var User */
103
    protected $createdByUser;
104
105
    //endregion
106
107
    public function __construct()
108
    {
109
        $this->setCreatedAt(new DateTime());
110
    }
111
112
    //region Column methods
113
114
    public function getId()
115
    {
116
        return $this->id;
117
    }
118
119
    public function getParentId()
120
    {
121
        return $this->parentId;
122
    }
123
124
    public function setParentId($parentId)
125
    {
126
        $this->parentId = $parentId;
127
128
        return $this;
129
    }
130
131
    public function getName()
132
    {
133
        return $this->name;
134
    }
135
136
    public function setName($name)
137
    {
138
        $this->name = $name;
139
140
        return $this;
141
    }
142
143
    public function getType()
144
    {
145
        return $this->type;
146
    }
147
148
    public function setType($type)
149
    {
150
        $this->type = $type;
151
152
        return $this;
153
    }
154
155
    public function getTemplateId()
156
    {
157
        return $this->templateId;
158
    }
159
160
    public function setTemplateId($templateId)
161
    {
162
        $this->templateId = $templateId;
163
164
        return $this;
165
    }
166
167
    public function getSystemAccess()
168
    {
169
        return $this->systemAccess;
170
    }
171
172
    public function setSystemAccess($systemAccess)
173
    {
174
        $this->systemAccess = $systemAccess;
175
176
        return $this;
177
    }
178
179
    public function getExternalAccess()
180
    {
181
        return $this->externalAccess;
182
    }
183
184
    public function setExternalAccess($externalAccess)
185
    {
186
        $this->externalAccess = $externalAccess;
187
188
        return $this;
189
    }
190
191
    public function getChildrenCount()
192
    {
193
        return $this->childrenCount;
194
    }
195
196
    public function setChildrenCount($childrenCount)
197
    {
198
        $this->childrenCount = $childrenCount;
199
200
        return $this;
201
    }
202
203
    public function getDescendantCount()
204
    {
205
        return $this->descendantCount;
206
    }
207
208
    public function setDescendantCount($descendantCount)
209
    {
210
        $this->descendantCount = $descendantCount;
211
212
        return $this;
213
    }
214
215
    public function getK()
216
    {
217
        return $this->k;
218
    }
219
220
    public function setK($k)
221
    {
222
        $this->k = $k;
223
224
        return $this;
225
    }
226
227
    public function getViews()
228
    {
229
        return $this->views;
230
    }
231
232
    public function setViews($views)
233
    {
234
        $this->views = $views;
235
236
        return $this;
237
    }
238
239
    public function getExternalLink()
240
    {
241
        return $this->externalLink;
242
    }
243
244
    public function setExternalLink($externalLink)
245
    {
246
        $this->externalLink = $externalLink;
247
248
        return $this;
249
    }
250
251
    public function getVector()
252
    {
253
        return $this->vector;
254
    }
255
256
    public function setVector($vector)
257
    {
258
        $this->vector = $vector;
259
260
        return $this;
261
    }
262
263
    public function getLevel3()
264
    {
265
        return $this->level3;
266
    }
267
268
    public function setLevel3($level3)
269
    {
270
        $this->level3 = $level3;
271
272
        return $this;
273
    }
274
275
    public function getContent()
276
    {
277
        return $this->content;
278
    }
279
280
    public function setContent($content)
281
    {
282
        $this->content = $content;
283
284
        return $this;
285
    }
286
287
    public function getNl2Br()
288
    {
289
        return $this->nl2br;
290
    }
291
292
    public function setNl2Br($nl2br)
293
    {
294
        $this->nl2br = $nl2br;
295
296
        return $this;
297
    }
298
299
    public function getCreatedAt()
300
    {
301
        return $this->createdAt;
302
    }
303
304
    public function setCreatedAt(DateTime $createdAt)
305
    {
306
        $this->createdAt = $createdAt;
307
308
        return $this;
309
    }
310
311
    public function getCreatedBy()
312
    {
313
        return $this->createdBy;
314
    }
315
316
    public function setCreatedBy($createdBy)
317
    {
318
        $this->createdBy = $createdBy;
319
320
        return $this;
321
    }
322
323
    public function getParentCreatedBy()
324
    {
325
        return $this->parentCreatedBy;
326
    }
327
328
    public function setParentCreatedBy($parentCreatedBy)
329
    {
330
        $this->parentCreatedBy = $parentCreatedBy;
331
332
        return $this;
333
    }
334
335
    public function getUpdatedAt()
336
    {
337
        return $this->updatedAt;
338
    }
339
340
    public function setUpdatedAt(DateTime $updatedAt)
341
    {
342
        $this->updatedAt = $updatedAt;
343
344
        return $this;
345
    }
346
347
    public function getLastChildCreatedAt()
348
    {
349
        return $this->lastChildCreatedAt;
350
    }
351
352
    public function setLastChildCreatedAt(DateTime $lastChildCreatedAt)
353
    {
354
        $this->lastChildCreatedAt = $lastChildCreatedAt;
355
356
        return $this;
357
    }
358
359
    public function getLastDescendantCreatedAt()
360
    {
361
        return $this->lastDescendantCreatedAt;
362
    }
363
364
    public function setLastDescendantCreatedAt(DateTime $lastDescendantCreatedAt)
365
    {
366
        $this->lastDescendantCreatedAt = $lastDescendantCreatedAt;
367
368
        return $this;
369
    }
370
371
    //endregion
372
373
    //region Association methods
374
375
    public function getParent()
376
    {
377
        return $this->parent;
378
    }
379
380
    public function setParent(Node $parent = null)
381
    {
382
        $this->parent = $parent;
383
384
        return $this;
385
    }
386
387
    public function getChildren()
388
    {
389
        return $this->children;
390
    }
391
392
    public function addChildren(Node $child)
393
    {
394
        $this->children[] = $child;
395
396
        return $this;
397
    }
398
399
    public function getCreatedByUser()
400
    {
401
        return $this->createdByUser;
402
    }
403
404
    public function setCreatedByUser(User $createdByUser)
405
    {
406
        $this->createdByUser = $createdByUser;
407
408
        return $this;
409
    }
410
411
    //endregion
412
413
    //region Custom methods
414
415
    public function incrementViews($amount = 1)
416
    {
417
        $this->views += $amount;
418
419
        return $this;
420
    }
421
422
    public function hasExternalAccess()
423
    {
424
        return $this->externalAccess === static::EXTERNAL_ACCESS_YES;
425
    }
426
427
    public function isModerated()
428
    {
429
        return $this->systemAccess === static::SYSTEM_ACCESS_MODERATED;
430
    }
431
432
    public function isPrivate()
433
    {
434
        return $this->systemAccess === static::SYSTEM_ACCESS_PRIVATE;
435
    }
436
437
    public function isPublic()
438
    {
439
        return $this->systemAccess === static::SYSTEM_ACCESS_PUBLIC || empty($this->systemAccess);
440
    }
441
442
    //endregion
443
}
444