1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* User action Entity. |
9
|
|
|
* |
10
|
|
|
* @ORM\Table(name="user_actions") |
11
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\UserActionRepository") |
12
|
|
|
* @ORM\HasLifecycleCallbacks() |
13
|
|
|
* |
14
|
|
|
* @author Borut Balažek <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class UserActionEntity |
17
|
|
|
{ |
18
|
|
|
/*************** Variables ***************/ |
19
|
|
|
/********** General Variables **********/ |
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
* |
23
|
|
|
* @ORM\Column(name="id", type="integer") |
24
|
|
|
* @ORM\Id |
25
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
26
|
|
|
*/ |
27
|
|
|
protected $id; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
* |
32
|
|
|
* @ORM\Column(name="`key`", type="text", nullable=true) |
33
|
|
|
*/ |
34
|
|
|
protected $key; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
* |
39
|
|
|
* @ORM\Column(name="message", type="text", nullable=true) |
40
|
|
|
*/ |
41
|
|
|
protected $message; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
* |
46
|
|
|
* @ORM\Column(name="data", type="text", nullable=true) |
47
|
|
|
*/ |
48
|
|
|
protected $data; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
* |
53
|
|
|
* @ORM\Column(name="ip", type="string", length=255, nullable=true) |
54
|
|
|
*/ |
55
|
|
|
protected $ip; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
* |
60
|
|
|
* @ORM\Column(name="user_agent", type="text", nullable=true) |
61
|
|
|
*/ |
62
|
|
|
protected $userAgent; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var \DateTime |
66
|
|
|
* |
67
|
|
|
* @ORM\Column(name="time_created", type="datetime") |
68
|
|
|
*/ |
69
|
|
|
protected $timeCreated; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var \DateTime |
73
|
|
|
* |
74
|
|
|
* @ORM\Column(name="time_updated", type="datetime") |
75
|
|
|
*/ |
76
|
|
|
protected $timeUpdated; |
77
|
|
|
|
78
|
|
|
/***** Relationship Variables *****/ |
79
|
|
|
/** |
80
|
|
|
* @ORM\ManyToOne(targetEntity="Application\Entity\UserEntity", inversedBy="userActions") |
81
|
|
|
*/ |
82
|
|
|
protected $user; |
83
|
|
|
|
84
|
|
|
/*************** Methods ***************/ |
85
|
|
|
/*** Id ***/ |
86
|
|
|
/** |
87
|
|
|
* @return int |
88
|
|
|
*/ |
89
|
|
|
public function getId() |
90
|
|
|
{ |
91
|
|
|
return $this->id; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param $id |
96
|
|
|
* |
97
|
|
|
* @return UserActionEntity |
98
|
|
|
*/ |
99
|
|
|
public function setId($id) |
100
|
|
|
{ |
101
|
|
|
$this->id = $id; |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/*** Key ***/ |
107
|
|
|
/** |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
|
|
public function getKey() |
111
|
|
|
{ |
112
|
|
|
return $this->key; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param $key |
117
|
|
|
* |
118
|
|
|
* @return UserActionEntity |
119
|
|
|
*/ |
120
|
|
|
public function setKey($key) |
121
|
|
|
{ |
122
|
|
|
$this->key = $key; |
123
|
|
|
|
124
|
|
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/*** Message ***/ |
128
|
|
|
/** |
129
|
|
|
* @return string |
130
|
|
|
*/ |
131
|
|
|
public function getMessage() |
132
|
|
|
{ |
133
|
|
|
return $this->message; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param $message |
138
|
|
|
* |
139
|
|
|
* @return UserActionEntity |
140
|
|
|
*/ |
141
|
|
|
public function setMessage($message) |
142
|
|
|
{ |
143
|
|
|
$this->message = $message; |
144
|
|
|
|
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/*** Data ***/ |
149
|
|
|
/** |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function getData() |
153
|
|
|
{ |
154
|
|
|
return $this->data; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param $data |
159
|
|
|
* |
160
|
|
|
* @return UserActionEntity |
161
|
|
|
*/ |
162
|
|
|
public function setData($data) |
163
|
|
|
{ |
164
|
|
|
if (is_array($data)) { |
165
|
|
|
$data = json_encode($data); |
166
|
|
|
|
167
|
|
|
$data = str_replace("\u0000*", '', $data); |
168
|
|
|
$data = str_replace("\u0000", '', $data); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$this->data = $data; |
172
|
|
|
|
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/*** IP ***/ |
177
|
|
|
/** |
178
|
|
|
* @return string |
179
|
|
|
*/ |
180
|
|
|
public function getIp() |
181
|
|
|
{ |
182
|
|
|
return $this->ip; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param $ip |
187
|
|
|
* |
188
|
|
|
* @return UserActionEntity |
189
|
|
|
*/ |
190
|
|
|
public function setIp($ip) |
191
|
|
|
{ |
192
|
|
|
$this->ip = $ip; |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/*** User agent ***/ |
198
|
|
|
/** |
199
|
|
|
* @return string |
200
|
|
|
*/ |
201
|
|
|
public function getUserAgent() |
202
|
|
|
{ |
203
|
|
|
return $this->userAgent; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param $userAgent |
208
|
|
|
* |
209
|
|
|
* @return UserActionEntity |
210
|
|
|
*/ |
211
|
|
|
public function setUserAgent($userAgent) |
212
|
|
|
{ |
213
|
|
|
$this->userAgent = $userAgent; |
214
|
|
|
|
215
|
|
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/*** Time created ***/ |
219
|
|
|
/** |
220
|
|
|
* @return \DateTime |
221
|
|
|
*/ |
222
|
|
|
public function getTimeCreated() |
223
|
|
|
{ |
224
|
|
|
return $this->timeCreated; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param \DateTime $timeCreated |
229
|
|
|
* |
230
|
|
|
* @return UserActionEntity |
231
|
|
|
*/ |
232
|
|
|
public function setTimeCreated(\DateTime $timeCreated) |
233
|
|
|
{ |
234
|
|
|
$this->timeCreated = $timeCreated; |
235
|
|
|
|
236
|
|
|
return $this; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/*** Time updated ***/ |
240
|
|
|
/** |
241
|
|
|
* @return \DateTime |
242
|
|
|
*/ |
243
|
|
|
public function getTimeUpdated() |
244
|
|
|
{ |
245
|
|
|
return $this->timeUpdated; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @param \DateTime $timeUpdated |
250
|
|
|
* |
251
|
|
|
* @return UserActionEntity |
252
|
|
|
*/ |
253
|
|
|
public function setTimeUpdated(\DateTime $timeUpdated) |
254
|
|
|
{ |
255
|
|
|
$this->timeUpdated = $timeUpdated; |
256
|
|
|
|
257
|
|
|
return $this; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/*** User ***/ |
261
|
|
|
/** |
262
|
|
|
* @return UserEntity $user |
263
|
|
|
*/ |
264
|
|
|
public function getUser() |
265
|
|
|
{ |
266
|
|
|
return $this->user; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @param UserEntity $user |
271
|
|
|
* |
272
|
|
|
* @return UserActionEntity |
273
|
|
|
*/ |
274
|
|
|
public function setUser(\Application\Entity\UserEntity $user = null) |
275
|
|
|
{ |
276
|
|
|
$this->user = $user; |
277
|
|
|
|
278
|
|
|
return $this; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/********** Other Methods **********/ |
282
|
|
|
/** |
283
|
|
|
* @return array |
284
|
|
|
*/ |
285
|
|
|
public function toArray() |
286
|
|
|
{ |
287
|
|
|
return array( |
288
|
|
|
'id' => $this->getId(), |
289
|
|
|
'key' => $this->getKey(), |
290
|
|
|
'ip' => $this->getIp(), |
291
|
|
|
'time_created' => $this->getTimeCreated()->format(DATE_ATOM), |
292
|
|
|
); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/********** Callback Methods **********/ |
296
|
|
|
/** |
297
|
|
|
* @ORM\PreUpdate |
298
|
|
|
*/ |
299
|
|
|
public function preUpdate() |
300
|
|
|
{ |
301
|
|
|
$this->setTimeUpdated(new \DateTime('now')); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @ORM\PrePersist |
306
|
|
|
*/ |
307
|
|
|
public function prePersist() |
308
|
|
|
{ |
309
|
|
|
$this->setTimeUpdated(new \DateTime('now')); |
310
|
|
|
$this->setTimeCreated(new \DateTime('now')); |
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
|