Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

src/Kunstmaan/NodeBundle/Entity/NodeVersion.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\NodeBundle\Entity;
4
5
use DateTime;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\Mapping as ORM;
8
use Kunstmaan\AdminBundle\Entity\AbstractEntity;
9
use Kunstmaan\UtilitiesBundle\Helper\ClassLookup;
10
11
/**
12
 * NodeVersion
13
 *
14
 * @ORM\Entity(repositoryClass="Kunstmaan\NodeBundle\Repository\NodeVersionRepository")
15
 * @ORM\Table(name="kuma_node_versions", indexes={@ORM\Index(name="idx_node_version_lookup", columns={"ref_id", "ref_entity_name"})})
16
 * @ORM\HasLifecycleCallbacks()
17
 * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
18
 */
19
class NodeVersion extends AbstractEntity
20
{
21
    const DRAFT_VERSION = 'draft';
22
    const PUBLIC_VERSION = 'public';
23
24
    /**
25
     * @var NodeTranslation
26
     *
27
     * @ORM\ManyToOne(targetEntity="NodeTranslation", inversedBy="nodeVersions")
28
     * @ORM\JoinColumn(name="node_translation_id", referencedColumnName="id")
29
     */
30
    protected $nodeTranslation;
31
32
    /**
33
     * @var string
34
     *
35
     * @ORM\Column(type="string")
36
     */
37
    protected $type;
38
39
    /**
40
     * @var string
41
     *
42
     * @ORM\Column(type="string")
43
     */
44
    protected $owner;
45
46
    /**
47
     * @var \DateTime
48
     *
49
     * @ORM\Column(type="datetime")
50
     */
51
    protected $created;
52
53
    /**
54
     * @var \DateTime
55
     *
56
     * @ORM\Column(type="datetime")
57
     */
58
    protected $updated;
59
60
    /**
61
     * @var int
62
     *
63
     * @ORM\Column(type="bigint", name="ref_id")
64
     */
65
    protected $refId;
66
67
    /**
68
     * @var string
69
     *
70
     * @ORM\Column(type="string", name="ref_entity_name")
71
     */
72
    protected $refEntityName;
73
74
    /**
75
     * The nodeVersion this nodeVersion originated from
76
     *
77
     * @var NodeVersion
78
     *
79
     * @ORM\ManyToOne(targetEntity="NodeVersion")
80
     * @ORM\JoinColumn(name="origin_id", referencedColumnName="id")
81
     */
82
    protected $origin;
83
84
    /**
85
     * Constructor
86
     */
87
    public function __construct()
88
    {
89
        $this->setCreated(new DateTime());
90
        $this->setUpdated(new DateTime());
91
    }
92
93
    /**
94
     * Set nodeTranslation
95
     *
96
     * @param NodeTranslation $nodeTranslation
97
     *
98
     * @return NodeVersion
99
     */
100
    public function setNodeTranslation(NodeTranslation $nodeTranslation)
101
    {
102
        $this->nodeTranslation = $nodeTranslation;
103
104
        return $this;
105
    }
106
107
    /**
108
     * Get NodeTranslation
109
     *
110
     * @return NodeTranslation
111
     */
112
    public function getNodeTranslation()
113
    {
114
        return $this->nodeTranslation;
115
    }
116
117
    /**
118
     * Get type
119
     *
120
     * @return string
121
     */
122
    public function getType()
123
    {
124
        return $this->type;
125
    }
126
127
    public function isDraft()
128
    {
129
        return self::DRAFT_VERSION === $this->type;
130
    }
131
132
    public function isPublic()
133
    {
134
        return self::PUBLIC_VERSION === $this->type;
135
    }
136
137
    /**
138
     * Set type
139
     *
140
     * @param string $type
141
     *
142
     * @return NodeVersion
143
     */
144
    public function setType($type)
145
    {
146
        $this->type = $type;
147
148
        return $this;
149
    }
150
151
    /**
152
     * Set owner
153
     *
154
     * @param string $owner
155
     *
156
     * @return NodeVersion
157
     */
158
    public function setOwner($owner)
159
    {
160
        $this->owner = $owner;
161
162
        return $this;
163
    }
164
165
    /**
166
     * Get owner
167
     *
168
     * @return string
169
     */
170
    public function getOwner()
171
    {
172
        return $this->owner;
173
    }
174
175
    /**
176
     * Set created
177
     *
178
     * @param DateTime $created
179
     *
180
     * @return NodeVersion
181
     */
182
    public function setCreated(DateTime $created)
183
    {
184
        $this->created = $created;
185
186
        return $this;
187
    }
188
189
    /**
190
     * Get created
191
     *
192
     * @return DateTime
193
     */
194
    public function getCreated()
195
    {
196
        return $this->created;
197
    }
198
199
    /**
200
     * Set updated
201
     *
202
     * @param DateTime $updated
203
     *
204
     * @return NodeVersion
205
     */
206
    public function setUpdated(DateTime $updated)
207
    {
208
        $this->updated = $updated;
209
210
        return $this;
211
    }
212
213
    /**
214
     * Get updated
215
     *
216
     * @return DateTime
217
     */
218
    public function getUpdated()
219
    {
220
        return $this->updated;
221
    }
222
223
    /**
224
     * Get refId
225
     *
226
     * @return int
227
     */
228
    public function getRefId()
229
    {
230
        return $this->refId;
231
    }
232
233
    /**
234
     * Set refId
235
     *
236
     * @param int $refId
237
     *
238
     * @return NodeVersion
239
     */
240
    protected function setRefId($refId)
241
    {
242
        $this->refId = $refId;
243
244
        return $this;
245
    }
246
247
    /**
248
     * Set reference entity name
249
     *
250
     * @param string $refEntityName
251
     *
252
     * @return NodeVersion
253
     */
254
    protected function setRefEntityName($refEntityName)
255
    {
256
        $this->refEntityName = $refEntityName;
257
258
        return $this;
259
    }
260
261
    /**
262
     * Get reference entity name
263
     *
264
     * @return string
265
     */
266
    public function getRefEntityName()
267
    {
268
        return $this->refEntityName;
269
    }
270
271
    public function getDefaultAdminType()
272
    {
273
        return null;
274
    }
275
276
    /**
277
     * @param HasNodeInterface $entity
278
     *
279
     * @return NodeVersion
280
     */
281
    public function setRef(HasNodeInterface $entity)
282
    {
283
        $this->setRefId($entity->getId());
284
        $this->setRefEntityName(ClassLookup::getClass($entity));
285
286
        return $this;
287
    }
288
289
    /**
290
     * @param EntityManager $em
291
     *
292
     * @return HasNodeInterface
0 ignored issues
show
Should the return type not be HasNodeInterface|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
293
     */
294
    public function getRef(EntityManager $em)
295
    {
296
        return $em->getRepository($this->getRefEntityName())->find($this->getRefId());
297
    }
298
299
    /**
300
     * @param NodeVersion $origin
301
     *
302
     * @return NodeVersion
303
     */
304
    public function setOrigin($origin)
305
    {
306
        $this->origin = $origin;
307
308
        return $this;
309
    }
310
311
    /**
312
     * @return NodeVersion
313
     */
314
    public function getOrigin()
315
    {
316
        return $this->origin;
317
    }
318
}
319