1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Bukashk0zzzLiipImagineSerializationBundle |
5
|
|
|
* |
6
|
|
|
* (c) Denis Golubovskiy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bukashk0zzz\LiipImagineSerializationBundle\Tests\Fixtures; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\Mapping as ORM; |
15
|
|
|
use Doctrine\Common\Persistence\Proxy; |
16
|
|
|
use JMS\Serializer\Annotation as JMS; |
17
|
|
|
use Vich\UploaderBundle\Mapping\Annotation as Vich; |
18
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
19
|
|
|
use Bukashk0zzz\LiipImagineSerializationBundle\Annotation as Bukashk0zzz; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* UserPhotos Entity |
23
|
|
|
* |
24
|
|
|
* @ORM\Table(name="userPhotos") |
25
|
|
|
* @ORM\Entity() |
26
|
|
|
* |
27
|
|
|
* @JMS\ExclusionPolicy("all") |
28
|
|
|
* |
29
|
|
|
* @Vich\Uploadable |
30
|
|
|
* @Bukashk0zzz\LiipImagineSerializableClass |
31
|
|
|
*/ |
32
|
|
View Code Duplication |
class UserPhotos implements Proxy |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @ORM\ManyToOne(targetEntity="Bukashk0zzz\LiipImagineSerializationBundle\Tests\Fixtures\User", inversedBy="photos") |
36
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="id") |
37
|
|
|
*/ |
38
|
|
|
protected $user; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @ORM\Column(type="integer") |
42
|
|
|
*/ |
43
|
|
|
protected $userId; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string $coverUrl Cover url |
47
|
|
|
* |
48
|
|
|
* @ORM\Column(type="string", length=255) |
49
|
|
|
* |
50
|
|
|
* @JMS\Expose |
51
|
|
|
* @JMS\SerializedName("cover") |
52
|
|
|
* |
53
|
|
|
* @Bukashk0zzz\LiipImagineSerializableField(filter={"big", "small"}) |
54
|
|
|
*/ |
55
|
|
|
public $coverUrl; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string $imageUrl Image url |
59
|
|
|
* |
60
|
|
|
* @ORM\Column(type="string", length=255) |
61
|
|
|
* |
62
|
|
|
* @JMS\Expose |
63
|
|
|
* @JMS\SerializedName("image") |
64
|
|
|
* |
65
|
|
|
* @Bukashk0zzz\LiipImagineSerializableField(filter="thumb_filter", virtualField="image_thumb") |
66
|
|
|
*/ |
67
|
|
|
public $imageUrl; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string $photoName Photo name |
71
|
|
|
* |
72
|
|
|
* @ORM\Column(type="string", length=255) |
73
|
|
|
* |
74
|
|
|
* @JMS\Expose |
75
|
|
|
* @JMS\SerializedName("photo") |
76
|
|
|
* |
77
|
|
|
* @Bukashk0zzz\LiipImagineSerializableField(filter={"thumb_big", "thumb_small"}, vichUploaderField="photoFile", virtualField="photoThumb") |
78
|
|
|
*/ |
79
|
|
|
public $photoName; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var File $photoFile Photo file |
83
|
|
|
* |
84
|
|
|
* @JMS\Exclude |
85
|
|
|
* |
86
|
|
|
* @Vich\UploadableField(mapping="user_photo_mapping", fileNameProperty="photoName") |
87
|
|
|
*/ |
88
|
|
|
public $photoFile; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var bool |
92
|
|
|
*/ |
93
|
|
|
private $status = false; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @inheritdoc |
97
|
|
|
*/ |
98
|
|
|
public function __load() |
99
|
|
|
{ |
100
|
|
|
$this->setCoverUrl(__DIR__.'/test.png'); |
101
|
|
|
$this->setPhotoName('/uploads/photo.jpg'); |
102
|
|
|
$this->status = true; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @inheritdoc |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
public function __isInitialized() |
110
|
|
|
{ |
111
|
|
|
return $this->status; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* To string |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function __toString() |
120
|
|
|
{ |
121
|
|
|
return 'New Photo'; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set userId |
126
|
|
|
* |
127
|
|
|
* @param integer $userId |
128
|
|
|
* |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
|
|
public function setUserId($userId) |
132
|
|
|
{ |
133
|
|
|
$this->userId = $userId; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Get userId |
140
|
|
|
* |
141
|
|
|
* @return integer |
142
|
|
|
*/ |
143
|
|
|
public function getUserId() |
144
|
|
|
{ |
145
|
|
|
return $this->userId; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set user |
150
|
|
|
* |
151
|
|
|
* @param User $user |
152
|
|
|
* |
153
|
|
|
* @return $this |
154
|
|
|
*/ |
155
|
|
|
public function setUser(User $user = null) |
156
|
|
|
{ |
157
|
|
|
$this->user = $user; |
158
|
|
|
|
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Get user |
164
|
|
|
* |
165
|
|
|
* @return User |
166
|
|
|
*/ |
167
|
|
|
public function getUser() |
168
|
|
|
{ |
169
|
|
|
return $this->user; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
|
|
public function getCoverUrl() |
176
|
|
|
{ |
177
|
|
|
return $this->coverUrl; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $coverUrl |
182
|
|
|
* @return $this |
183
|
|
|
*/ |
184
|
|
|
public function setCoverUrl($coverUrl) |
185
|
|
|
{ |
186
|
|
|
$this->coverUrl = $coverUrl; |
187
|
|
|
|
188
|
|
|
return $this; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
|
|
public function getImageUrl() |
195
|
|
|
{ |
196
|
|
|
return $this->imageUrl; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param string $imageUrl |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
|
|
public function setImageUrl($imageUrl) |
204
|
|
|
{ |
205
|
|
|
$this->imageUrl = $imageUrl; |
206
|
|
|
|
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return mixed |
212
|
|
|
*/ |
213
|
|
|
public function getPhotoName() |
214
|
|
|
{ |
215
|
|
|
return $this->photoName; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param mixed $photoName |
220
|
|
|
* @return $this |
221
|
|
|
*/ |
222
|
|
|
public function setPhotoName($photoName) |
223
|
|
|
{ |
224
|
|
|
$this->photoName = $photoName; |
225
|
|
|
|
226
|
|
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @return File |
231
|
|
|
*/ |
232
|
|
|
public function getPhotoFile() |
233
|
|
|
{ |
234
|
|
|
return $this->photoFile; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param File $photoFile |
239
|
|
|
* @return $this |
240
|
|
|
*/ |
241
|
|
|
public function setPhotoFile($photoFile) |
242
|
|
|
{ |
243
|
|
|
$this->photoFile = $photoFile; |
244
|
|
|
|
245
|
|
|
return $this; |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.