]> Raphaël G. Git Repositories - airbundle/blob - Entity/User.php
Fix subscriber user add/remove from inverse side
[airbundle] / Entity / User.php
1 <?php declare(strict_types=1);
2
3 /*
4 * this file is part of the rapsys packbundle package.
5 *
6 * (c) raphaël gertz <symfony@rapsys.eu>
7 *
8 * for the full copyright and license information, please view the license
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\AirBundle\Entity;
13
14 use Doctrine\Common\Collections\Collection;
15 use Doctrine\Common\Collections\ArrayCollection;
16
17 use Rapsys\UserBundle\Entity\User as BaseUser;
18
19 class User extends BaseUser {
20 /**
21 * @var ?string
22 */
23 private ?string $city;
24
25 /**
26 * @var ?string
27 */
28 private ?string $phone;
29
30 /**
31 * @var Country
32 */
33 private ?Country $country;
34
35 /**
36 * @var ?string
37 */
38 private ?string $pseudonym;
39
40 /**
41 * @var ?string
42 */
43 private ?string $zipcode;
44
45 /**
46 * @var \Doctrine\Common\Collections\Collection
47 */
48 private Collection $applications;
49
50 /**
51 * @var \Doctrine\Common\Collections\Collection
52 */
53 private Collection $dances;
54
55 /**
56 * @var \Doctrine\Common\Collections\Collection
57 */
58 private Collection $locations;
59
60 /**
61 * @var \Doctrine\Common\Collections\Collection
62 */
63 private Collection $snippets;
64
65 /**
66 * @var \Doctrine\Common\Collections\Collection
67 */
68 private Collection $subscribers;
69
70 /**
71 * @var \Doctrine\Common\Collections\Collection
72 */
73 private Collection $subscriptions;
74
75 /**
76 * @var \Doctrine\Common\Collections\Collection
77 */
78 private Collection $googleTokens;
79
80 /**
81 * Constructor
82 *
83 * @param string $mail The user mail
84 */
85 public function __construct(string $mail) {
86 //Call parent constructor
87 parent::__construct($mail);
88
89 //Set defaults
90 $this->city = null;
91 $this->country = null;
92 $this->phone = null;
93 $this->pseudonym = null;
94 $this->zipcode = null;
95
96 //Set collections
97 $this->applications = new ArrayCollection();
98 $this->dances = new ArrayCollection();
99 $this->locations = new ArrayCollection();
100 $this->snippets = new ArrayCollection();
101 $this->subscribers = new ArrayCollection();
102 $this->subscriptions = new ArrayCollection();
103 $this->googleTokens = new ArrayCollection();
104 }
105
106 /**
107 * Set city
108 *
109 * @param string $city
110 *
111 * @return User
112 */
113 public function setCity(?string $city): User {
114 $this->city = $city;
115
116 return $this;
117 }
118
119 /**
120 * Get city
121 *
122 * @return string
123 */
124 public function getCity(): ?string {
125 return $this->city;
126 }
127
128 /**
129 * Set country
130 *
131 * @param Country $country
132 *
133 * @return User
134 */
135 public function setCountry(?Country $country): User {
136 $this->country = $country;
137
138 return $this;
139 }
140
141 /**
142 * Get country
143 *
144 * @return Country
145 */
146 public function getCountry(): ?Country {
147 return $this->country;
148 }
149
150 /**
151 * Set phone
152 *
153 * @param string $phone
154 *
155 * @return User
156 */
157 public function setPhone(?string $phone): User {
158 $this->phone = $phone;
159
160 return $this;
161 }
162
163 /**
164 * Get phone
165 *
166 * @return string
167 */
168 public function getPhone(): ?string {
169 return $this->phone;
170 }
171
172 /**
173 * Set pseudonym
174 *
175 * @param string $pseudonym
176 *
177 * @return User
178 */
179 public function setPseudonym(?string $pseudonym): User {
180 $this->pseudonym = $pseudonym;
181
182 return $this;
183 }
184
185 /**
186 * Get pseudonym
187 *
188 * @return string
189 */
190 public function getPseudonym(): ?string {
191 return $this->pseudonym;
192 }
193
194 /**
195 * Set zipcode
196 *
197 * @param string $zipcode
198 *
199 * @return User
200 */
201 public function setZipcode(?string $zipcode): User {
202 $this->zipcode = $zipcode;
203
204 return $this;
205 }
206
207 /**
208 * Get zipcode
209 *
210 * @return string
211 */
212 public function getZipcode(): ?string {
213 return $this->zipcode;
214 }
215
216 /**
217 * Add application
218 *
219 * @param Application $application
220 *
221 * @return User
222 */
223 public function addApplication(Application $application): User {
224 $this->applications[] = $application;
225
226 return $this;
227 }
228
229 /**
230 * Remove application
231 *
232 * @param Application $application
233 */
234 public function removeApplication(Application $application): bool {
235 return $this->applications->removeElement($application);
236 }
237
238 /**
239 * Get applications
240 *
241 * @return \Doctrine\Common\Collections\Collection
242 */
243 public function getApplications(): Collection {
244 return $this->applications;
245 }
246
247 /**
248 * Add dance
249 *
250 * @param Dance $dance
251 *
252 * @return User
253 */
254 public function addDance(Dance $dance): User {
255 $this->dances[] = $dance;
256
257 return $this;
258 }
259
260 /**
261 * Remove dance
262 *
263 * @param Dance $dance
264 *
265 * @return bool
266 */
267 public function removeDance(Dance $dance): bool {
268 return $this->dances->removeElement($dance);
269 }
270
271 /**
272 * Get dances
273 *
274 * @return \Doctrine\Common\Collections\Collection
275 */
276 public function getDances(): Collection {
277 return $this->dances;
278 }
279
280 /**
281 * Add location
282 *
283 * @param Location $location
284 *
285 * @return User
286 */
287 public function addLocation(Location $location): User {
288 $this->locations[] = $location;
289
290 return $this;
291 }
292
293 /**
294 * Remove location
295 *
296 * @param Location $location
297 */
298 public function removeLocation(Location $location): bool {
299 return $this->locations->removeElement($location);
300 }
301
302 /**
303 * Get locations
304 *
305 * @return \Doctrine\Common\Collections\Collection
306 */
307 public function getLocations(): Collection {
308 return $this->locations;
309 }
310
311 /**
312 * Add snippet
313 *
314 * @param Snippet $snippet
315 *
316 * @return User
317 */
318 public function addSnippet(Snippet $snippet): User {
319 $this->snippets[] = $snippet;
320
321 return $this;
322 }
323
324 /**
325 * Remove snippet
326 *
327 * @param Snippet $snippet
328 */
329 public function removeSnippet(Snippet $snippet): bool {
330 return $this->snippets->removeElement($snippet);
331 }
332
333 /**
334 * Get snippets
335 *
336 * @return \Doctrine\Common\Collections\Collection
337 */
338 public function getSnippets(): Collection {
339 return $this->snippets;
340 }
341
342 /**
343 * Add subscriber
344 *
345 * @param User $subscriber
346 *
347 * @return User
348 */
349 public function addSubscriber(User $subscriber): User {
350 //Add from owning side
351 $subscriber->addSubscription($this);
352
353 $this->subscribers[] = $subscriber;
354
355 return $this;
356 }
357
358 /**
359 * Remove subscriber
360 *
361 * @param User $subscriber
362 */
363 public function removeSubscriber(User $subscriber): bool {
364 if (!$this->subscriptions->contains($subscriber)) {
365 return true;
366 }
367
368 //Remove from owning side
369 $subscriber->removeSubscription($this);
370
371 return $this->subscribers->removeElement($subscriber);
372 }
373
374 /**
375 * Get subscribers
376 *
377 * @return \Doctrine\Common\Collections\Collection
378 */
379 public function getSubscribers(): Collection {
380 return $this->subscribers;
381 }
382
383 /**
384 * Add subscription
385 *
386 * @param User $subscription
387 *
388 * @return User
389 */
390 public function addSubscription(User $subscription): User {
391 $this->subscriptions[] = $subscription;
392
393 return $this;
394 }
395
396 /**
397 * Remove subscription
398 *
399 * @param User $subscription
400 */
401 public function removeSubscription(User $subscription): bool {
402 return $this->subscriptions->removeElement($subscription);
403 }
404
405 /**
406 * Get subscriptions
407 *
408 * @return \Doctrine\Common\Collections\Collection
409 */
410 public function getSubscriptions(): Collection {
411 return $this->subscriptions;
412 }
413
414 /**
415 * Add google token
416 *
417 * @param GoogleToken $googleToken
418 *
419 * @return User
420 */
421 public function addGoogleToken(GoogleToken $googleToken): User {
422 $this->googleTokens[] = $googleToken;
423
424 return $this;
425 }
426
427 /**
428 * Remove google token
429 *
430 * @param GoogleToken $googleToken
431 */
432 public function removeGoogleToken(GoogleToken $googleToken): bool {
433 return $this->googleTokens->removeElement($googleToken);
434 }
435
436 /**
437 * Get googleTokens
438 *
439 * @return \Doctrine\Common\Collections\Collection
440 */
441 public function getGoogleTokens(): Collection {
442 return $this->googleTokens;
443 }
444 }