Completed
Push — master ( 8578c1...3a76aa )
by Julito
09:38
created

ResourceFile::getCrop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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 string
210
     */
211
    public function __toString(): string
212
    {
213
        return (string) $this->getName();
214
    }
215
216
    /**
217
     * @return mixed
218
     */
219
    public function getName()
220
    {
221
        return $this->name;
222
    }
223
224
    /**
225
     * @param mixed $name
226
     *
227
     * @return ResourceFile
228
     */
229
    public function setName($name)
230
    {
231
        $this->name = $name;
232
233
        return $this;
234
    }
235
236
    /**
237
     * @return string
238
     */
239
    public function getCrop()
240
    {
241
        return $this->crop;
242
    }
243
244
    /**
245
     * @param string $crop
246
     *
247
     * @return $this
248
     */
249
    public function setCrop($crop)
250
    {
251
        $this->crop = $crop;
252
253
        return $this;
254
    }
255
256
    /**
257
     * @return string
258
     */
259
    public function getHash(): string
260
    {
261
        return $this->hash;
262
    }
263
264
    /**
265
     * @param string $hash
266
     *
267
     * @return ResourceFile
268
     */
269
    public function setHash(string $hash): ResourceFile
270
    {
271
        $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...
272
273
        return $this;
274
    }
275
276
    /**
277
     * @return string
278
     */
279
    public function getOriginalFilename(): string
280
    {
281
        return $this->originalFilename;
282
    }
283
284
    /**
285
     * @param string $originalFilename
286
     *
287
     * @return ResourceFile
288
     */
289
    public function setOriginalFilename(string $originalFilename): ResourceFile
290
    {
291
        $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...
292
293
        return $this;
294
    }
295
296
    /**
297
     * @return int
298
     */
299
    public function getSize(): int
300
    {
301
        return (int) $this->size;
302
    }
303
304
    /**
305
     * @param int $size
306
     *
307
     * @return ResourceFile
308
     */
309
    public function setSize($size): ResourceFile
310
    {
311
        $this->size = $size;
312
313
        return $this;
314
    }
315
316
    /**
317
     * @return string
318
     */
319
    public function getCopyright(): string
320
    {
321
        return (string) $this->copyright;
322
    }
323
324
    /**
325
     * @return string
326
     */
327
    public function getContentType(): string
328
    {
329
        return (string) $this->contentType;
330
    }
331
332
    /**
333
     * @param string $contentType
334
     *
335
     * @return ResourceFile
336
     */
337
    public function setContentType(string $contentType): ResourceFile
338
    {
339
        $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...
340
341
        return $this;
342
    }
343
344
    /**
345
     * @return string
346
     */
347
    public function getExtension(): string
348
    {
349
        return $this->extension;
350
    }
351
352
    /**
353
     * @param string $extension
354
     *
355
     * @return ResourceFile
356
     */
357
    public function setExtension(string $extension): ResourceFile
358
    {
359
        $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...
360
361
        return $this;
362
    }
363
364
    /**
365
     * @return ResourceNode
366
     */
367
    public function getResourceNode(): ResourceNode
368
    {
369
        return $this->resourceNode;
370
    }
371
372
    /**
373
     * @param ResourceNode $resourceNode
374
     *
375
     * @return ResourceFile
376
     */
377
    public function setResourceNode(ResourceNode $resourceNode): ResourceFile
378
    {
379
        $this->resourceNode = $resourceNode;
380
381
        return $this;
382
    }
383
384
    /**
385
     * @return bool
386
     */
387
    public function isEnabled(): bool
388
    {
389
        return $this->enabled;
390
    }
391
392
    /**
393
     * @param bool $enabled
394
     *
395
     * @return ResourceFile
396
     */
397
    public function setEnabled(bool $enabled): ResourceFile
398
    {
399
        $this->enabled = $enabled;
400
401
        return $this;
402
    }
403
404
    /**
405
     * @return mixed
406
     */
407
    public function getId()
408
    {
409
        return $this->id;
410
    }
411
412
    /**
413
     * @param mixed $id
414
     *
415
     * @return ResourceFile
416
     */
417
    public function setId($id)
418
    {
419
        $this->id = $id;
420
421
        return $this;
422
    }
423
424
    /**
425
     * @return string
426
     */
427
    public function getDescription(): string
428
    {
429
        return $this->description;
430
    }
431
432
    /**
433
     * @param string $description
434
     *
435
     * @return ResourceFile
436
     */
437
    public function setDescription(string $description): ResourceFile
438
    {
439
        $this->description = $description;
440
441
        return $this;
442
    }
443
444
    /**
445
     * @return string
446
     */
447
    public function getMimeType(): string
448
    {
449
        return $this->mimeType;
450
    }
451
452
    /**
453
     * @param string $mimeType
454
     *
455
     * @return ResourceFile
456
     */
457
    public function setMimeType($mimeType): ResourceFile
458
    {
459
        $this->mimeType = $mimeType;
460
461
        return $this;
462
    }
463
464
    /**
465
     * @return string
466
     */
467
    public function getOriginalName(): string
468
    {
469
        return $this->originalName;
470
    }
471
472
    /**
473
     * @param string $originalName
474
     *
475
     * @return ResourceFile
476
     */
477
    public function setOriginalName($originalName): ResourceFile
478
    {
479
        $this->originalName = $originalName;
480
481
        return $this;
482
    }
483
484
    /**
485
     * @return array
486
     */
487
    public function getDimensions(): array
488
    {
489
        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...
490
    }
491
492
    /**
493
     * @param array $dimensions
494
     *
495
     * @return ResourceFile
496
     */
497
    public function setDimensions($dimensions): ResourceFile
498
    {
499
        $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...
500
501
        return $this;
502
    }
503
504
    /**
505
     * @return int
506
     */
507
    public function getWidth(): int
508
    {
509
        $data = $this->getDimensions();
510
511
        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...
512
            $data = explode(',', $data);
513
514
            return (int) $data[0];
515
        }
516
517
        return 0;
518
    }
519
520
    /**
521
     * @return int
522
     */
523
    public function getHeight(): int
524
    {
525
        $data = $this->getDimensions();
526
527
        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...
528
            $data = explode(',', $data);
529
530
            return (int) $data[1];
531
        }
532
533
        return 0;
534
    }
535
536
    /**
537
     * @return File
538
     */
539
    public function getFile(): ?File
540
    {
541
        return $this->file;
542
    }
543
544
    /**
545
     * @param File|UploadedFile $file
546
     */
547
    public function setFile(File $file = null): void
548
    {
549
        $this->file = $file;
550
551
        if (null !== $file) {
552
            // It is required that at least one field changes if you are using doctrine
553
            // otherwise the event listeners won't be called and the file is lost
554
            $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...
555
        }
556
    }
557
}
558