-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAlbum.php
289 lines (252 loc) · 4.97 KB
/
Album.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
namespace FOQ\AlbumBundle\Document;
use FOS\UserBundle\Model\User;
use FOQ\AlbumBundle\Model\AlbumInterface;
use FOQ\AlbumBundle\Model\PhotoCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use DateTime;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\MappedSuperclass
*/
abstract class Album implements AlbumInterface
{
/**
* User who owns this album
* You must overwrite this mapping to set the target document to your user class
*
* @var User
*/
protected $user = null;
/**
* Photos in the album
*
* @var Collection
* You must overwrite this mapping to set the target document to your user class
* // mongodb:ReferenceMany(targetDocument="Photo")
*/
protected $photos = null;
/**
* End of abstract mappings
*/
/**
* Document id
*
* @var string
* @MongoDB\Id()
*/
protected $id = null;
/**
* Album slug
*
* @var string
* @MongoDB\Field(type="string")
* @gedmo:Slug
*/
protected $slug = null;
/**
* Album title
*
* @var string
* @MongoDB\Field(type="string")
* @gedmo:Sluggable
*/
protected $title = null;
/**
* Album description
*
* @var string
* @MongoDB\Field(type="string")
*/
protected $description = null;
/**
* Number of photos in the album
*
* @var int
* @MongoDB\Field(type="int")
*/
protected $count = 0;
/**
* Whether or not the album is visible
*
* @var bool
* @MongoDB\Field(type="boolean")
*/
protected $published = false;
/**
* Number of times the album has been displayed
*
* @var int
* @MongoDB\Field(type="int")
*/
protected $impressions = 0;
/**
* @MongoDB\Field(type="date")
*/
protected $createdAt;
/**
* @MongoDB\Field(type="date")
*/
protected $updatedAt;
/**
* Date of first publication
*
* @var DateTime
* @MongoDB\Field(type="date")
*/
protected $publishedAt = null;
public function __construct()
{
$this->photos = new ArrayCollection();
$this->createdAt = new DateTime();
}
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param string
* @return null
*/
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string
* @return null
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string
* @return null
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return bool
*/
public function getIsPublished()
{
return $this->published;
}
/**
* @param bool
* @return null
*/
public function setIsPublished($published)
{
$this->published = $published;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @param User
* @return null
*/
public function setUser(User $user)
{
$this->user = $user;
}
/**
* @return PhotoCollection
*/
public function getPhotos()
{
return new PhotoCollection($this->photos ?: $this->photos = new ArrayCollection());
}
/**
* Gets number of photos
*
* @return int
**/
public function getCount()
{
return $this->count;
}
/**
* Update number of photos
*
* @return null
**/
public function updateCount()
{
$this->count = $this->getPhotos()->count();
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @return DateTime
*/
public function getPublishedAt()
{
return $this->publishedAt;
}
/**
* @param DateTime
* @return null
*/
public function setPublishedAt(DateTime $publishedAt)
{
$this->publishedAt = $publishedAt;
}
public function setUpdatedNow()
{
$this->updatedAt = new DateTime();
}
/**
* @return int number of impressions
*/
public function getImpressions()
{
return $this->impressions;
}
/**
* Increment the number of page impressions
*/
public function incrementImpressions()
{
$this->impressions++;
}
}