zend-blog-3-backend
411 строк · 7.3 Кб
1<?php
2
3namespace App\Entity;4
5use App\Entity\Embedded\NestedSet;6use App\Entity\Traits\ModifyEntityTrait;7use DateTime;8use Doctrine\Common\Collections\ArrayCollection;9use Doctrine\Common\Collections\Collection;10use Doctrine\ORM\Mapping as ORM;11
12/**
13* @ORM\Table(name="comments", indexes={
14* @ORM\Index(name="left_key_idx", columns={"tree_left_key"}),
15* @ORM\Index(name="right_key_idx", columns={"tree_right_key"})
16* })
17* @ORM\Entity(repositoryClass="App\Repository\CommentRepository")
18* @ORM\HasLifecycleCallbacks()
19*/
20class Comment implements CommentInterface21{
22use ModifyEntityTrait;23
24/**25* @var int
26*
27* @ORM\Id
28* @ORM\Column(type="integer")
29* @ORM\GeneratedValue(strategy="AUTO")
30*/
31protected $id;32
33/**34* @var Collection
35*
36* @ORM\OneToMany(targetEntity="Comment", mappedBy="parent")
37**/
38protected $children;39
40/**41* @ORM\ManyToOne(targetEntity="Comment", inversedBy="children")
42* @ORM\JoinColumn(onDelete="SET NULL")
43**/
44protected $parent;45
46/**47* @var Post
48*
49* @ORM\ManyToOne(targetEntity="Post", inversedBy="comments")
50* @ORM\JoinColumn(nullable=false)
51*/
52protected $post;53
54/**55* @var Commentator
56*
57* @ORM\ManyToOne(targetEntity="Commentator", inversedBy="comments")
58*/
59protected $commentator;60
61/**62* @var User
63*
64* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="comments")
65*/
66protected $user;67
68/**69* @var string
70*
71* @ORM\Column(type="text")
72*/
73protected $text;74
75/**76* @var bool
77*
78* @ORM\Column(type="boolean", options={"default": false})
79*/
80protected $deleted = false;81
82/**83* @var TrackingAgent
84*
85* @ORM\ManyToOne(targetEntity="TrackingAgent")
86* @ORM\JoinColumn(name="user_agent_id", referencedColumnName="id", onDelete="SET NULL")
87*/
88protected $trackingAgent;89
90/**91* @var string|null
92*
93* @ORM\Column(name="ip_addr", type="string", length=15, nullable=true)
94*/
95protected $ipAddress;96
97/**98* @var GeoLocation
99*
100* @ORM\ManyToOne(targetEntity="GeoLocation")
101* @ORM\JoinColumn(name="ip_long", referencedColumnName="ip_long", onDelete="SET NULL")
102*/
103private $geoLocation;104
105/**106* @var NestedSet
107*
108* @ORM\Embedded(class="App\Entity\Embedded\NestedSet", columnPrefix = "tree_")
109*/
110private $nestedSet;111
112public function __construct()113{114$this->children = new ArrayCollection();115$this->timeCreated = new DateTime();116$this->nestedSet = new NestedSet();117}118
119/**120* Get id
121*
122* @return int
123*/
124public function getId(): ?int125{126return $this->id;127}128
129/**130* @return string
131*/
132public function getAvatarHash(): string133{134$hash = '';135if ($this->getCommentator()) {136$hash = $this->getCommentator()->getAvatarHash();137} elseif ($this->getUser()) {138$hash = $this->getUser()->getAvatarHash();139}140
141return $hash;142}143
144/**145* Add children
146*
147* @param Comment $children
148*
149* @return Comment
150*/
151public function addChild(self $children)152{153$this->children[] = $children;154
155return $this;156}157
158/**159* Remove children
160*
161* @param Comment $children
162*/
163public function removeChild(self $children)164{165$this->children->removeElement($children);166}167
168/**169* Get children
170*
171* @return Collection
172*/
173public function getChildren()174{175return $this->children;176}177
178/**179* Set parent
180*
181* @param Comment|null $parent
182*
183* @return Comment
184*/
185public function setParent(self $parent = null)186{187$this->parent = $parent;188
189return $this;190}191
192/**193* Get parent
194*
195* @return Comment|null
196*/
197public function getParent(): ?Comment198{199return $this->parent;200}201
202/**203* Set commentator
204*
205* @param Commentator|null $commentator
206*
207* @return Comment
208*/
209public function setCommentator(Commentator $commentator = null)210{211$this->commentator = $commentator;212
213return $this;214}215
216/**217* Get commentator
218*
219* @return Commentator|null
220*/
221public function getCommentator(): ?Commentator222{223return $this->commentator;224}225
226/**227* Set user
228*
229* @param User|null $user
230*
231* @return Comment
232*/
233public function setUser(User $user = null)234{235$this->user = $user;236
237return $this;238}239
240/**241* Get user
242*
243* @return User|null
244*/
245public function getUser(): ?User246{247return $this->user;248}249
250/**251* Set text
252*
253* @param string $text
254*
255* @return Comment
256*/
257public function setText($text)258{259$this->text = $text;260
261return $this;262}263
264/**265* Get text
266*
267* @return string
268*/
269public function getText(): string270{271return $this->text;272}273
274/**275* Set deleted
276*
277* @param bool $deleted
278*
279* @return Comment
280*/
281public function setDeleted($deleted)282{283$this->deleted = $deleted;284
285return $this;286}287
288/**289* Is deleted
290*
291* @return bool
292*/
293public function isDeleted(): bool294{295return $this->deleted;296}297
298/**299* Set ipAddress
300*
301* @param string|null $ipAddress
302*
303* @return Comment
304*/
305public function setIpAddress($ipAddress)306{307$this->ipAddress = $ipAddress;308
309return $this;310}311
312/**313* Get ipAddress
314*
315* @return string|null
316*/
317public function getIpAddress()318{319return $this->ipAddress;320}321
322/**323* Set post
324*
325* @param Post $post
326*
327* @return Comment
328*/
329public function setPost(Post $post = null)330{331$this->post = $post;332
333return $this;334}335
336/**337* Get post
338*
339* @return Post
340*/
341public function getPost()342{343return $this->post;344}345
346/**347* Set trackingAgent
348*
349* @param TrackingAgent $trackingAgent
350*
351* @return Comment
352*/
353public function setTrackingAgent(TrackingAgent $trackingAgent = null)354{355$this->trackingAgent = $trackingAgent;356
357return $this;358}359
360/**361* Get trackingAgent
362*
363* @return TrackingAgent
364*/
365public function getTrackingAgent()366{367return $this->trackingAgent;368}369
370/**371* Get geoLocation
372*
373* @return GeoLocation|null
374*/
375public function getGeoLocation(): ?GeoLocation376{377return $this->geoLocation;378}379
380/**381* @param GeoLocation|null $location
382*
383* @return $this
384*/
385public function setGeoLocation(GeoLocation $location = null): self386{387$this->geoLocation = $location;388
389return $this;390}391
392/**393* @return NestedSet
394*/
395public function getNestedSet(): NestedSet396{397return $this->nestedSet;398}399
400/**401* @param NestedSet $nestedSet
402*
403* @return $this
404*/
405public function setNestedSet(NestedSet $nestedSet): self406{407$this->nestedSet = $nestedSet;408
409return $this;410}411}
412