1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace KI\PonthubBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use JMS\Serializer\Annotation as JMS; |
7
|
|
|
use KI\CoreBundle\Entity\Likeable; |
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @ORM\Entity |
12
|
|
|
* @JMS\ExclusionPolicy("all") |
13
|
|
|
*/ |
14
|
|
|
class PonthubFile extends Likeable |
15
|
|
|
{ |
16
|
|
|
protected $fleurDn = 'fleur.enpc.fr'; |
17
|
|
|
protected $fleurPort = 8080; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Chemin complet sur Fleur |
21
|
|
|
* @ORM\Column(name="path", type="string") |
22
|
|
|
* @JMS\Expose |
23
|
|
|
* @Assert\Type("string") |
24
|
|
|
*/ |
25
|
|
|
protected $path; |
26
|
|
|
|
27
|
|
|
public function fileUrl() |
28
|
|
|
{ |
29
|
|
|
return 'http://'.$this->fleurDn.':'.$this->fleurPort.str_replace('/root/web', '', $this->path); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Taille en octets |
34
|
|
|
* @ORM\Column(name="size", type="bigint", nullable=true) |
35
|
|
|
* @JMS\Expose |
36
|
|
|
* @Assert\Type("string") |
37
|
|
|
*/ |
38
|
|
|
protected $size; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Date d'ajout (timestamp) |
42
|
|
|
* @ORM\Column(name="added", type="integer", nullable=true) |
43
|
|
|
* @JMS\Expose |
44
|
|
|
* @Assert\Type("integer") |
45
|
|
|
*/ |
46
|
|
|
protected $added; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Statut [OK|NeedInfos|NotFound] |
50
|
|
|
* @ORM\Column(name="status", type="string") |
51
|
|
|
* @JMS\Expose |
52
|
|
|
* @Assert\Type("string") |
53
|
|
|
*/ |
54
|
|
|
protected $status; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Description |
58
|
|
|
* @ORM\Column(name="description", type="string", nullable=true) |
59
|
|
|
* @JMS\Expose |
60
|
|
|
* @Assert\Type("string") |
61
|
|
|
*/ |
62
|
|
|
protected $description; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Image (affiche/jaquette/screenshot...) |
66
|
|
|
* @ORM\OneToOne(targetEntity="KI\CoreBundle\Entity\Image", cascade={"persist", "remove"}) |
67
|
|
|
* @Assert\Valid() |
68
|
|
|
*/ |
69
|
|
|
protected $image; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @JMS\VirtualProperty() |
73
|
|
|
*/ |
74
|
|
|
public function imageUrl() |
75
|
|
|
{ |
76
|
|
|
return $this->image !== null ? $this->image->getWebPath() : null; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Tags |
81
|
|
|
* @ORM\ManyToMany(targetEntity="KI\CoreBundle\Entity\Tag", cascade={"persist"}) |
82
|
|
|
* @Assert\Valid() |
83
|
|
|
*/ |
84
|
|
|
protected $listTags; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @JMS\VirtualProperty() |
88
|
|
|
*/ |
89
|
|
|
public function tags() |
90
|
|
|
{ |
91
|
|
|
$tags = []; |
92
|
|
|
if(is_array($this->listTags) || is_object($this->listTags)) { |
93
|
|
|
foreach ($this->listTags as $tag) { |
94
|
|
|
$tags[] = $tag->getName(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
return $tags; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Genres |
102
|
|
|
* @ORM\ManyToMany(targetEntity="KI\PonthubBundle\Entity\Genre", cascade={"persist"}) |
103
|
|
|
* @Assert\Valid() |
104
|
|
|
*/ |
105
|
|
|
protected $listGenres; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @JMS\VirtualProperty() |
109
|
|
|
*/ |
110
|
|
|
public function genres() |
111
|
|
|
{ |
112
|
|
|
$genres = []; |
113
|
|
|
foreach ($this->listGenres as $genre) { |
114
|
|
|
$genres[] = $genre->getName(); |
115
|
|
|
} |
116
|
|
|
return $genres; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Utilisateurs ayant téléchargé le fichier |
121
|
|
|
* @ORM\OneToMany(targetEntity="KI\PonthubBundle\Entity\PonthubFileUser", mappedBy="file", cascade={"remove"}) |
122
|
|
|
* @Assert\Valid() |
123
|
|
|
*/ |
124
|
|
|
protected $users; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Nombre de fois où le fichier a été téléchargé |
128
|
|
|
* @JMS\VirtualProperty() |
129
|
|
|
*/ |
130
|
|
|
public function downloads() |
131
|
|
|
{ |
132
|
|
|
return count($this->users); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Constructor |
137
|
|
|
*/ |
138
|
|
|
public function __construct() |
139
|
|
|
{ |
140
|
|
|
$this->listGenres = new \Doctrine\Common\Collections\ArrayCollection(); |
141
|
|
|
$this->listTags = new \Doctrine\Common\Collections\ArrayCollection(); |
142
|
|
|
$this->users = new \Doctrine\Common\Collections\ArrayCollection(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Set size |
147
|
|
|
* |
148
|
|
|
* @param integer $size |
149
|
|
|
* @return PonthubFile |
150
|
|
|
*/ |
151
|
|
|
public function setSize($size) |
152
|
|
|
{ |
153
|
|
|
$this->size = $size; |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Get size |
160
|
|
|
* |
161
|
|
|
* @return integer |
162
|
|
|
*/ |
163
|
|
|
public function getSize() |
164
|
|
|
{ |
165
|
|
|
return $this->size; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Set path |
170
|
|
|
* |
171
|
|
|
* @param string $path |
172
|
|
|
* @return PonthubFile |
173
|
|
|
*/ |
174
|
|
|
public function setPath($path) |
175
|
|
|
{ |
176
|
|
|
$this->path = $path; |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get path |
183
|
|
|
* |
184
|
|
|
* @return string |
185
|
|
|
*/ |
186
|
|
|
public function getPath() |
187
|
|
|
{ |
188
|
|
|
return $this->path; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Set added |
193
|
|
|
* |
194
|
|
|
* @param integer $added |
195
|
|
|
* @return PonthubFile |
196
|
|
|
*/ |
197
|
|
|
public function setAdded($added) |
198
|
|
|
{ |
199
|
|
|
$this->added = $added; |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Get added |
206
|
|
|
* |
207
|
|
|
* @return integer |
208
|
|
|
*/ |
209
|
|
|
public function getAdded() |
210
|
|
|
{ |
211
|
|
|
return $this->added; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Set status |
216
|
|
|
* |
217
|
|
|
* @param string $status |
218
|
|
|
* @return PonthubFile |
219
|
|
|
*/ |
220
|
|
|
public function setStatus($status) |
221
|
|
|
{ |
222
|
|
|
$this->status = $status; |
223
|
|
|
|
224
|
|
|
return $this; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Get status |
229
|
|
|
* |
230
|
|
|
* @return string |
231
|
|
|
*/ |
232
|
|
|
public function getStatus() |
233
|
|
|
{ |
234
|
|
|
return $this->status; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Set description |
239
|
|
|
* |
240
|
|
|
* @param string $description |
241
|
|
|
* @return PonthubFile |
242
|
|
|
*/ |
243
|
|
|
public function setDescription($description) |
244
|
|
|
{ |
245
|
|
|
$this->description = $description; |
246
|
|
|
|
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Get description |
252
|
|
|
* |
253
|
|
|
* @return string |
254
|
|
|
*/ |
255
|
|
|
public function getDescription() |
256
|
|
|
{ |
257
|
|
|
return $this->description; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Set image |
262
|
|
|
* |
263
|
|
|
* @param \KI\CoreBundle\Entity\Image $image |
264
|
|
|
* @return PonthubFile |
265
|
|
|
*/ |
266
|
|
|
public function setImage(\KI\CoreBundle\Entity\Image $image = null) |
267
|
|
|
{ |
268
|
|
|
$this->image = $image; |
269
|
|
|
|
270
|
|
|
return $this; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Get image |
275
|
|
|
* |
276
|
|
|
* @return \KI\CoreBundle\Entity\Image |
277
|
|
|
*/ |
278
|
|
|
public function getImage() |
279
|
|
|
{ |
280
|
|
|
return $this->image; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Add tags |
285
|
|
|
* |
286
|
|
|
* @param \KI\CoreBundle\Entity\Tag $tag |
287
|
|
|
* @return PonthubFile |
288
|
|
|
*/ |
289
|
|
|
public function addTag(\KI\CoreBundle\Entity\Tag $tag) |
290
|
|
|
{ |
291
|
|
|
$this->listTags[] = $tag; |
292
|
|
|
|
293
|
|
|
return $this; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Remove tags |
298
|
|
|
* |
299
|
|
|
* @param \KI\CoreBundle\Entity\Tag $tag |
300
|
|
|
*/ |
301
|
|
|
public function removeTag(\KI\CoreBundle\Entity\Tag $tag) |
302
|
|
|
{ |
303
|
|
|
$this->listTags->removeElement($tag); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Get tags |
308
|
|
|
* |
309
|
|
|
* @return \Doctrine\Common\Collections\Collection |
310
|
|
|
*/ |
311
|
|
|
public function getTags() |
312
|
|
|
{ |
313
|
|
|
return $this->listTags; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Set tags |
318
|
|
|
* |
319
|
|
|
* @return PonthubFile |
320
|
|
|
*/ |
321
|
|
|
public function setTags($tags) |
322
|
|
|
{ |
323
|
|
|
return $this->listTags = $tags; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Add genres |
328
|
|
|
* |
329
|
|
|
* @param \KI\PonthubBundle\Entity\Genre $genre |
330
|
|
|
* @return PonthubFile |
331
|
|
|
*/ |
332
|
|
|
public function addGenre(\KI\PonthubBundle\Entity\Genre $genre) |
333
|
|
|
{ |
334
|
|
|
$this->listGenres[] = $genre; |
335
|
|
|
|
336
|
|
|
return $this; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* Remove genres |
341
|
|
|
* |
342
|
|
|
* @param \KI\PonthubBundle\Entity\Genre $genre |
343
|
|
|
*/ |
344
|
|
|
public function removeGenre(\KI\PonthubBundle\Entity\Genre $genre) |
345
|
|
|
{ |
346
|
|
|
$this->listGenres->removeElement($genre); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Get genres |
351
|
|
|
* |
352
|
|
|
* @return \Doctrine\Common\Collections\Collection |
353
|
|
|
*/ |
354
|
|
|
public function getGenres() |
355
|
|
|
{ |
356
|
|
|
return $this->listGenres; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Set genres |
361
|
|
|
* |
362
|
|
|
* @return PonthubFile |
363
|
|
|
*/ |
364
|
|
|
public function setGenres($genres) |
365
|
|
|
{ |
366
|
|
|
return $this->listGenres = $genres; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Add user |
372
|
|
|
* |
373
|
|
|
* @param \KI\UserBundle\Entity\User $user |
374
|
|
|
* @return PonthubFile |
375
|
|
|
*/ |
376
|
|
|
public function addUser(\KI\UserBundle\Entity\User $user) |
377
|
|
|
{ |
378
|
|
|
$this->users[] = $user; |
379
|
|
|
|
380
|
|
|
return $this; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Remove users |
385
|
|
|
* |
386
|
|
|
* @param \KI\UserBundle\Entity\User $user |
387
|
|
|
*/ |
388
|
|
|
public function removeUser(\KI\UserBundle\Entity\User $user) |
389
|
|
|
{ |
390
|
|
|
$this->users->removeElement($user); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Get users |
395
|
|
|
* |
396
|
|
|
* @return \Doctrine\Common\Collections\Collection |
397
|
|
|
*/ |
398
|
|
|
public function getUsers() |
399
|
|
|
{ |
400
|
|
|
return $this->users; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Set users |
405
|
|
|
* |
406
|
|
|
* @return PonthubFile |
407
|
|
|
*/ |
408
|
|
|
public function setUsers($users) |
409
|
|
|
{ |
410
|
|
|
return $this->users = $users; |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* @JMS\Expose |
415
|
|
|
*/ |
416
|
|
|
protected $downloaded = false; |
417
|
|
|
|
418
|
|
|
public function hasBeenDownloaded() |
419
|
|
|
{ |
420
|
|
|
return $this->downloaded; |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
public function setDownloaded($downloaded) |
424
|
|
|
{ |
425
|
|
|
return $this->downloaded = $downloaded; |
426
|
|
|
} |
427
|
|
|
} |
428
|
|
|
|