forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.php
423 lines (329 loc) · 9.39 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
<?php
declare(strict_types=1);
namespace Documents;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use function bcadd;
/**
* @ODM\Document(collection="users")
* @ODM\InheritanceType("COLLECTION_PER_CLASS")
*/
class User extends BaseDocument
{
/** @ODM\Id */
protected $id;
/** @ODM\Field(type="string") */
protected $username;
/** @ODM\Field(type="bin_md5") */
protected $password;
/** @ODM\Field(type="date") */
protected $createdAt;
/** @ODM\EmbedOne(targetDocument=Address::class) */
protected $address;
/** @ODM\EmbedOne(targetDocument=Address::class, nullable=true) */
protected $addressNullable;
/** @ODM\ReferenceOne(targetDocument=Profile::class, cascade={"all"}) */
protected $profile;
/** @ODM\ReferenceOne(targetDocument=ProfileNotify::class, cascade={"all"}) */
protected $profileNotify;
/** @ODM\EmbedMany(targetDocument=Phonenumber::class) */
protected $phonenumbers;
/** @ODM\EmbedMany(targetDocument=Phonebook::class) */
protected $phonebooks;
/** @ODM\ReferenceMany(targetDocument=Group::class, cascade={"all"}) */
protected $groups;
/** @ODM\ReferenceMany(targetDocument=Group::class, storeAs="id", cascade={"all"}) */
protected $groupsSimple;
/** @ODM\ReferenceMany(targetDocument=Group::class, cascade={"all"}, strategy="addToSet") */
protected $uniqueGroups;
/** @ODM\ReferenceMany(targetDocument=Group::class, name="groups", notSaved=true, sort={"name"="asc"}, strategy="setArray") */
protected $sortedAscGroups;
/** @ODM\ReferenceMany(targetDocument=Group::class, name="groups", notSaved=true, sort={"name"="desc"}, strategy="setArray") */
protected $sortedDescGroups;
/** @ODM\ReferenceOne(targetDocument=Account::class, cascade={"all"}) */
protected $account;
/** @ODM\ReferenceOne(targetDocument=Account::class, storeAs="id", cascade={"all"}) */
protected $accountSimple;
/** @ODM\Field(type="int") */
protected $hits = 0;
/** @ODM\Field(type="string") */
protected $nullTest;
/** @ODM\Field(type="int", strategy="increment") */
protected $count;
/** @ODM\Field(type="float", strategy="increment") */
protected $floatCount;
/** @ODM\Field(type="decimal128", strategy="increment") */
protected $decimal128Count;
/** @ODM\ReferenceMany(targetDocument=BlogPost::class, mappedBy="user", nullable=true) */
protected $posts;
/** @ODM\ReferenceOne(targetDocument=SimpleReferenceUser::class, mappedBy="user") */
protected $simpleReferenceOneInverse;
/** @ODM\ReferenceMany(targetDocument=SimpleReferenceUser::class, mappedBy="users") */
protected $simpleReferenceManyInverse;
/** @ODM\ReferenceOne(targetDocument=ReferenceUser::class, mappedBy="referencedUser") */
protected $embeddedReferenceOneInverse;
/** @ODM\ReferenceMany(targetDocument=ReferenceUser::class, mappedBy="referencedUsers") */
protected $embeddedReferenceManyInverse;
/** @ODM\Field(type="collection") */
private $logs = [];
/** @var @ODM\ReferenceOne(storeAs="dbRefWithDb") */
protected $referenceToAnything;
/** @var @ODM\ReferenceOne(storeAs="dbRef") */
protected $referenceToAnythingWithoutDb;
public function __construct()
{
$this->phonebooks = new ArrayCollection();
$this->phonenumbers = new ArrayCollection();
$this->groups = new ArrayCollection();
$this->groupsSimple = new ArrayCollection();
$this->sortedGroups = new ArrayCollection();
$this->sortedGroupsAsc = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->createdAt = new DateTime();
}
public function setId($id)
{
$this->id = $id;
}
public function getLogs()
{
return $this->logs;
}
public function setLogs($logs)
{
$this->logs = $logs;
}
public function log($log)
{
$this->logs[] = $log;
}
public function getId()
{
return $this->id;
}
public function setUsername($username)
{
$this->username = $username;
}
public function getUsername()
{
return $this->username;
}
public function setPassword($password)
{
$this->password = $password;
}
public function getPassword()
{
return $this->password;
}
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function getAddress()
{
return $this->address;
}
public function setAddress(?Address $address = null)
{
$this->address = $address;
$this->addressNullable = $address ? clone $address : $address;
}
public function removeAddress()
{
$this->address = null;
$this->addressNullable = null;
}
public function setProfile(Profile $profile)
{
$this->profile = $profile;
}
public function getProfile()
{
return $this->profile;
}
public function setProfileNotify(ProfileNotify $profile)
{
$this->profileNotify = $profile;
}
public function getProfileNotify()
{
return $this->profileNotify;
}
public function setAccount(Account $account)
{
$this->account = $account;
$this->account->setUser($this);
}
public function getAccount()
{
return $this->account;
}
public function setAccountSimple(Account $account)
{
$this->accountSimple = $account;
$this->accountSimple->setUser($this);
}
public function getAccountSimple()
{
return $this->accountSimple;
}
public function getPhonenumbers()
{
return $this->phonenumbers;
}
public function addPhonenumber(Phonenumber $phonenumber)
{
$this->phonenumbers[] = $phonenumber;
}
public function getSortedAscGroups()
{
return $this->sortedAscGroups;
}
public function getSortedDescGroups()
{
return $this->sortedDescGroups;
}
public function getGroups()
{
return $this->groups;
}
public function setGroups($groups)
{
$this->groups = $groups;
}
public function addGroup(Group $group)
{
$this->groups[] = $group;
}
public function removeGroup($name)
{
foreach ($this->groups as $key => $group) {
if ($group->getName() === $name) {
unset($this->groups[$key]);
return true;
}
}
return false;
}
public function addGroupSimple(Group $group)
{
$this->groupsSimple[] = $group;
}
public function getUniqueGroups()
{
return $this->uniqueGroups;
}
public function setUniqueGroups($groups)
{
$this->uniqueGroups = $groups;
}
public function addUniqueGroup(Group $group)
{
$this->uniqueGroups[] = $group;
}
public function getHits()
{
return $this->hits;
}
public function setHits($hits)
{
$this->hits = $hits;
}
public function getCount()
{
return $this->count;
}
public function setCount($count)
{
$this->count = $count;
}
public function getFloatCount()
{
return $this->floatCount;
}
public function setFloatCount($floatCount)
{
$this->floatCount = $floatCount;
}
public function getDecimal128Count()
{
return $this->decimal128Count;
}
public function setDecimal128Count($decimal128Count)
{
$this->decimal128Count = $decimal128Count;
}
public function getSimpleReferenceOneInverse()
{
return $this->simpleReferenceOneInverse;
}
public function getSimpleReferenceManyInverse()
{
return $this->simpleReferenceManyInverse;
}
public function incrementCount($num = null)
{
if ($num === null) {
$this->count++;
} else {
$this->count += $num;
}
}
public function incrementFloatCount($num = null)
{
if ($num === null) {
$this->floatCount++;
} else {
$this->floatCount += $num;
}
}
public function incrementDecimal128Count($num = null)
{
$this->decimal128Count = bcadd($this->decimal128Count, $num ?? '1');
}
public function setPosts($posts)
{
$this->posts = $posts;
}
public function addPost(BlogPost $post)
{
$this->posts[] = $post;
}
public function removePost($id)
{
foreach ($this->posts as $key => $post) {
if ($post->getId() === $id) {
unset($this->posts[$key]);
return true;
}
}
return false;
}
public function getPosts()
{
return $this->posts;
}
public function setPhonenumbers($phonenumbers)
{
$this->phonenumbers = $phonenumbers;
}
public function addPhonebook(Phonebook $phonebook)
{
$this->phonebooks->add($phonebook);
}
public function getPhonebooks()
{
return $this->phonebooks;
}
public function removePhonebook(Phonebook $phonebook)
{
$this->phonebooks->removeElement($phonebook);
}
}