1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Orm\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\Column; |
8
|
|
|
use Doctrine\ORM\Mapping\Entity; |
9
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
10
|
|
|
use Doctrine\ORM\Mapping\Id; |
11
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
12
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
13
|
|
|
use Doctrine\ORM\Mapping\Table; |
14
|
|
|
use Stu\Component\Crew\CrewTypeEnum; |
15
|
|
|
use Stu\Orm\Attribute\TruncateOnGameReset; |
16
|
|
|
use Stu\Orm\Repository\CrewRepository; |
17
|
|
|
|
18
|
|
|
#[Table(name: 'stu_crew')] |
19
|
|
|
#[Entity(repositoryClass: CrewRepository::class)] |
20
|
|
|
#[TruncateOnGameReset] |
21
|
|
|
class Crew |
22
|
|
|
{ |
23
|
|
|
public const int CREW_GENDER_MALE = 1; |
|
|
|
|
24
|
|
|
public const int CREW_GENDER_FEMALE = 2; |
25
|
|
|
|
26
|
|
|
#[Id] |
27
|
|
|
#[Column(type: 'integer')] |
28
|
|
|
#[GeneratedValue(strategy: 'IDENTITY')] |
29
|
|
|
private int $id; |
30
|
|
|
|
31
|
|
|
#[Column(type: 'smallint', enumType: CrewTypeEnum::class)] |
32
|
|
|
private CrewTypeEnum $type = CrewTypeEnum::CREWMAN; |
33
|
|
|
|
34
|
|
|
#[Column(type: 'smallint')] |
35
|
|
|
private int $gender = 0; |
36
|
|
|
|
37
|
|
|
#[Column(type: 'string')] |
38
|
|
|
private string $name = ''; |
39
|
|
|
|
40
|
|
|
#[Column(type: 'integer')] |
41
|
|
|
private int $user_id = 0; |
42
|
|
|
|
43
|
|
|
#[Column(type: 'integer')] |
44
|
|
|
private int $race_id = 0; |
45
|
|
|
|
46
|
|
|
#[ManyToOne(targetEntity: CrewRace::class)] |
47
|
|
|
#[JoinColumn(name: 'race_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
48
|
|
|
private CrewRace $race; |
49
|
|
|
|
50
|
|
|
#[ManyToOne(targetEntity: User::class)] |
51
|
|
|
#[JoinColumn(name: 'user_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
52
|
|
|
private User $user; |
53
|
|
|
|
54
|
1 |
|
public function getId(): int |
55
|
|
|
{ |
56
|
1 |
|
return $this->id; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
public function getType(): CrewTypeEnum |
60
|
|
|
{ |
61
|
1 |
|
return $this->type; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setType(CrewTypeEnum $type): Crew |
65
|
|
|
{ |
66
|
|
|
$this->type = $type; |
67
|
|
|
|
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function getGender(): int |
72
|
|
|
{ |
73
|
1 |
|
return $this->gender; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setGender(int $gender): Crew |
77
|
|
|
{ |
78
|
|
|
$this->gender = $gender; |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
1 |
|
public function getName(): string |
84
|
|
|
{ |
85
|
1 |
|
return $this->name; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function setName(string $name): Crew |
89
|
|
|
{ |
90
|
|
|
$this->name = $name; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getUserId(): int |
96
|
|
|
{ |
97
|
|
|
return $this->user_id; |
98
|
|
|
} |
99
|
|
|
|
100
|
5 |
|
public function getUser(): User |
101
|
|
|
{ |
102
|
5 |
|
return $this->user; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setUser(User $user): Crew |
106
|
|
|
{ |
107
|
|
|
$this->user = $user; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getRaceId(): int |
113
|
|
|
{ |
114
|
|
|
return $this->race_id; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function setRaceId(int $raceId): Crew |
118
|
|
|
{ |
119
|
|
|
$this->race_id = $raceId; |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
1 |
|
public function getGenderShort(): string |
125
|
|
|
{ |
126
|
1 |
|
if ($this->getGender() == self::CREW_GENDER_MALE) { |
127
|
1 |
|
return 'm'; |
128
|
|
|
} |
129
|
1 |
|
return 'w'; |
130
|
|
|
} |
131
|
|
|
|
132
|
1 |
|
public function getRace(): CrewRace |
133
|
|
|
{ |
134
|
1 |
|
return $this->race; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function setRace(CrewRace $crewRace): Crew |
138
|
|
|
{ |
139
|
|
|
$this->race = $crewRace; |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function __toString(): string |
145
|
|
|
{ |
146
|
|
|
return sprintf('crewId: %d', $this->getId()); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|