|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Entity\Infrasctucture; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\Band; |
|
6
|
|
|
use AppBundle\Entity\BandMember; |
|
7
|
|
|
use AppBundle\Entity\Organizer; |
|
8
|
|
|
use AppBundle\Entity\OrganizerMember; |
|
9
|
|
|
use AppBundle\Entity\User; |
|
10
|
|
|
use AppBundle\Exception\UnsupportedEntityException; |
|
11
|
|
|
use AppBundle\Service\HashGenerator; |
|
12
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
13
|
|
|
use Doctrine\Common\Collections\Collection; |
|
14
|
|
|
use JMS\Serializer\Annotation\Accessor; |
|
15
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
16
|
|
|
use JMS\Serializer\Annotation\Type as SerializerType; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Vehsamrak |
|
20
|
|
|
* @ORM\MappedSuperclass |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class Ambassador |
|
23
|
|
|
{ |
|
24
|
|
|
use CreatorLoginTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
* @ORM\Id |
|
29
|
|
|
* @ORM\Column(name="id", type="string", length=8, unique=true) |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $id; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
* @ORM\Column(name="name", type="string", length=255, unique=true) |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $name; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var \DateTime |
|
41
|
|
|
* @ORM\Column(name="registration_date", type="datetime") |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $registrationDate; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string |
|
47
|
|
|
* @ORM\Column(name="description", type="text", nullable=true) |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $description; |
|
50
|
|
|
|
|
51
|
|
|
/** @var ArrayCollection */ |
|
52
|
|
|
protected $members; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var User |
|
56
|
|
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="createdBands") |
|
57
|
|
|
* @ORM\JoinColumn(name="creator", referencedColumnName="login") |
|
58
|
|
|
* @Accessor(getter="getCreatorLogin") |
|
59
|
|
|
* @SerializerType("string") |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $creator; |
|
62
|
|
|
|
|
63
|
5 |
|
public function __construct( |
|
64
|
|
|
string $name, |
|
65
|
|
|
User $creator, |
|
66
|
|
|
string $description = null, |
|
67
|
|
|
HashGenerator $hashGenerator = null |
|
68
|
|
|
) |
|
69
|
|
|
{ |
|
70
|
|
|
/** @var HashGenerator $hashGenerator */ |
|
71
|
5 |
|
$hashGenerator = $hashGenerator ?: new HashGenerator(); |
|
72
|
5 |
|
$this->id = $hashGenerator->generate(); |
|
73
|
5 |
|
$this->registrationDate = new \DateTime(); |
|
74
|
5 |
|
$this->name = $name; |
|
75
|
5 |
|
$this->description = $description; |
|
76
|
5 |
|
$this->members = new ArrayCollection(); |
|
77
|
5 |
|
$this->creator = $creator; |
|
78
|
5 |
|
} |
|
79
|
|
|
|
|
80
|
3 |
|
public function getId(): string |
|
81
|
|
|
{ |
|
82
|
3 |
|
return $this->id; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return Collection|AmbassadorMember[] |
|
87
|
|
|
*/ |
|
88
|
11 |
|
public function getMembers(): Collection |
|
89
|
|
|
{ |
|
90
|
11 |
|
return $this->members; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
4 |
|
public function addMember(AmbassadorMember $ambassadorMember) |
|
94
|
|
|
{ |
|
95
|
4 |
|
$this->members->add($ambassadorMember); |
|
96
|
4 |
|
} |
|
97
|
|
|
|
|
98
|
1 |
|
public function removeMember(AmbassadorMember $ambassadorMember) |
|
99
|
|
|
{ |
|
100
|
1 |
|
$this->members->removeElement($ambassadorMember); |
|
101
|
1 |
|
} |
|
102
|
|
|
|
|
103
|
1 |
|
public function setName(string $name) |
|
104
|
|
|
{ |
|
105
|
1 |
|
$this->name = $name; |
|
106
|
1 |
|
} |
|
107
|
|
|
|
|
108
|
1 |
|
public function setDescription(string $description) |
|
109
|
|
|
{ |
|
110
|
1 |
|
$this->description = $description; |
|
111
|
1 |
|
} |
|
112
|
|
|
|
|
113
|
11 |
|
public function getCreator(): User |
|
114
|
|
|
{ |
|
115
|
11 |
|
return $this->creator; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
6 |
|
public function getMemberClass(): string |
|
119
|
|
|
{ |
|
120
|
6 |
|
if ($this instanceof Band) { |
|
121
|
3 |
|
return BandMember::class; |
|
122
|
|
|
} elseif ($this instanceof Organizer) { |
|
123
|
3 |
|
return OrganizerMember::class; |
|
124
|
|
|
} else { |
|
125
|
|
|
throw new UnsupportedEntityException(); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|