Passed
Push — master ( 6b8b10...614334 )
by Stone
06:50 queued 10s
created

Image::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Entity;
4
5
use DateTimeImmutable;
6
use DateTimeInterface;
7
use Doctrine\ORM\Mapping as ORM;
8
use Exception;
9
use Symfony\Component\HttpFoundation\File\File;
10
use Symfony\Component\Validator\Constraints as Assert;
11
use Vich\UploaderBundle\Mapping\Annotation as Vich;
12
use Gedmo\Mapping\Annotation as Gedmo;
13
14
/**
15
 * @ORM\Entity(repositoryClass="App\Repository\ImageRepository")
16
 * @Vich\Uploadable
17
 */
18
class Image extends AbstractAppEntity
19
{
20
21
    /**
22
     * @ORM\Id()
23
     * @ORM\GeneratedValue()
24
     * @ORM\Column(type="integer")
25
     */
26
    private $id;
27
28
    /**
29
     * @ORM\Column(type="string", length=255, nullable=false)
30
     * @Assert\Length(
31
     *     min=5,
32
     *     max=255,
33
     *     minMessage = "Title must be at least {{ limit }} characters",
34
     *     maxMessage = "Title can not exceed {{ limit }} characters"
35
     * )
36
     */
37
    private $title;
38
39
    /**
40
     * @ORM\Column(type="string", length=255)
41
     */
42
    private $image;
43
44
    /**
45
     * @Assert\Image()
46
     * @Vich\UploadableField(mapping="trick_images", fileNameProperty="image")
47
     * @var File
48
     */
49
    private $imageFile;
50
51
    /**
52
     * @ORM\ManyToOne(targetEntity="App\Entity\Trick", inversedBy="images")
53
     */
54
    private $trick;
55
56
    /**
57
     * @ORM\Column(type="datetime")
58
     * @Gedmo\Timestampable(on="update")
59
     */
60
    private $updatedAt;
61
62
    /**
63
     * @ORM\Column(type="boolean")
64
     */
65
    private $primaryImage = false;
66
67
    public function getId(): ?int
68
    {
69
        return $this->id;
70
    }
71
72
    public function getTitle(): ?string
73
    {
74
        return $this->title;
75
    }
76
77
    public function setTitle(?string $title): self
78
    {
79
        $this->title = $title;
80
81
        return $this;
82
    }
83
84
    public function getImage(): ?string
85
    {
86
        return $this->image;
87
    }
88
89
    public function getWebImage(): ?string
90
    {
91
        return '/uploads/trick_images/' . $this->image;
92
    }
93
94
95
    public function setImage(?string $image): self
96
    {
97
        $this->image = $image;
98
99
        return $this;
100
    }
101
102
    public function getTrick(): ?Trick
103
    {
104
        return $this->trick;
105
    }
106
107
    public function setTrick(?Trick $trick): self
108
    {
109
        $this->trick = $trick;
110
111
        return $this;
112
    }
113
114
    public function getUpdatedAt(): ?DateTimeInterface
115
    {
116
        return $this->updatedAt;
117
    }
118
119
    public function setUpdatedAt(DateTimeInterface $updatedAt): self
120
    {
121
        $this->updatedAt = $updatedAt;
122
123
        return $this;
124
    }
125
126
    /**
127
     * @return null|File
128
     */
129
    public function getImageFile(): ?File
130
    {
131
        return $this->imageFile;
132
    }
133
134
    /**
135
     * @param File $imageFile
136
     * @return Image
137
     * @throws Exception
138
     */
139
    public function setImageFile(File $imageFile): Image
140
    {
141
        $this->imageFile = $imageFile;
142
        $this->updatedAt = new DateTimeImmutable();
143
144
        return $this;
145
    }
146
147
    public function __toString()
148
    {
149
        return $this->getTitle();
150
    }
151
152
    public function getPrimaryImage(): ?bool
153
    {
154
        return $this->primaryImage;
155
    }
156
157
    public function setPrimaryImage(bool $primaryImage): self
158
    {
159
        $this->primaryImage = $primaryImage;
160
161
        return $this;
162
    }
163
}
164