Completed
Pull Request — master (#142)
by Ihor
15:10
created

Ticket::getSetDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

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
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
    protected $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
    protected $performanceEvent;
94
95
    /**
96
     * @var CustomerOrder
97
     *
98
     * @ORM\ManyToOne(targetEntity="CustomerOrder", inversedBy="tickets")
99
     * @ORM\Column(name="customer_order_id", type="integer", nullable=true)
100
     */
101
    protected $customerOrder;
102
103
    /**
104
     * @var string
105
     * @Assert\Choice(callback="getStatuses")
106
     * @ORM\Column(name="status", type="string", length=15)
107
     * @Serializer\Groups({"get_ticket"})
108
     * @Type("string")
109
     * @Expose()
110
     */
111
    protected $status;
112
113
    /**
114
     * Ticket constructor.
115
     *
116
     * @param Seat $seat
117
     * @param PerformanceEvent $performanceEvent
118
     * @param int $ticketPrice
119
     * @param \DateTime $seriesDate
120
     * @param string $seriesNumber
121
     */
122
    public function __construct(
123
        Seat $seat,
124
        PerformanceEvent $performanceEvent,
125
        int $ticketPrice,
126
        \DateTime $seriesDate,
127
        string $seriesNumber
128
    ) {
129
        $this->id = Uuid::uuid4();
130
        $this->status = self::STATUS_FREE;
131
        $this->seat = $seat;
132
        $this->performanceEvent = $performanceEvent;
133
        $this->price = $ticketPrice;
134
        $this->seriesDate = $seriesDate;
135
        $this->seriesNumber = $seriesNumber;
136
    }
137
138
    /**
139
     * @return Uuid
140
     */
141
    public function getId(): Uuid
142
    {
143
        return $this->id;
144
    }
145
146
    /**
147
     * @return int
148
     */
149
    public function getPrice(): int
150
    {
151
        return $this->price;
152
    }
153
154
    /**
155
     * @return Seat
156
     */
157
    public function getSeat(): Seat
158
    {
159
        return $this->seat;
160
    }
161
162
    /**
163
     * @return PerformanceEvent
164
     */
165
    public function getPerformanceEvent(): PerformanceEvent
166
    {
167
        return $this->performanceEvent;
168
    }
169
170
    /**
171
     * Get PerformanceEvent Id.
172
     *
173
     * @Serializer\VirtualProperty()
174
     * @Serializer\SerializedName("performance_event_id")
175
     * @Type("integer")
176
     * @Serializer\Groups({"get_ticket"})
177
     *
178
     * @return integer
179
     */
180
    public function getPerformanceEventId(): int
181
    {
182
        return $this->performanceEvent->getId();
183
    }
184
185
    /**
186
     * Get PriceCategory Id.
187
     *
188
     * @Serializer\VirtualProperty()
189
     * @Serializer\SerializedName("price_category_id")
190
     * @Type("integer")
191
     * @Serializer\Groups({"get_ticket"})
192
     *
193
     * @return integer
194
     */
195
    public function getPriceCategoryId(): int
196
    {
197
        //TODO
198
        return 0;
199
    }
200
201
    /**
202
     * @return string
203
     */
204
    public function getStatus(): string
205
    {
206
        return $this->status;
207
    }
208
209
    /**
210
     * @param String $status
211
     *
212
     * @return Ticket
213
     */
214
    public function setStatus($status)
215
    {
216
        $this->status = $status;
217
218
        return $this;
219
    }
220
221
    /**
222
     * @return array
223
     */
224
    public static function getStatuses(): array
225
    {
226
        return [
227
            self::STATUS_FREE,
228
            self::STATUS_BOOKED,
229
            self::STATUS_PAID,
230
            self::STATUS_OFFLINE,
231
        ];
232
    }
233
234
    /**
235
     * @return \DateTime
236
     */
237
    public function getSeriesDate(): \DateTime
238
    {
239
        return $this->seriesDate;
240
    }
241
242
    /**
243
     * @return string
244
     */
245
    public function getSeriesNumber(): string
246
    {
247
        return $this->seriesNumber;
248
    }
249
}
250