Completed
Pull Request — master (#151)
by Ihor
13:44
created

Ticket::getPriceCategory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use AppBundle\Traits\TimestampableTrait;
6
use Doctrine\ORM\Mapping as ORM;
7
use JMS\Serializer\Annotation as Serializer;
8
use JMS\Serializer\Annotation\ExclusionPolicy;
9
use JMS\Serializer\Annotation\Expose;
10
use JMS\Serializer\Annotation\Type;
11
use Ramsey\Uuid\Uuid;
12
use Symfony\Component\Validator\Constraints as Assert;
13
14
/**
15
 * @ORM\Table(name="ticket")
16
 * @ORM\Entity(repositoryClass="AppBundle\Repository\TicketRepository")
17
 * @ExclusionPolicy("all")
18
 */
19
class Ticket
20
{
21
    use TimestampableTrait;
22
23
    const STATUS_FREE    = 'free';
24
    const STATUS_BOOKED  = 'booked';
25
    const STATUS_PAID    = 'paid';
26
    const STATUS_OFFLINE = 'offline';
27
28
    /**
29
     * @var Uuid
30
     *
31
     * @ORM\Column(name="id", type="uuid_binary")
32
     * @ORM\Id
33
     * @ORM\GeneratedValue(strategy="UUID")
34
     *
35
     * @Serializer\Groups({"get_ticket"})
36
     * @Type("string")
37
     * @Expose
38
     */
39
    private $id;
40
41
    /**
42
     * @var \DateTime
43
     * @Assert\DateTime()
44
     * @ORM\Column(name="series_date", type="datetime", nullable=false)
45
     *
46
     * @Serializer\Groups({"get_ticket"})
47
     * @Type("DateTime")
48
     * @Expose
49
     */
50
    private $seriesDate;
51
52
    /**
53
     * @var string
54
     * @Assert\NotBlank()
55
     * @ORM\Column(name="series_number", type="string", length=10, nullable=false)
56
     *
57
     * @Serializer\Groups({"get_ticket"})
58
     * @Type("string")
59
     * @Expose
60
     */
61
    private $seriesNumber;
62
63
    /**
64
     * @var integer
65
     * @Assert\NotBlank()
66
     * @ORM\Column(type="integer", nullable=false)
67
     *
68
     * @Serializer\Groups({"get_ticket"})
69
     * @Type("integer")
70
     * @Expose
71
     */
72
    private $price;
73
74
    /**
75
     * @var Seat
76
     *
77
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Seat", fetch="EAGER")
78
     * @ORM\JoinColumn(name="seat_id", referencedColumnName="id", nullable=false)
79
     *
80
     * @Serializer\Groups({"get_ticket"})
81
     * @Type("AppBundle\Entity\Seat")
82
     * @Expose()
83
     */
84
    private $seat;
85
86
    /**
87
     * @var PerformanceEvent
88
     *
89
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\PerformanceEvent",  fetch="EAGER")
90
     * @ORM\JoinColumn(name="performance_event_id", referencedColumnName="id", nullable=false)
91
     * @Type("AppBundle\Entity\PerformanceEvent")
92
     */
93
    private $performanceEvent;
94
95
    /**
96
     * @var UserOrder
97
     *
98
     * @ORM\ManyToOne(targetEntity="UserOrder", inversedBy="tickets")
99
     * @ORM\Column(name="user_order_id", type="integer", nullable=true)
100
     */
101
    protected $userOrder;
102
103
    /**
104
     * @var PriceCategory
105
     *
106
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\PriceCategory", fetch="EAGER")
107
     * @ORM\JoinColumn(name="price_category_id", referencedColumnName="id", nullable=false)
108
     *
109
     * @Type("AppBundle\Entity\PriceCategory")
110
     * @Expose()
111
     */
112
    private $priceCategory;
113
114
    /**
115
     * @var string
116
     * @Assert\Choice(callback="getStatuses")
117
     * @ORM\Column(name="status", type="string", length=15)
118
     * @Serializer\Groups({"get_ticket"})
119
     * @Type("string")
120
     * @Expose()
121
     */
122
    private $status;
123
124
    /**
125
     * Ticket constructor.
126
     *
127
     * @param Seat $seat
128
     * @param PerformanceEvent $performanceEvent
129
     * @param PriceCategory $priceCategory
130
     * @param int $ticketPrice
131
     * @param \DateTime $seriesDate
132
     * @param string $seriesNumber
133
     * @param $status string
134
     */
135
    public function __construct(
136
        Seat $seat,
137
        PerformanceEvent $performanceEvent,
138
        PriceCategory $priceCategory,
139
        int $ticketPrice,
140
        \DateTime $seriesDate,
141 3
        string $seriesNumber,
142
        $status = self::STATUS_FREE
143 3
    ) {
144
        $this->id = Uuid::uuid4();
145
        $this->seat = $seat;
146
        $this->performanceEvent = $performanceEvent;
147
        $this->priceCategory = $priceCategory;
148
        $this->price = $ticketPrice;
149
        $this->seriesDate = $seriesDate;
150
        $this->seriesNumber = $seriesNumber;
151
        $this->status = $status;
152
    }
153
154
    /**
155
     * @return Uuid
156
     */
157
    public function getId(): Uuid
158
    {
159
        return $this->id;
160
    }
161
162
    /**
163
     * @return int
164
     */
165
    public function getPrice(): int
166
    {
167
        return $this->price;
168
    }
169
170
    /**
171
     * @return Seat
172
     */
173
    public function getSeat(): Seat
174
    {
175
        return $this->seat;
176
    }
177
178
    /**
179
     * @return PerformanceEvent
180 2
     */
181
    public function getPerformanceEvent(): PerformanceEvent
182 2
    {
183
        return $this->performanceEvent;
184
    }
185
186
    /**
187
     * Get PerformanceEvent Id.
188
     *
189
     * @Serializer\VirtualProperty()
190
     * @Serializer\SerializedName("performance_event_id")
191
     * @Type("integer")
192
     * @Serializer\Groups({"get_ticket"})
193
     *
194
     * @return integer
195 2
     */
196
    public function getPerformanceEventId(): int
197
    {
198 2
        return $this->performanceEvent->getId();
199
    }
200
201
    /**
202
     * Get PriceCategory Id.
203
     *
204
     * @Serializer\VirtualProperty()
205
     * @Serializer\SerializedName("price_category_id")
206
     * @Type("integer")
207
     * @Serializer\Groups({"get_ticket"})
208
     *
209
     * @return integer
210
     */
211
    public function getPriceCategoryId(): int
212
    {
213
        return empty($this->priceCategory) ? 0 : $this->priceCategory->getId();
214 1
    }
215
216 1
    /**
217
     * @return string
218 1
     */
219
    public function getStatus(): string
220
    {
221
        return $this->status;
222
    }
223
224
    /**
225
     * @param String $status
226
     *
227
     * @return Ticket
228
     */
229
    public function setStatus($status)
230
    {
231
        $this->status = $status;
232
233
        return $this;
234
    }
235
236
    /**
237
     * @return array
238
     */
239
    public static function getStatuses(): array
240
    {
241
        return [
242
            self::STATUS_FREE,
243
            self::STATUS_BOOKED,
244
            self::STATUS_PAID,
245
            self::STATUS_OFFLINE,
246
        ];
247
    }
248
249
    /**
250
     * @return \DateTime
251
     */
252
    public function getSeriesDate(): \DateTime
253
    {
254
        return $this->seriesDate;
255
    }
256
257
    /**
258
     * @return string
259
     */
260
    public function getSeriesNumber(): string
261
    {
262
        return $this->seriesNumber;
263
    }
264
265
    /**
266
     * @return PriceCategory
267
     */
268
    public function getPriceCategory(): PriceCategory
269
    {
270
        return $this->priceCategory;
271
    }
272
}
273