Completed
Push — master ( 9f183a...8cd85a )
by Julito
13:16
created

ResourceFile::setOriginalFilename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Entity\Resource;
5
6
use Doctrine\ORM\Mapping as ORM;
7
use Gedmo\Timestampable\Traits\TimestampableEntity;
8
use Symfony\Component\HttpFoundation\File\File;
9
use Symfony\Component\HttpFoundation\File\UploadedFile;
10
use Symfony\Component\Validator\Constraints as Assert;
11
use Vich\UploaderBundle\Mapping\Annotation as Vich;
12
13
/**
14
 * @ORM\Entity
15
 *
16
 * @Vich\Uploadable
17
 *
18
 * @ORM\Table(name="resource_file")
19
 */
20
class ResourceFile
21
{
22
    use TimestampableEntity;
23
24
    /**
25
     * @ORM\Id
26
     * @ORM\Column(type="integer")
27
     * @ORM\GeneratedValue
28
     */
29
    protected $id;
30
31
    /**
32
     * @Assert\NotBlank()
33
     *
34
     * @var string
35
     *
36
     * @ORM\Column(type="string", length=255)
37
     */
38
    protected $name;
39
40
    /**
41
     * @var string
42
     */
43
    protected $description;
44
45
    /**
46
     * @var bool
47
     */
48
    protected $enabled = false;
49
50
    /**
51
     * @var int
52
     */
53
    protected $width;
54
55
    /**
56
     * @var int
57
     */
58
    protected $height;
59
60
    /**
61
     * @var float
62
     */
63
    protected $length;
64
65
    /**
66
     * @var string
67
     */
68
    protected $copyright;
69
70
    /**
71
     * @var string
72
     *
73
     * @ORM\Column(type="text", nullable=true)
74
     */
75
    protected $mimeType;
76
77
    /**
78
     * @var string
79
     *
80
     * @ORM\Column(type="text", nullable=true)
81
     */
82
    protected $originalName;
83
84
    /**
85
     * @var string
86
     *
87
     * @ORM\Column(type="simple_array", nullable=true)
88
     */
89
    protected $dimensions;
90
91
    /**
92
     * @var int
93
     *
94
     * @ORM\Column(type="integer", nullable=true)
95
     */
96
    protected $size;
97
98
    /**
99
     * @var File
100
     *
101
     * @Vich\UploadableField(
102
     *     mapping="resources",
103
     *     fileNameProperty="name",
104
     *     size="size",
105
     *     mimeType="mimeType",
106
     *     originalName="originalName",
107
     *     dimensions="dimensions"
108
     * )
109
     */
110
    protected $file;
111
112
    /**
113
     * @var string
114
     *
115
     * @ORM\Column(name="crop", type="string", length=255, nullable=true)
116
     */
117
    protected $crop;
118
119
    /**
120
     * @var ResourceNode
121
     *
122
     * @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="resourceFile")
123
     */
124
    protected $resourceNode;
125
126
//    /**
127
//     * @var string
128
//     *
129
//     * @Assert\NotBlank()
130
//     *
131
//     * @ORM\Column(name="hash", type="string", nullable=false)
132
//     */
133
//    protected $hash;
134
135
//    /**
136
//     * @Assert\NotBlank()
137
//     *
138
//     * @var string
139
//     *
140
//     * @ORM\Column(name="original_filename", type="string", nullable=false)
141
//     */
142
//    protected $originalFilename;
143
//
144
//    /**
145
//     * @Assert\NotBlank()
146
//     *
147
//     * @var string
148
//     *
149
//     * @ORM\Column(name="size", type="string", nullable=false)
150
//     */
151
//    protected $size;
152
//
153
//    /**
154
//     * @Assert\NotBlank()
155
//     *
156
//     * @var string
157
//     *
158
//     * @ORM\Column(name="width", type="string", nullable=true)
159
//     */
160
//    protected $width;
161
162
//    /**
163
//     * @Assert\NotBlank()
164
//     *
165
//     * @var string
166
//     *
167
//     * @ORM\Column(name="height", type="string", nullable=true)
168
//     */
169
//    protected $height;
170
//
171
//    /**
172
//     * @var string
173
//     *
174
//     * @ORM\Column(name="copyright", type="string", nullable=true)
175
//     */
176
//    protected $copyright;
177
178
//    /**
179
//     * @var string
180
//     *
181
//     * @ORM\Column(name="contentType", type="string", nullable=true)
182
//     */
183
//    protected $contentType;
184
//
185
//    /**
186
//     * @var string
187
//     *
188
//     * @ORM\Column(name="extension", type="string", nullable=false)
189
//     */
190
//    protected $extension;
191
192
193
    /**
194
     * @var bool
195
     *
196
     * @ORM\Column(name="enabled", type="boolean")
197
     */
198
    //protected $enabled;
199
200
    /**
201
     * Constructor.
202
     */
203
    public function __construct()
204
    {
205
        $this->enabled = true;
206
    }
207
208
    /**
209
     * @return mixed
210
     */
211
    public function getName()
212
    {
213
        return $this->name;
214
    }
215
216
    /**
217
     * @param mixed $name
218
     *
219
     * @return ResourceFile
220
     */
221
    public function setName($name)
222
    {
223
        $this->name = $name;
224
225
        return $this;
226
    }
227
228
229
    /**
230
     * @return string
231
     */
232
    public function getCrop(): string
233
    {
234
        return $this->crop;
235
    }
236
237
    /**
238
     * @param string $crop
239
     *
240
     * @return $this
241
     */
242
    public function setCrop($crop)
243
    {
244
        $this->crop = $crop;
245
246
        return $this;
247
    }
248
249
    /**
250
     * @return string
251
     */
252
    public function getHash(): string
253
    {
254
        return $this->hash;
255
    }
256
257
    /**
258
     * @param string $hash
259
     *
260
     * @return ResourceFile
261
     */
262
    public function setHash(string $hash): ResourceFile
263
    {
264
        $this->hash = $hash;
0 ignored issues
show
Bug Best Practice introduced by
The property hash does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
265
266
        return $this;
267
    }
268
269
    /**
270
     * @return string
271
     */
272
    public function getOriginalFilename(): string
273
    {
274
        return $this->originalFilename;
275
    }
276
277
    /**
278
     * @param string $originalFilename
279
     *
280
     * @return ResourceFile
281
     */
282
    public function setOriginalFilename(string $originalFilename): ResourceFile
283
    {
284
        $this->originalFilename = $originalFilename;
0 ignored issues
show
Bug Best Practice introduced by
The property originalFilename does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
285
286
        return $this;
287
    }
288
289
    /**
290
     * @return int
291
     */
292
    public function getSize(): int
293
    {
294
        return (int) $this->size;
295
    }
296
297
    /**
298
     * @param int $size
299
     *
300
     * @return ResourceFile
301
     */
302
    public function setSize($size): ResourceFile
303
    {
304
        $this->size = $size;
305
306
        return $this;
307
    }
308
309
    /**
310
     * @return string
311
     */
312
    public function getCopyright(): string
313
    {
314
        return (string) $this->copyright;
315
    }
316
317
    /**
318
     * @return string
319
     */
320
    public function getContentType(): string
321
    {
322
        return (string) $this->contentType;
323
    }
324
325
    /**
326
     * @param string $contentType
327
     *
328
     * @return ResourceFile
329
     */
330
    public function setContentType(string $contentType): ResourceFile
331
    {
332
        $this->contentType = $contentType;
0 ignored issues
show
Bug Best Practice introduced by
The property contentType does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
333
334
        return $this;
335
    }
336
337
    /**
338
     * @return string
339
     */
340
    public function getExtension(): string
341
    {
342
        return $this->extension;
343
    }
344
345
    /**
346
     * @param string $extension
347
     *
348
     * @return ResourceFile
349
     */
350
    public function setExtension(string $extension): ResourceFile
351
    {
352
        $this->extension = $extension;
0 ignored issues
show
Bug Best Practice introduced by
The property extension does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
353
354
        return $this;
355
    }
356
357
    /**
358
     * @return ResourceNode
359
     */
360
    public function getResourceNode(): ResourceNode
361
    {
362
        return $this->resourceNode;
363
    }
364
365
    /**
366
     * @param ResourceNode $resourceNode
367
     *
368
     * @return ResourceFile
369
     */
370
    public function setResourceNode(ResourceNode $resourceNode): ResourceFile
371
    {
372
        $this->resourceNode = $resourceNode;
373
374
        return $this;
375
    }
376
377
    /**
378
     * @return bool
379
     */
380
    public function isEnabled(): bool
381
    {
382
        return $this->enabled;
383
    }
384
385
    /**
386
     * @param bool $enabled
387
     *
388
     * @return ResourceFile
389
     */
390
    public function setEnabled(bool $enabled): ResourceFile
391
    {
392
        $this->enabled = $enabled;
393
394
        return $this;
395
    }
396
397
    /**
398
     * @return mixed
399
     */
400
    public function getId()
401
    {
402
        return $this->id;
403
    }
404
405
    /**
406
     * @param mixed $id
407
     *
408
     * @return ResourceFile
409
     */
410
    public function setId($id)
411
    {
412
        $this->id = $id;
413
414
        return $this;
415
    }
416
417
    /**
418
     * @return string
419
     */
420
    public function getDescription(): string
421
    {
422
        return $this->description;
423
    }
424
425
    /**
426
     * @param string $description
427
     *
428
     * @return ResourceFile
429
     */
430
    public function setDescription(string $description): ResourceFile
431
    {
432
        $this->description = $description;
433
434
        return $this;
435
    }
436
437
    /**
438
     * @return string
439
     */
440
    public function getMimeType(): string
441
    {
442
        return $this->mimeType;
443
    }
444
445
    /**
446
     * @param string $mimeType
447
     *
448
     * @return ResourceFile
449
     */
450
    public function setMimeType($mimeType): ResourceFile
451
    {
452
        $this->mimeType = $mimeType;
453
454
        return $this;
455
    }
456
457
    /**
458
     * @return string
459
     */
460
    public function getOriginalName(): string
461
    {
462
        return $this->originalName;
463
    }
464
465
    /**
466
     * @param string $originalName
467
     *
468
     * @return ResourceFile
469
     */
470
    public function setOriginalName($originalName): ResourceFile
471
    {
472
        $this->originalName = $originalName;
473
474
        return $this;
475
    }
476
477
    /**
478
     * @return array
479
     */
480
    public function getDimensions(): array
481
    {
482
        return $this->dimensions;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->dimensions returns the type string which is incompatible with the type-hinted return array.
Loading history...
483
    }
484
485
    /**
486
     * @param array $dimensions
487
     *
488
     * @return ResourceFile
489
     */
490
    public function setDimensions($dimensions): ResourceFile
491
    {
492
        $this->dimensions = $dimensions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $dimensions of type array is incompatible with the declared type string of property $dimensions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
493
494
        return $this;
495
    }
496
497
    /**
498
     * @return int
499
     */
500
    public function getWidth(): int
501
    {
502
        $data = $this->getDimensions();
503
504
        if ($data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
505
            $data = explode(',', $data);
506
507
            return (int) $data[0];
508
        }
509
510
        return 0;
511
    }
512
513
    /**
514
     * @return int
515
     */
516
    public function getHeight(): int
517
    {
518
        $data = $this->getDimensions();
519
520
        if ($data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
521
            $data = explode(',', $data);
522
523
            return (int) $data[1];
524
        }
525
526
        return 0;
527
    }
528
529
    /**
530
     * @return File
531
     */
532
    public function getFile(): ?File
533
    {
534
        return $this->file;
535
    }
536
537
    /**
538
     * @param File|UploadedFile $file
539
     */
540
    public function setFile(File $file = null): void
541
    {
542
        $this->file = $file;
543
544
        if (null !== $file) {
545
            // It is required that at least one field changes if you are using doctrine
546
            // otherwise the event listeners won't be called and the file is lost
547
            $this->updatedAt = new \DateTimeImmutable();
0 ignored issues
show
Bug Best Practice introduced by
The property updatedAt does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
548
        }
549
    }
550
}
551