vendor/sulu/sulu/src/Sulu/Bundle/CategoryBundle/Entity/CategoryTranslation.php line 21

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Sulu.
  4. *
  5. * (c) Sulu GmbH
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Sulu\Bundle\CategoryBundle\Entity;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Sulu\Component\Security\Authentication\UserInterface;
  14. /**
  15. * CategoryTranslation.
  16. */
  17. class CategoryTranslation implements CategoryTranslationInterface
  18. {
  19. /**
  20. * @var string
  21. */
  22. protected $translation;
  23. /**
  24. * @var string|null
  25. */
  26. protected $description;
  27. /**
  28. * @var Collection<int, CategoryTranslationMedia>
  29. */
  30. protected $medias;
  31. /**
  32. * @var string
  33. */
  34. protected $locale;
  35. /**
  36. * @var int
  37. */
  38. protected $id;
  39. /**
  40. * @var CategoryInterface
  41. */
  42. protected $category;
  43. /**
  44. * @var UserInterface|null
  45. */
  46. protected $creator;
  47. /**
  48. * @var UserInterface|null
  49. */
  50. protected $changer;
  51. /**
  52. * @var \DateTime
  53. */
  54. protected $created;
  55. /**
  56. * @var \DateTime
  57. */
  58. protected $changed;
  59. /**
  60. * @var Collection<int, KeywordInterface>
  61. */
  62. protected $keywords;
  63. public function __construct()
  64. {
  65. $this->keywords = new ArrayCollection();
  66. $this->medias = new ArrayCollection();
  67. }
  68. public function setTranslation($translation)
  69. {
  70. $this->translation = $translation;
  71. return $this;
  72. }
  73. public function getTranslation()
  74. {
  75. return $this->translation;
  76. }
  77. /**
  78. * @return string|null
  79. */
  80. public function getDescription()
  81. {
  82. return $this->description;
  83. }
  84. public function setDescription($description)
  85. {
  86. $this->description = $description;
  87. return $this;
  88. }
  89. public function getMedias()
  90. {
  91. $medias = [];
  92. foreach ($this->medias as $media) {
  93. $medias[$media->getPosition()] = $media->getMedia();
  94. }
  95. \ksort($medias);
  96. return \array_values($medias);
  97. }
  98. public function setMedias($medias)
  99. {
  100. $position = 0;
  101. foreach ($this->medias as $media) {
  102. $mediaEntity = $medias[$position] ?? null;
  103. ++$position;
  104. if (!$mediaEntity) {
  105. $this->medias->removeElement($media);
  106. continue;
  107. }
  108. $media->setMedia($mediaEntity);
  109. $media->setPosition($position);
  110. }
  111. for (; $position < \count($medias); ++$position) {
  112. $media = new CategoryTranslationMedia($this, $medias[$position], $position + 1);
  113. $this->medias->add($media);
  114. }
  115. }
  116. public function setLocale($locale)
  117. {
  118. $this->locale = $locale;
  119. return $this;
  120. }
  121. public function getLocale()
  122. {
  123. return $this->locale;
  124. }
  125. public function getId()
  126. {
  127. return $this->id;
  128. }
  129. public function setCategory(CategoryInterface $category)
  130. {
  131. $this->category = $category;
  132. return $this;
  133. }
  134. public function getCategory()
  135. {
  136. return $this->category;
  137. }
  138. public function getCreator()
  139. {
  140. return $this->creator;
  141. }
  142. public function setCreator($creator)
  143. {
  144. $this->creator = $creator;
  145. }
  146. public function getChanger()
  147. {
  148. return $this->changer;
  149. }
  150. public function setChanger($changer)
  151. {
  152. $this->changer = $changer;
  153. }
  154. public function getCreated()
  155. {
  156. return $this->created;
  157. }
  158. public function setCreated($created)
  159. {
  160. $this->created = $created;
  161. }
  162. public function getChanged()
  163. {
  164. return $this->changed;
  165. }
  166. public function setChanged($changed)
  167. {
  168. $this->changed = $changed;
  169. }
  170. public function addKeyword(KeywordInterface $keyword)
  171. {
  172. $this->keywords[] = $keyword;
  173. return $this;
  174. }
  175. public function removeKeyword(KeywordInterface $keyword)
  176. {
  177. $this->keywords->removeElement($keyword);
  178. }
  179. public function getKeywords()
  180. {
  181. return $this->keywords;
  182. }
  183. public function hasKeyword(KeywordInterface $keyword)
  184. {
  185. return $this->keywords->exists(
  186. function($key, KeywordInterface $element) use ($keyword) {
  187. return $element->equals($keyword);
  188. }
  189. );
  190. }
  191. }