Completed
Pull Request — master (#123)
by
unknown
12:58
created

History::setDateTime()   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 3
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\ArrayCollection;
6
use AppBundle\Traits\DeletedByTrait;
7
use Application\Sonata\MediaBundle\Entity\GalleryHasMedia;
8
use Doctrine\Common\Collections\ArrayCollection;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Cannot use Doctrine\Common\Collections\ArrayCollection as ArrayCollection because the name is already in use
Loading history...
9
use Doctrine\ORM\Mapping as ORM;
10
use Gedmo\Mapping\Annotation as Gedmo;
11
use JMS\Serializer\Annotation as Serializer;
12
use Symfony\Component\Validator\Constraints as Assert;
13
14
/**
15
 * @ORM\Table(name="history")
16
 * @ORM\Entity(repositoryClass="AppBundle\Repository\HistoryRepository")
17
 * @Gedmo\TranslationEntity(class="AppBundle\Entity\Translations\HistoryTranslation")
18
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
19
 * @Serializer\ExclusionPolicy("all")
20
 */
21
class History extends AbstractTranslateableStory
22
{
23
    use DeletedByTrait;
24
25
    /**
26
     * @var integer
27
     *
28
     * @ORM\Column(name="id", type="integer")
29
     * @ORM\Id
30
     * @ORM\GeneratedValue(strategy="AUTO")
31
     */
32
    protected $id;
33
34
    /**
35
     * @var /Datetime
36
     *
37
     * @Assert\NotBlank()
38
     * @ORM\Column(type="datetime")
39
     * @Serializer\Type("DateTime")
40
     */
41
    protected $dateTime;
42
43
    /**
44
     * @var int
45
     *
46
     * @Serializer\Type("integer")
47
     * @Serializer\Expose
48
     * @Serializer\Accessor(getter="getYear")
49
     */
50
    protected $year;
51
52
    /**
53
     * @var ArrayCollection|Translation[]
54
     *
55
     * @ORM\OneToMany(
56
     *     targetEntity="AppBundle\Entity\Translations\HistoryTranslation",
57
     *     mappedBy="object",
58
     *     cascade={"persist", "remove"}
59
     * )
60
     */
61
    protected $translations;
62
63
    /**
64
     * @var ArrayCollection|GalleryHasMedia[]
65
     *
66
     * @ORM\ManyToMany(targetEntity="Application\Sonata\MediaBundle\Entity\GalleryHasMedia", cascade={"persist"})
67
     * @ORM\JoinTable(name="history_galleryHasMedia",
68
     *     joinColumns={@ORM\JoinColumn(name="history_id",referencedColumnName="id")},
69
     *     inverseJoinColumns={@ORM\JoinColumn(name="galleryHasMedia_id",referencedColumnName="id")}
70
     * )
71
     */
72
    protected $galleryHasMedia;
73
74
    /**
75
     * @var string
76
     *
77
     * @Assert\NotBlank()
78
     * @Assert\Choice(callback = "getTypes", message = "choose_valid_type")
79
     * @ORM\Column(type="string", length=255)
80
     * @Serializer\Type("string")
81
     * @Serializer\Expose
82
     */
83
    protected $type;
84
85
    /**
86
     * ArrayCollection|Performances[]
87
     *
88
     * @Serializer\Expose
89
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Performance", mappedBy="festival", orphanRemoval=true)
90
     */
91
    protected $performances;
92
93
    /**
94 1
     * Constructor
95
     */
96 1
    public function __construct()
97 1
    {
98 1
        parent::__construct();
99
        $this->galleryHasMedia = new ArrayCollection();
100
    }
101
102
    /**
103
     * Get id
104
     *
105 2
     * @return integer
106
     */
107 2
    public function getId()
108
    {
109
        return $this->id;
110
    }
111
112
    /**
113
     * Unset translations
114
     *
115 2
     * @return History
116
     */
117 2
    public function unsetTranslations()
118
    {
119 2
        $this->translations = null;
120
121
        return $this;
122
    }
123
124
    /**
125
     * Set dateTime
126
     *
127
     * @param  \DateTime $dateTime
128
     * @return History
129
     */
130
    public function setDateTime($dateTime)
131
    {
132
        $this->dateTime = $dateTime;
133
134
        return $this;
135
    }
136
137
    /**
138
     * Get dateTime
139
     *
140 5
     * @return \DateTime
141
     */
142 5
    public function getDateTime()
143
    {
144
        return $this->dateTime;
145
    }
146
147
    /**
148 4
     * @return mixed
149
     */
150 4
    public function getYear()
151
    {
152
        return $this->getDateTime()->format('Y');
153
    }
154
155
    /**
156
     * Add galleryHasMedia
157
     *
158
     * @param \Application\Sonata\MediaBundle\Entity\GalleryHasMedia $galleryHasMedia
159
     * @return self
160
     */
161
    public function addGalleryHasMedia(\Application\Sonata\MediaBundle\Entity\GalleryHasMedia $galleryHasMedia)
162
    {
163
        $this->galleryHasMedia[] = $galleryHasMedia;
164
165
        return $this;
166
    }
167
168
    /**
169
     * Remove galleryHasMedia
170
     *
171
     * @param \Application\Sonata\MediaBundle\Entity\GalleryHasMedia $galleryHasMedia
172
     */
173
    public function removeGalleryHasMedia(\Application\Sonata\MediaBundle\Entity\GalleryHasMedia $galleryHasMedia)
174
    {
175
        $this->galleryHasMedia->removeElement($galleryHasMedia);
176
    }
177
178
    /**
179
     * Get galleryHasMedia
180
     *
181 3
     * @return \Doctrine\Common\Collections\Collection
182
     */
183 3
    public function getGalleryHasMedia()
184
    {
185
        return $this->galleryHasMedia;
186
    }
187
188
    /**
189 3
     * @return string
190
     */
191 3
    public function getType()
192
    {
193
        return $this->type;
194
    }
195
196
    /**
197
     * @param string $type
198
     * @return $this
199
     */
200
    public function setType($type)
201
    {
202
        $this->type = $type;
203
204
        return $this;
205 2
    }
206
207 2
    public static function getTypes()
208
    {
209
        return ['history' => 'history', 'festival' => 'festival'];
210
    }
211
}
212