]> Raphaël G. Git Repositories - blogbundle/blob - Entity/Keyword.php
Add user translation entity
[blogbundle] / Entity / Keyword.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 * Keyword
20 */
21 class Keyword {
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 $keyword_translations;
41
42 /**
43 * @var \Doctrine\Common\Collections\Collection
44 */
45 private Collection $articles;
46
47 /**
48 * Constructor
49 */
50 public function __construct() {
51 $this->created = new \DateTime('now');
52 $this->updated = new \DateTime('now');
53 $this->keyword_translations = new ArrayCollection();
54 $this->articles = 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 created
68 *
69 * @param \DateTime $created
70 *
71 * @return Keyword
72 */
73 public function setCreated(\DateTime $created): Keyword {
74 $this->created = $created;
75
76 return $this;
77 }
78
79 /**
80 * Get created
81 *
82 * @return \DateTime
83 */
84 public function getCreated(): \DateTime {
85 return $this->created;
86 }
87
88 /**
89 * Set updated
90 *
91 * @param \DateTime $updated
92 *
93 * @return Keyword
94 */
95 public function setUpdated(\DateTime $updated): Keyword {
96 $this->updated = $updated;
97
98 return $this;
99 }
100
101 /**
102 * Get updated
103 *
104 * @return \DateTime
105 */
106 public function getUpdated(): \DateTime {
107 return $this->updated;
108 }
109
110 /**
111 * Add keywordTranslation
112 *
113 * @param \Rapsys\BlogBundle\Entity\KeywordTranslation $keywordTranslation
114 *
115 * @return Keyword
116 */
117 public function addKeywordTranslation(KeywordTranslation $keywordTranslation): Keyword {
118 $this->keyword_translations[] = $keywordTranslation;
119
120 return $this;
121 }
122
123 /**
124 * Remove keywordTranslation
125 *
126 * @param \Rapsys\BlogBundle\Entity\KeywordTranslation $keywordTranslation
127 *
128 * @return \Doctrine\Common\Collections\Collection
129 */
130 public function removeKeywordTranslation(KeywordTranslation $keywordTranslation): Collection {
131 return $this->keyword_translations->removeElement($keywordTranslation);
132 }
133
134 /**
135 * Get keywordTranslations
136 *
137 * @return \Doctrine\Common\Collections\Collection
138 */
139 public function getKeywordTranslations(): Collection {
140 return $this->keyword_translations;
141 }
142
143 /**
144 * Add article
145 *
146 * @param \Rapsys\BlogBundle\Entity\Article $article
147 *
148 * @return Keyword
149 */
150 public function addArticle(Article $article): Keyword {
151 $this->articles[] = $article;
152
153 return $this;
154 }
155
156 /**
157 * Remove article
158 *
159 * @param \Rapsys\BlogBundle\Entity\Article $article
160 *
161 * @return \Doctrine\Common\Collections\Collection
162 */
163 public function removeArticle(Article $article): Collection {
164 return $this->articles->removeElement($article);
165 }
166
167 /**
168 * Get articles
169 *
170 * @return \Doctrine\Common\Collections\Collection
171 */
172 public function getArticles(): Collection {
173 return $this->articles;
174 }
175
176 /**
177 * {@inheritdoc}
178 */
179 public function preUpdate(PreUpdateEventArgs $eventArgs): ?Keyword {
180 //Check that we have an snippet instance
181 if (($entity = $eventArgs->getEntity()) instanceof Keyword) {
182 //Set updated value
183 return $entity->setUpdated(new \DateTime('now'));
184 }
185 }
186 }