Completed
Pull Request — master (#136)
by
unknown
12:44
created

PerformanceEvent::addPriceCategory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 0
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\Common\Collections\Collection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Gedmo\Mapping\Annotation as Gedmo;
9
use Gedmo\Blameable\Traits\BlameableEntity;
10
use JMS\Serializer\Annotation as Serializer;
11
use Symfony\Component\Validator\Constraints as Assert;
12
use AppBundle\Traits\TimestampableTrait;
13
use AppBundle\Traits\DeletedByTrait;
14
use JMS\Serializer\Annotation\ExclusionPolicy;
15
use JMS\Serializer\Annotation\Expose;
16
use JMS\Serializer\Annotation\Type;
17
use JMS\Serializer\Annotation\Accessor;
18
use AppBundle\Validator\TwoPerformanceEventsPerDay;
19
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
20
use Sonata\TranslationBundle\Model\Gedmo\AbstractPersonalTranslatable;
21
22
/**
23
 * @ORM\Table(name="performance_schedule")
24
 * @ORM\Entity(repositoryClass="AppBundle\Repository\PerformanceEventRepository")
25
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
26
 * @ExclusionPolicy("all")
27
 * @Gedmo\TranslationEntity(class="AppBundle\Entity\Translations\PerformanceEventTranslation")
28
 * @TwoPerformanceEventsPerDay()
29
 */
30
class PerformanceEvent extends AbstractPersonalTranslatable implements TranslatableInterface
31
{
32
    use TimestampableTrait, BlameableEntity, DeletedByTrait;
33
34
    /**
35
     * @var integer
36
     *
37
     * @ORM\Column(name="id", type="integer")
38
     * @ORM\Id
39
     * @ORM\GeneratedValue(strategy="AUTO")
40
     *
41
     * @Serializer\Groups({"get_ticket"})
42
     * @Type("integer")
43
     * @Expose
44
     */
45
    private $id;
46
47
    /**
48
     * @var Performance
49
     *
50
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Performance", inversedBy="performanceEvents")
51
     *
52
     * @Serializer\Groups({"get_ticket"})
53
     * @Type("AppBundle\Entity\Performance")
54
     * @Expose
55
     */
56
    private $performance;
57
58
    /**
59
     * @var /Datetime
60
     *
61
     * @Assert\NotBlank()
62
     * @ORM\Column(type="datetime")
63
     *
64
     * @Serializer\Groups({"get_ticket"})
65
     * @Type("DateTime")
66
     * @Expose
67
     */
68
    private $dateTime;
69
70
    /**
71
     * @var Venue
72
     *
73
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Venue", inversedBy="performanceEvents")
74
     *
75
     * @Serializer\Groups({"get_ticket"})
76
     * @Type("AppBundle\Entity\Venue")
77
     * @Expose
78
     */
79
    private $venue;
80
81
    /**
82
     * @var int
83
     *
84
     * @Serializer\Groups({"get_ticket"})
85
     * @Type("integer")
86
     * @Expose
87
     * @Accessor(getter="getYear")
88
     */
89
    private $year;
90
91
    /**
92
     * @var int
93
     *
94
     * @Serializer\Groups({"get_ticket"})
95
     * @Expose
96
     * @Accessor(getter="getMonth")
97
     */
98
    private $month;
99
100
    /**
101
     * @var int
102
     *
103
     * @Serializer\Groups({"get_ticket"})
104
     * @Expose
105
     * @Accessor(getter="getDay")
106
     */
107
    private $day;
108
109
    /**
110
     * @var string
111
     *
112
     * @Serializer\Groups({"get_ticket"})
113
     * @Expose
114
     * @Accessor(getter="getTime")
115
     */
116
    private $time;
117
118
    /**
119
     * @var string
120
     * @Assert\NotBlank()
121
     * @ORM\Column(type="string", length=10,  nullable=false)
122
     *
123
     * @Type("string")
124
     * @Expose
125
     */
126
    private $setNumber;
127
128
    /**
129
     * @var ArrayCollection|Translation[]
130 4
     *
131
     * @ORM\OneToMany(
132 4
     *     targetEntity="AppBundle\Entity\Translations\PerformanceEventTranslation",
133
     *     mappedBy="object",
134 4
     *     cascade={"persist", "remove"}
135
     * )
136
     */
137
    protected $translations;
138
139
    /**
140
     * @var ArrayCollection|PriceCategory[]
141
     *
142 10
     * @Assert\Valid
143
     * @ORM\OneToMany(
144 10
     *     targetEntity="AppBundle\Entity\PriceCategory",
145
     *     mappedBy="performanceEvent",
146
     *     cascade={"persist"},
147
     *     orphanRemoval=true
148
     * )
149
     */
150
    protected $priceCategories;
151
152
    public function __construct()
153 7
    {
154
        parent::__construct();
155 7
        $this->priceCategories = new ArrayCollection();
156
    }
157 7
158
    /**
159
     * Unset translations
160
     *
161
     * @return PerformanceEvent
162
     */
163
    public function unsetTranslations()
164
    {
165 14
        $this->translations = null;
166
167 14
        return $this;
168
    }
169
170
    /**
171
     * Get id
172
     *
173
     * @return integer
174
     */
175
    public function getId()
176
    {
177
        return $this->id;
178
    }
179
180
    /**
181
     * Set dateTime
182
     *
183
     * @param  \DateTime        $dateTime
184
     * @return PerformanceEvent
185
     */
186
    public function setDateTime($dateTime)
187
    {
188 6
        $this->dateTime = $dateTime;
189
190 6
        return $this;
191
    }
192
193 2
    /**
194
     * Get dateTime
195 2
     *
196 1
     * @return \DateTime
197
     */
198
    public function getDateTime()
199 1
    {
200
        return $this->dateTime;
201
    }
202
203
    /**
204
     * Set performance
205 4
     *
206
     * @param  \AppBundle\Entity\Performance $performance
207 4
     * @return PerformanceEvent
208
     */
209
    public function setPerformance(\AppBundle\Entity\Performance $performance = null)
210
    {
211
        $this->performance = $performance;
212
213
        return $this;
214
    }
215
216
    /**
217
     * Get performance
218
     *
219
     * @return \AppBundle\Entity\Performance
220
     */
221 4
    public function getPerformance()
222
    {
223 4
        return $this->performance;
224
    }
225
226
    public function __toString()
227
    {
228
        if ($this->getDateTime()) {
229
            return $this->getDateTime()->format('d-m-Y H:i');
230
        }
231
232
        return date("F j, Y, g:i a");
233
    }
234
235
    /**
236
     * @return mixed
237 4
     */
238
    public function getYear()
239 4
    {
240
        return $this->getDateTime()->format('Y');
241
    }
242
243
    /**
244
     * @param mixed $year
245
     */
246
    public function setYear($year)
247
    {
248
        $this->year = $year;
249
    }
250
251
    /**
252
     * @return int
253 4
     */
254
    public function getMonth()
255 4
    {
256
        return $this->getDateTime()->format('n');
257
    }
258
259
    /**
260
     * @param int $month
261
     */
262
    public function setMonth($month)
263
    {
264
        $this->month = $month;
265
    }
266
267
    /**
268
     * @return int
269 7
     */
270
    public function getDay()
271 7
    {
272
        return $this->getDateTime()->format('j');
273
    }
274
275
    /**
276
     * @param int $day
277 4
     */
278
    public function setDay($day)
279 4
    {
280 4
        $this->day = $day;
281
    }
282
283
    /**
284
     * @return string
285
     */
286
    public function getTime()
287
    {
288
        return $this->getDateTime()->format('G:i');
289
    }
290
291
    /**
292
     * @param string $time
293
     */
294
    public function setTime($time)
295
    {
296
        $this->time = $time;
297
    }
298
299
    /**
300
     * @return Venue
301
     */
302
    public function getVenue()
303
    {
304
        return $this->venue;
305
    }
306
307
    /**
308
     * @param Venue $venue
309
     * @return PerformanceEvent
310
     */
311
    public function setVenue(Venue $venue)
312
    {
313
        $this->venue = $venue;
314
315
        return $this;
316
    }
317
318
    /**
319
     * @param  PriceCategory $priceCategory
320
     * @return PerformanceEvent
321
     */
322
    public function addPriceCategory(PriceCategory $priceCategory)
323
    {
324
        $this->priceCategories[] = $priceCategory;
325
326
        return $this;
327
    }
328
329
    /**
330
     * @param PriceCategory $priceCategory
331
     */
332
    public function removePriceCategories(PriceCategory $priceCategory)
333
    {
334
        $this->priceCategories->removeElement($priceCategory);
335
    }
336
337
    /**
338
     * @return Collection
339
     */
340
    public function getPriceCategories()
341
    {
342
        return $this->priceCategories;
343
    }
344
345
    /**
346
     * @param PriceCategory[]|ArrayCollection $priceCategory
347
     */
348
    public function setPriceCategories($priceCategory)
349
    {
350
        $this->priceCategories = $priceCategory;
351
    }
352
353
    /**
354
     * @return string
355
     */
356
    public function getSetNumber()
357
    {
358
        return $this->setNumber;
359
    }
360
361
    /**
362
     * @param string $setNumber
363
     */
364
    public function setSetNumber($setNumber)
365
    {
366
        $this->setNumber = $setNumber;
367
    }
368
}
369