Completed
Pull Request — master (#124)
by Serhii
13:45
created

PerformanceEvent   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 254
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
dl 0
loc 254
ccs 28
cts 44
cp 0.6364
rs 10
c 0
b 0
f 0
wmc 18
lcom 2
cbo 4

17 Methods

Rating   Name   Duplication   Size   Complexity  
A unsetTranslations() 0 6 1
A getId() 0 4 1
A setDateTime() 0 6 1
A getDateTime() 0 4 1
A setPerformance() 0 6 1
A getPerformance() 0 4 1
A getYear() 0 4 1
A setYear() 0 4 1
A getMonth() 0 4 1
A setMonth() 0 4 1
A getDay() 0 4 1
A setDay() 0 4 1
A getTime() 0 4 1
A setTime() 0 4 1
A getVenue() 0 4 1
A setVenue() 0 4 1
A __toString() 0 8 2
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Gedmo\Mapping\Annotation as Gedmo;
8
use Gedmo\Blameable\Traits\BlameableEntity;
9
use Symfony\Component\Validator\Constraints as Assert;
10
use AppBundle\Traits\TimestampableTrait;
11
use AppBundle\Traits\DeletedByTrait;
12
use JMS\Serializer\Annotation\ExclusionPolicy;
13
use JMS\Serializer\Annotation\Expose;
14
use JMS\Serializer\Annotation\Type;
15
use JMS\Serializer\Annotation\Accessor;
16
use AppBundle\Validator\TwoPerformanceEventsPerDay;
17
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
18
use Sonata\TranslationBundle\Model\Gedmo\AbstractPersonalTranslatable;
19
20
/**
21
 * @ORM\Table(name="performance_schedule")
22
 * @ORM\Entity(repositoryClass="AppBundle\Repository\PerformanceEventRepository")
23
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
24
 * @ExclusionPolicy("all")
25
 * @Gedmo\TranslationEntity(class="AppBundle\Entity\Translations\PerformanceEventTranslation")
26
 * @TwoPerformanceEventsPerDay()
27
 */
28
class PerformanceEvent extends AbstractPersonalTranslatable implements TranslatableInterface
29
{
30
    use TimestampableTrait, BlameableEntity, DeletedByTrait;
31
32
    const VENUE_PHILHARMONIC = "venue-philharmonic";
33
    const VENUE_KULIC_HOUSE  = "venue-kilic-house";
34
    const VENUE_THEATRE      = "venue-theatre";
35
36
    public static $venues = [
37
        self::VENUE_PHILHARMONIC => self::VENUE_PHILHARMONIC,
38
        self::VENUE_KULIC_HOUSE  => self::VENUE_KULIC_HOUSE,
39
        self::VENUE_THEATRE      => self::VENUE_THEATRE,
40
    ];
41
42
    /**
43
     * @var integer
44
     *
45
     * @ORM\Column(name="id", type="integer")
46
     * @ORM\Id
47
     * @ORM\GeneratedValue(strategy="AUTO")
48
     * @Type("integer")
49
     * @Expose
50
     */
51
    private $id;
52
53
    /**
54
     * @var Performance
55
     *
56
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Performance", inversedBy="performanceEvents")
57
     * @Type("AppBundle\Entity\Performance")
58
     * @Expose
59
     */
60
    private $performance;
61
62
    /**
63
     * @var /Datetime
64
     *
65
     * @Assert\NotBlank()
66
     * @ORM\Column(type="datetime")
67
     * @Type("DateTime")
68
     * @Expose
69
     */
70
    private $dateTime;
71
72
    /**
73
     * Place where performance happens
74
     * @var string
75
     * @ORM\Column(type="string")
76
     * @Type("string")
77
     * @Expose
78
     */
79
    private $venue;
80
81
    /**
82
     * @var int
83
     *
84
     * @Type("integer")
85
     * @Expose
86
     * @Accessor(getter="getYear")
87
     */
88
    private $year;
89
90
    /**
91
     * @var int
92
     *
93
     * @Expose
94
     * @Accessor(getter="getMonth")
95
     */
96
    private $month;
97
98
    /**
99
     * @var int
100
     *
101
     * @Expose
102
     * @Accessor(getter="getDay")
103
     */
104
    private $day;
105
106
    /**
107
     * @var string
108
     *
109
     * @Expose
110
     * @Accessor(getter="getTime")
111
     */
112
    private $time;
113
114
    /**
115
     * @var ArrayCollection|Translation[]
116
     *
117
     * @ORM\OneToMany(
118
     *     targetEntity="AppBundle\Entity\Translations\PerformanceEventTranslation",
119
     *     mappedBy="object",
120
     *     cascade={"persist", "remove"}
121
     * )
122
     */
123
    protected $translations;
124
125
    /**
126
     * Unset translations
127
     *
128
     * @return PerformanceEvent
129
     */
130 4
    public function unsetTranslations()
131
    {
132 4
        $this->translations = null;
133
134 4
        return $this;
135
    }
136
137
    /**
138
     * Get id
139
     *
140
     * @return integer
141
     */
142 9
    public function getId()
143
    {
144 9
        return $this->id;
145
    }
146
147
    /**
148
     * Set dateTime
149
     *
150
     * @param  \DateTime        $dateTime
151
     * @return PerformanceEvent
152
     */
153 7
    public function setDateTime($dateTime)
154
    {
155 7
        $this->dateTime = $dateTime;
156
157 7
        return $this;
158
    }
159
160
    /**
161
     * Get dateTime
162
     *
163
     * @return \DateTime
164
     */
165 12
    public function getDateTime()
166
    {
167 12
        return $this->dateTime;
168
    }
169
170
    /**
171
     * Set performance
172
     *
173
     * @param  \AppBundle\Entity\Performance $performance
174
     * @return PerformanceEvent
175
     */
176
    public function setPerformance(\AppBundle\Entity\Performance $performance = null)
177
    {
178
        $this->performance = $performance;
179
180
        return $this;
181
    }
182
183
    /**
184
     * Get performance
185
     *
186
     * @return \AppBundle\Entity\Performance
187
     */
188 3
    public function getPerformance()
189
    {
190 3
        return $this->performance;
191
    }
192
193 1
    public function __toString()
194
    {
195 1
        if ($this->getDateTime()) {
196 1
            return $this->getDateTime()->format('d-m-Y H:i');
197
        }
198
199
        return date("F j, Y, g:i a");
200
    }
201
202
    /**
203
     * @return mixed
204
     */
205 4
    public function getYear()
206
    {
207 4
        return $this->getDateTime()->format('Y');
208
    }
209
210
    /**
211
     * @param mixed $year
212
     */
213
    public function setYear($year)
214
    {
215
        $this->year = $year;
216
    }
217
218
    /**
219
     * @return int
220
     */
221 4
    public function getMonth()
222
    {
223 4
        return $this->getDateTime()->format('n');
224
    }
225
226
    /**
227
     * @param int $month
228
     */
229
    public function setMonth($month)
230
    {
231
        $this->month = $month;
232
    }
233
234
    /**
235
     * @return int
236
     */
237 4
    public function getDay()
238
    {
239 4
        return $this->getDateTime()->format('j');
240
    }
241
242
    /**
243
     * @param int $day
244
     */
245
    public function setDay($day)
246
    {
247
        $this->day = $day;
248
    }
249
250
    /**
251
     * @return string
252
     */
253 4
    public function getTime()
254
    {
255 4
        return $this->getDateTime()->format('G:i');
256
    }
257
258
    /**
259
     * @param string $time
260
     */
261
    public function setTime($time)
262
    {
263
        $this->time = $time;
264
    }
265
266
    /**
267
     * @return string
268
     */
269 4
    public function getVenue()
270
    {
271 4
        return $this->venue;
272
    }
273
274
    /**
275
     * @param string $venue
276
     */
277 4
    public function setVenue($venue)
278
    {
279 4
        $this->venue = $venue;
280 4
    }
281
}
282