Completed
Push — master ( 4f5e08...58c386 )
by Adrien
05:49
created

Booking::getEndDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\DBAL\Types\BookingStatusType;
8
use Cake\Chronos\Chronos;
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\Common\Collections\Collection;
11
use Doctrine\ORM\Mapping as ORM;
12
use GraphQL\Doctrine\Annotation as API;
13
14
/**
15
 * A booking linking a user and several bookables
16
 *
17
 * @ORM\Entity(repositoryClass="Application\Repository\BookingRepository")
18
 */
19
class Booking extends AbstractModel
20
{
21
    /**
22
     * @var string
23
     *
24
     * @ORM\Column(type="BookingStatus", length=10, options={"default" = BookingStatusType::APPLICATION})
25
     */
26
    private $status = BookingStatusType::APPLICATION;
27
28
    /**
29
     * @var int
30
     * @ORM\Column(type="integer", options={"unsigned" = true, "default" = 1})
31
     */
32
    private $participantCount = 1;
33
34
    /**
35
     * @var string
36
     *
37
     * @ORM\Column(type="string", length=50, options={"default" = ""})
38
     */
39
    private $destination = '';
40
41
    /**
42
     * @var string
43
     *
44
     * @ORM\Column(type="text", length=65535, options={"default" = ""})
45
     */
46
    private $startComment = '';
47
48
    /**
49
     * @var string
50
     *
51
     * @ORM\Column(type="text", length=65535, options={"default" = ""})
52
     */
53
    private $endComment = '';
54
55
    /**
56
     * @var Chronos
57
     *
58
     * @ORM\Column(type="datetime")
59
     */
60
    private $startDate;
61
62
    /**
63
     * @var Chronos
64
     *
65
     * @ORM\Column(type="datetime", nullable=true)
66
     */
67
    private $endDate;
68
69
    /**
70
     * @var string
71
     *
72
     * @ORM\Column(type="string", length=50, options={"default" = ""})
73
     */
74
    private $estimatedEndDate = '';
75
76
    /**
77
     * @var User
78
     *
79
     * @ORM\ManyToOne(targetEntity="User", inversedBy="bookings")
80
     * @ORM\JoinColumns({
81
     *     @ORM\JoinColumn(onDelete="SET NULL")
82
     * })
83
     */
84
    private $responsible;
85
86
    /**
87
     * @var Collection
88
     *
89
     * @ORM\ManyToMany(targetEntity="Bookable", inversedBy="bookings")
90
     */
91
    private $bookables;
92
93
    /**
94
     * Constructor
95
     */
96 2
    public function __construct()
97
    {
98 2
        $this->bookables = new ArrayCollection();
99 2
    }
100
101
    /**
102
     * Set responsible
103
     *
104
     * @param null|User $responsible
105
     */
106 1
    public function setResponsible(?User $responsible): void
107
    {
108 1
        if ($this->responsible) {
109 1
            $this->responsible->bookingRemoved($this);
110
        }
111 1
        $this->responsible = $responsible;
112 1
        if ($this->responsible) {
113 1
            $this->responsible->bookingAdded($this);
114
        }
115 1
    }
116
117
    /**
118
     * Get responsible
119
     *
120
     * @return null|User
121
     */
122 1
    public function getResponsible(): ?User
123
    {
124 1
        return $this->responsible;
125
    }
126
127
    /**
128
     * Total count of participant, at least 1.
129
     *
130
     * @return int
131
     */
132
    public function getParticipantCount(): int
133
    {
134
        return $this->participantCount;
135
    }
136
137
    /**
138
     * @param int $participantCount
139
     */
140
    public function setParticipantCount(int $participantCount): void
141
    {
142
        $this->participantCount = $participantCount;
143
    }
144
145
    /**
146
     * @return string
147
     */
148
    public function getDestination(): string
149
    {
150
        return $this->destination;
151
    }
152
153
    /**
154
     * @param string $destination
155
     */
156
    public function setDestination(string $destination): void
157
    {
158
        $this->destination = $destination;
159
    }
160
161
    /**
162
     * @return string
163
     */
164
    public function getStartComment(): string
165
    {
166
        return $this->startComment;
167
    }
168
169
    /**
170
     * @param string $startComment
171
     */
172
    public function setStartComment(string $startComment): void
173
    {
174
        $this->startComment = $startComment;
175
    }
176
177
    /**
178
     * @return string
179
     */
180
    public function getEndComment(): string
181
    {
182
        return $this->endComment;
183
    }
184
185
    /**
186
     * @param string $endComment
187
     */
188
    public function setEndComment(string $endComment): void
189
    {
190
        $this->endComment = $endComment;
191
    }
192
193
    /**
194
     * @return Chronos
195
     */
196
    public function getStartDate(): Chronos
197
    {
198
        return $this->startDate;
199
    }
200
201
    /**
202
     * @param Chronos $startDate
203
     */
204
    public function setStartDate(Chronos $startDate): void
205
    {
206
        $this->startDate = $startDate;
207
    }
208
209
    /**
210
     * @return null|Chronos
211
     */
212
    public function getEndDate(): ?Chronos
213
    {
214
        return $this->endDate;
215
    }
216
217
    /**
218
     * @param Chronos $endDate
219
     */
220
    public function setEndDate(Chronos $endDate): void
221
    {
222
        $this->endDate = $endDate;
223
    }
224
225
    /**
226
     * @return string
227
     */
228
    public function getEstimatedEndDate(): string
229
    {
230
        return $this->estimatedEndDate;
231
    }
232
233
    /**
234
     * @param string $estimatedEndDate
235
     */
236
    public function setEstimatedEndDate(string $estimatedEndDate): void
237
    {
238
        $this->estimatedEndDate = $estimatedEndDate;
239
    }
240
241
    /**
242
     * @return Collection
243
     */
244 1
    public function getBookables(): Collection
245
    {
246 1
        return $this->bookables;
247
    }
248
249
    /**
250
     * Add bookable
251
     *
252
     * @param Bookable $bookable
253
     */
254 1
    public function addBookable(Bookable $bookable): void
255
    {
256 1
        if (!$this->bookables->contains($bookable)) {
257 1
            $this->bookables->add($bookable);
258 1
            $bookable->bookingAdded($this);
259
        }
260 1
    }
261
262
    /**
263
     * Remove bookable
264
     *
265
     * @param Bookable $bookable
266
     */
267 1
    public function removeBookable(Bookable $bookable): void
268
    {
269 1
        $this->bookables->removeElement($bookable);
270 1
        $bookable->bookingRemoved($this);
271 1
    }
272
273
    /**
274
     * @API\Field(type="BookingStatus")
275
     *
276
     * @return string
277
     */
278
    public function getStatus(): string
279
    {
280
        return $this->status;
281
    }
282
283
    /**
284
     * @API\Input(type="BookingStatus")
285
     *
286
     * @param string $status
287
     */
288
    public function setStatus(string $status): void
289
    {
290
        $this->status = $status;
291
    }
292
}
293