]> Raphaël G. Git Repositories - treebundle/blob - Entity/Album.php
Version 0.0.6
[treebundle] / Entity / Album.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys TreeBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
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 Rapsys\TreeBundle\Entity;
13
14 use Doctrine\Common\Collections\Collection;
15 use Doctrine\Common\Collections\ArrayCollection;
16 use Doctrine\ORM\Event\PreUpdateEventArgs;
17
18 /**
19 * Album
20 */
21 class Album {
22 /**
23 * @var int
24 */
25 private ?int $id;
26
27 /**
28 * @var \DateTime
29 */
30 private \DateTime $created;
31
32 /**
33 * @var \DateTime
34 */
35 private \DateTime $updated;
36
37 /**
38 * @var \Doctrine\Common\Collections\Collection
39 */
40 private Collection $resources;
41
42 /**
43 * Constructor
44 *
45 * @param string $path The album path
46 * @param string $slug The album slug
47 * @param string $title The album title
48 */
49 public function __construct(private string $path, private string $slug, private string $title) {
50 //Set defaults
51 $this->created = new \DateTime('now');
52 $this->updated = new \DateTime('now');
53
54 //Set collections
55 $this->resources = new ArrayCollection();
56 }
57
58 /**
59 * Get id
60 *
61 * @return ?int
62 */
63 public function getId(): ?int {
64 return $this->id;
65 }
66
67 /**
68 * Set path
69 *
70 * @param string $path
71 *
72 * @return Album
73 */
74 public function setPath(string $path): Album {
75 $this->path = $path;
76
77 return $this;
78 }
79
80 /**
81 * Get path
82 *
83 * @return string
84 */
85 public function getPath(): string {
86 return $this->path;
87 }
88
89 /**
90 * Set slug
91 *
92 * @param string $slug
93 *
94 * @return Album
95 */
96 public function setSlug(string $slug): Album {
97 $this->slug = $slug;
98
99 return $this;
100 }
101
102 /**
103 * Get slug
104 *
105 * @return string
106 */
107 public function getSlug(): string {
108 return $this->slug;
109 }
110
111 /**
112 * Set title
113 *
114 * @param string $title
115 *
116 * @return Album
117 */
118 public function setTitle(string $title): Album {
119 $this->title = $title;
120
121 return $this;
122 }
123
124 /**
125 * Get title
126 *
127 * @return string
128 */
129 public function getTitle(): string {
130 return $this->title;
131 }
132
133 /**
134 * Set created
135 *
136 * @param \DateTime $created
137 *
138 * @return Album
139 */
140 public function setCreated(\DateTime $created): Album {
141 $this->created = $created;
142
143 return $this;
144 }
145
146 /**
147 * Get created
148 *
149 * @return \DateTime
150 */
151 public function getCreated(): \DateTime {
152 return $this->created;
153 }
154
155 /**
156 * Set updated
157 *
158 * @param \DateTime $updated
159 *
160 * @return Album
161 */
162 public function setUpdated(\DateTime $updated): Album {
163 $this->updated = $updated;
164
165 return $this;
166 }
167
168 /**
169 * Get updated
170 *
171 * @return \DateTime
172 */
173 public function getUpdated(): \DateTime {
174 return $this->updated;
175 }
176
177 /**
178 * Add resource
179 *
180 * @param Resource $resource
181 *
182 * @return User
183 */
184 public function addResource(Resource $resource): User {
185 $this->resources[] = $resource;
186
187 return $this;
188 }
189
190 /**
191 * Remove resource
192 *
193 * @param Resource $resource
194 *
195 * @return \Doctrine\Common\Collections\Collection
196 */
197 public function removeResource(Resource $resource): Collection {
198 return $this->resources->removeElement($resource);
199 }
200
201 /**
202 * Get resources
203 *
204 * @return \Doctrine\Common\Collections\Collection
205 */
206 public function getResources(): Collection {
207 return $this->resources;
208 }
209
210 /**
211 * {@inheritdoc}
212 */
213 public function preUpdate(PreUpdateEventArgs $eventArgs): ?Album {
214 //Check that we have an snippet instance
215 if (($entity = $eventArgs->getEntity()) instanceof Album) {
216 //Set updated value
217 return $entity->setUpdated(new \DateTime('now'));
218 }
219 }
220 }