]> Raphaël G. Git Repositories - blogbundle/blob - Entity/Article.php
Add pseudonym and slug translations
[blogbundle] / Entity / Article.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys BlogBundle 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\BlogBundle\Entity;
13
14 use Doctrine\Common\Collections\Collection;
15 use Doctrine\Common\Collections\ArrayCollection;
16 use Doctrine\ORM\Event\PreUpdateEventArgs;
17
18 /**
19 * Article
20 */
21 class Article {
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 \Rapsys\BlogBundle\Entity\User
39 */
40 private User $user;
41
42 /**
43 * @var \Doctrine\Common\Collections\Collection
44 */
45 private Collection $article_translations;
46
47 /**
48 * @var \Doctrine\Common\Collections\Collection
49 */
50 private Collection $keywords;
51
52 /**
53 * Constructor
54 *
55 * @param \Rapsys\BlogBundle\Entity\User $user
56 */
57 public function __construct(User $user) {
58 $this->created = new \DateTime('now');
59 $this->updated = new \DateTime('now');
60 $this->user = $user;
61 $this->article_translations = new ArrayCollection();
62 $this->keywords = new ArrayCollection();
63 }
64
65 /**
66 * Get id
67 *
68 * @return ?int
69 */
70 public function getId(): ?int {
71 return $this->id;
72 }
73
74 /**
75 * Set created
76 *
77 * @param \DateTime $created
78 *
79 * @return Article
80 */
81 public function setCreated(\DateTime $created): Article {
82 $this->created = $created;
83
84 return $this;
85 }
86
87 /**
88 * Get created
89 *
90 * @return \DateTime
91 */
92 public function getCreated(): \DateTime {
93 return $this->created;
94 }
95
96 /**
97 * Set updated
98 *
99 * @param \DateTime $updated
100 *
101 * @return Article
102 */
103 public function setUpdated(\DateTime $updated): Article {
104 $this->updated = $updated;
105
106 return $this;
107 }
108
109 /**
110 * Get updated
111 *
112 * @return \DateTime
113 */
114 public function getUpdated(): \DateTime {
115 return $this->updated;
116 }
117
118 /**
119 * Set user
120 *
121 * @param \Rapsys\BlogBundle\Entity\User $user
122 *
123 * @return Article
124 */
125 public function setUser(User $user): Article {
126 $this->user = $user;
127
128 return $this;
129 }
130
131 /**
132 * Get user
133 *
134 * @return \Rapsys\BlogBundle\Entity\User
135 */
136 public function getUser(): User {
137 return $this->user;
138 }
139
140 /**
141 * Add article translation
142 *
143 * @param \Rapsys\BlogBundle\Entity\ArticleTranslation $articleTranslation
144 *
145 * @return Article
146 */
147 public function addArticleTranslation(ArticleTranslation $articleTranslation): Article {
148 $this->article_translations[] = $articleTranslation;
149
150 return $this;
151 }
152
153 /**
154 * Remove article translation
155 *
156 * @param \Rapsys\BlogBundle\Entity\ArticleTranslation $articleTranslation
157 *
158 * @return \Doctrine\Common\Collections\Collection
159 */
160 public function removeArticleTranslation(ArticleTranslation $articleTranslation): Collection {
161 return $this->article_translations->removeElement($articleTranslation);
162 }
163
164 /**
165 * Get article translations
166 *
167 * @return \Doctrine\Common\Collections\Collection
168 */
169 public function getArticleTranslations(): Collection {
170 return $this->article_translations;
171 }
172
173 /**
174 * Add keyword
175 *
176 * @param \Rapsys\BlogBundle\Entity\Keyword $keyword
177 *
178 * @return Article
179 */
180 public function addKeyword(Keyword $keyword): Article {
181 $this->keywords[] = $keyword;
182
183 return $this;
184 }
185
186 /**
187 * Remove keyword
188 *
189 * @param \Rapsys\BlogBundle\Entity\Keyword $keyword
190 *
191 * @return \Doctrine\Common\Collections\Collection
192 */
193 public function removeKeyword(Keyword $keyword): Collection {
194 return $this->keywords->removeElement($keyword);
195 }
196
197 /**
198 * Get keywords
199 *
200 * @return \Doctrine\Common\Collections\Collection
201 */
202 public function getKeywords(): Collection {
203 return $this->keywords;
204 }
205
206 /**
207 * {@inheritdoc}
208 */
209 public function preUpdate(PreUpdateEventArgs $eventArgs): ?Article {
210 //Check that we have an snippet instance
211 if (($entity = $eventArgs->getEntity()) instanceof Article) {
212 //Set updated value
213 return $entity->setUpdated(new \DateTime('now'));
214 }
215 }
216 }