1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the TheAlternativeZurich/events project. |
5
|
|
|
* |
6
|
|
|
* (c) Florian Moser <[email protected]> |
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 App\Entity; |
13
|
|
|
|
14
|
|
|
use App\Entity\Base\BaseEntity; |
15
|
|
|
use App\Entity\Traits\ContactInformationTrait; |
16
|
|
|
use App\Entity\Traits\IdTrait; |
17
|
|
|
use App\Entity\Traits\TimeTrait; |
18
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
19
|
|
|
use Doctrine\ORM\Mapping as ORM; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\RegistrationRepository") |
23
|
|
|
* @ORM\HasLifecycleCallbacks |
24
|
|
|
*/ |
25
|
|
|
class Registration extends BaseEntity |
26
|
|
|
{ |
27
|
|
|
use IdTrait; |
28
|
|
|
use TimeTrait; |
29
|
|
|
use ContactInformationTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
* |
34
|
|
|
* @ORM\Column(type="boolean") |
35
|
|
|
*/ |
36
|
|
|
private $isOrganizer = false; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var int |
40
|
|
|
* |
41
|
|
|
* @ORM\Column(type="integer") |
42
|
|
|
*/ |
43
|
|
|
private $number; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var Event |
47
|
|
|
* |
48
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Event", inversedBy="registrations") |
49
|
|
|
*/ |
50
|
|
|
private $event; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var User |
54
|
|
|
* |
55
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="registrations") |
56
|
|
|
*/ |
57
|
|
|
private $user; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var Participation[]|ArrayCollection |
61
|
|
|
* |
62
|
|
|
* @ORM\OneToMany (targetEntity="App\Entity\Participation", mappedBy="registration") |
63
|
|
|
*/ |
64
|
|
|
private $participations; |
65
|
|
|
|
66
|
|
|
public function __construct() |
67
|
|
|
{ |
68
|
|
|
$this->participations = new ArrayCollection(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public static function createFromUser(Event $event, User $user, bool $isOrganizer = false) |
72
|
|
|
{ |
73
|
|
|
$registration = new Registration(); |
74
|
|
|
$registration->event = $event; |
75
|
|
|
$registration->user = $user; |
76
|
|
|
$registration->isOrganizer = $isOrganizer; |
77
|
|
|
$registration->fromOtherContactInformation($user); |
78
|
|
|
|
79
|
|
|
return $registration; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function setNumber(int $number) |
83
|
|
|
{ |
84
|
|
|
$this->number = $number; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getIsOrganizer(): bool |
88
|
|
|
{ |
89
|
|
|
return $this->isOrganizer; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function setIsOrganizer(bool $isOrganizer): void |
93
|
|
|
{ |
94
|
|
|
$this->isOrganizer = $isOrganizer; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return Event |
99
|
|
|
*/ |
100
|
|
|
public function getEvent() |
101
|
|
|
{ |
102
|
|
|
return $this->event; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return User |
107
|
|
|
*/ |
108
|
|
|
public function getUser() |
109
|
|
|
{ |
110
|
|
|
return $this->user; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getNumber(): int |
114
|
|
|
{ |
115
|
|
|
return $this->number; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function canDeregister(): bool |
119
|
|
|
{ |
120
|
|
|
if ($this->participations->count() > 0) { |
121
|
|
|
return false; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return $this->event->isRegistrationOpen(); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|