zend-blog-3-backend
202 строки · 3.4 Кб
1<?php
2
3namespace App\Entity;4
5use DateTime;6use Doctrine\Common\Collections\ArrayCollection;7use Doctrine\Common\Collections\Collection;8use Doctrine\ORM\Mapping as ORM;9
10/**
11* @ORM\Table(name="tracking_agent")
12* @ORM\Entity(repositoryClass="App\Repository\TrackingAgentRepository")
13*/
14class TrackingAgent15{
16/**17* @var int
18*
19* @ORM\Id
20* @ORM\Column(type="integer")
21* @ORM\GeneratedValue(strategy="AUTO")
22*/
23protected $id;24
25/**26* @var string
27*
28* @ORM\Column(type="text", length=65000)
29*/
30protected $userAgent;31
32/**33* @var string
34*
35* @ORM\Column(type="string", length=32, unique=true)
36*/
37protected $hash;38
39/**40* @var bool
41*
42* @ORM\Column(type="boolean", name="is_bot", options={"default": false})
43*/
44protected $bot = false;45
46/**47* @var DateTime
48*
49* @ORM\Column(type="milliseconds_dt", options={"default": "CURRENT_TIMESTAMP(3)"})
50*/
51protected $createdAt;52
53/**54* @var Collection
55*
56* @ORM\OneToMany(targetEntity="Tracking", mappedBy="trackingAgent", cascade={"persist"})
57*/
58protected $trackings;59
60public function __construct()61{62$this->trackings = new ArrayCollection();63$this->createdAt = new DateTime();64}65
66/**67* Get id
68*
69* @return int
70*/
71public function getId()72{73return $this->id;74}75
76/**77* Set userAgent
78*
79* @param string $userAgent
80*
81* @return TrackingAgent
82*/
83public function setUserAgent($userAgent)84{85$this->userAgent = $userAgent;86$this->hash = md5($userAgent);87
88return $this;89}90
91/**92* Get userAgent
93*
94* @return string
95*/
96public function getUserAgent()97{98return $this->userAgent;99}100
101/**102* Add trackings
103*
104* @param Tracking $trackings
105*
106* @return TrackingAgent
107*/
108public function addTracking(Tracking $trackings)109{110$this->trackings[] = $trackings;111
112return $this;113}114
115/**116* Remove trackings
117*
118* @param Tracking $trackings
119*/
120public function removeTracking(Tracking $trackings)121{122$this->trackings->removeElement($trackings);123}124
125/**126* Get trackings
127*
128* @return Collection
129*/
130public function getTrackings()131{132return $this->trackings;133}134
135/**136* Set hash
137*
138* @param string $hash
139*
140* @return TrackingAgent
141*/
142public function setHash($hash)143{144$this->hash = $hash;145
146return $this;147}148
149/**150* Get hash
151*
152* @return string
153*/
154public function getHash()155{156return $this->hash;157}158
159/**160* Set createdAt
161*
162* @param DateTime $createdAt
163*
164* @return TrackingAgent
165*/
166public function setCreatedAt($createdAt)167{168$this->createdAt = $createdAt;169
170return $this;171}172
173/**174* Get createdAt
175*
176* @return DateTime
177*/
178public function getCreatedAt(): DateTime179{180return $this->createdAt;181}182
183/**184* @return bool
185*/
186public function isBot(): bool187{188return $this->bot;189}190
191/**192* @param bool $bot
193*
194* @return $this
195*/
196public function setBot(bool $bot): self197{198$this->bot = $bot;199
200return $this;201}202}
203