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