1
|
|
|
<?php |
2
|
|
|
namespace PlaygroundGame\Entity; |
3
|
|
|
|
4
|
|
|
use Doctrine\ORM\Mapping as ORM; |
5
|
|
|
use Doctrine\ORM\Mapping\HasLifecycleCallbacks; |
6
|
|
|
use Doctrine\ORM\Mapping\PrePersist; |
7
|
|
|
use Doctrine\ORM\Mapping\PreUpdate; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @ORM\Entity @HasLifecycleCallbacks |
11
|
|
|
* @ORM\Table(name="game_invitation", uniqueConstraints={ |
12
|
|
|
* @ORM\UniqueConstraint(name="requestkey_game", columns={"request_key", "game_id"}) |
13
|
|
|
* }) |
14
|
|
|
*/ |
15
|
|
|
class Invitation implements \JsonSerializable |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @ORM\ManyToOne(targetEntity="Game", cascade={"persist","remove"}) |
19
|
|
|
* @ORM\JoinColumn(name="game_id", referencedColumnName="id", onDelete="CASCADE") |
20
|
|
|
**/ |
21
|
|
|
protected $game; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ORM\Id |
25
|
|
|
* @ORM\Column(type="integer"); |
26
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
27
|
|
|
*/ |
28
|
|
|
protected $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
* @ORM\Column(name="request_key", type="string", length=255, nullable=false) |
33
|
|
|
*/ |
34
|
|
|
protected $requestKey; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @ORM\ManyToOne(targetEntity="PlaygroundUser\Entity\User") |
38
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id") |
39
|
|
|
**/ |
40
|
|
|
protected $user; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The user who invite (it can be the system who's the host. This attribute will be null then) |
44
|
|
|
* @ORM\ManyToOne(targetEntity="PlaygroundUser\Entity\User", cascade={"persist","remove"}) |
45
|
|
|
* @ORM\JoinColumn(name="host_id", referencedColumnName="user_id", onDelete="CASCADE") |
46
|
|
|
**/ |
47
|
|
|
protected $host; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
51
|
|
|
*/ |
52
|
|
|
protected $createdAt; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @ORM\Column(name="updated_at", type="datetime") |
56
|
|
|
*/ |
57
|
|
|
protected $updatedAt; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @PrePersist |
61
|
|
|
*/ |
62
|
|
|
public function createChrono() |
63
|
|
|
{ |
64
|
|
|
$this->createdAt = new \DateTime("now"); |
65
|
|
|
$this->updatedAt = new \DateTime("now"); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @PreUpdate |
70
|
|
|
*/ |
71
|
|
|
public function updateChrono() |
72
|
|
|
{ |
73
|
|
|
$this->updatedAt = new \DateTime("now"); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setId($id) |
77
|
|
|
{ |
78
|
|
|
$this->id = $id; |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getId() |
84
|
|
|
{ |
85
|
|
|
return $this->id; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function setRequestKey($key) |
89
|
|
|
{ |
90
|
|
|
$this->requestKey = $key; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getRequestKey() |
96
|
|
|
{ |
97
|
|
|
return $this->requestKey; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function setUser($user) |
101
|
|
|
{ |
102
|
|
|
$this->user = $user; |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getUser() |
108
|
|
|
{ |
109
|
|
|
return $this->user; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function setHost($host) |
113
|
|
|
{ |
114
|
|
|
$this->host = $host; |
115
|
|
|
|
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getHost() |
120
|
|
|
{ |
121
|
|
|
return $this->host; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return the unknown_type |
126
|
|
|
*/ |
127
|
|
|
public function getGame() |
128
|
|
|
{ |
129
|
|
|
return $this->game; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param unknown_type $game |
134
|
|
|
*/ |
135
|
|
|
public function setGame($game) |
136
|
|
|
{ |
137
|
|
|
$this->game = $game; |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Convert the object to an array. |
144
|
|
|
* |
145
|
|
|
* @return array |
146
|
|
|
*/ |
147
|
|
|
public function getArrayCopy() |
148
|
|
|
{ |
149
|
|
|
$obj_vars = get_object_vars($this); |
150
|
|
|
|
151
|
|
|
return $obj_vars; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Convert the object to json. |
156
|
|
|
* |
157
|
|
|
* @return array |
158
|
|
|
*/ |
159
|
|
|
public function jsonSerialize() |
160
|
|
|
{ |
161
|
|
|
return $this->getArrayCopy(); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|