]> Raphaël G. Git Repositories - treebundle/blob - Entity/Album.php
Remove document route
[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 $assets;
41
42 /**
43 * Constructor
44 *
45 * @param string $path The album path
46 * @param string $slug The album slug
47 */
48 public function __construct(private string $path, private string $slug) {
49 //Set defaults
50 $this->created = new \DateTime('now');
51 $this->updated = new \DateTime('now');
52
53 //Set collections
54 $this->assets = new ArrayCollection();
55 }
56
57 /**
58 * Get id
59 *
60 * @return ?int
61 */
62 public function getId(): ?int {
63 return $this->id;
64 }
65
66 /**
67 * Set path
68 *
69 * @param string $path
70 *
71 * @return Album
72 */
73 public function setPath(string $path): Album {
74 $this->path = $path;
75
76 return $this;
77 }
78
79 /**
80 * Get path
81 *
82 * @return string
83 */
84 public function getPath(): string {
85 return $this->path;
86 }
87
88 /**
89 * Set slug
90 *
91 * @param string $slug
92 *
93 * @return Album
94 */
95 public function setSlug(string $slug): Album {
96 $this->slug = $slug;
97
98 return $this;
99 }
100
101 /**
102 * Get slug
103 *
104 * @return string
105 */
106 public function getSlug(): string {
107 return $this->slug;
108 }
109
110 /**
111 * Set created
112 *
113 * @param \DateTime $created
114 *
115 * @return Album
116 */
117 public function setCreated(\DateTime $created): Album {
118 $this->created = $created;
119
120 return $this;
121 }
122
123 /**
124 * Get created
125 *
126 * @return \DateTime
127 */
128 public function getCreated(): \DateTime {
129 return $this->created;
130 }
131
132 /**
133 * Set updated
134 *
135 * @param \DateTime $updated
136 *
137 * @return Album
138 */
139 public function setUpdated(\DateTime $updated): Album {
140 $this->updated = $updated;
141
142 return $this;
143 }
144
145 /**
146 * Get updated
147 *
148 * @return \DateTime
149 */
150 public function getUpdated(): \DateTime {
151 return $this->updated;
152 }
153
154 /**
155 * Add asset
156 *
157 * @param Asset $asset
158 *
159 * @return User
160 */
161 public function addAsset(Asset $asset): User {
162 $this->assets[] = $asset;
163
164 return $this;
165 }
166
167 /**
168 * Remove asset
169 *
170 * @param Asset $asset
171 *
172 * @return \Doctrine\Common\Collections\Collection
173 */
174 public function removeAsset(Asset $asset): Collection {
175 return $this->assets->removeElement($asset);
176 }
177
178 /**
179 * Get assets
180 *
181 * @return \Doctrine\Common\Collections\Collection
182 */
183 public function getAssets(): Collection {
184 return $this->assets;
185 }
186
187 /**
188 * {@inheritdoc}
189 */
190 public function preUpdate(PreUpdateEventArgs $eventArgs): ?Album {
191 //Check that we have an snippet instance
192 if (($entity = $eventArgs->getEntity()) instanceof Album) {
193 //Set updated value
194 return $entity->setUpdated(new \DateTime('now'));
195 }
196 }
197 }