vendor/roothirsch/core-bundle/Translation/Entity/TranslationUnit.php line 56

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\CoreBundle\Translation\Entity;
  3. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use ApiPlatform\Core\Annotation\ApiSubresource;
  10. use ApiPlatform\Core\Annotation\ApiFilter;
  11. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  12. /**
  13. * @ORM\Entity
  14. * @ORM\Table(name="translation_unit")
  15. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  16. * @ApiResource(
  17. * shortName="Translation/Unit",
  18. * itemOperations={
  19. * "get",
  20. * "put",
  21. * "delete",
  22. * "translate"={
  23. * "route_name": "api_translation_units_translate_item",
  24. * "method"="put",
  25. * "requirements"={"id"="[a-z0-9\-]+", "language"="[a-z]+"},
  26. * "swagger_context" = {
  27. * "parameters" = {
  28. * {
  29. * "name" = "id",
  30. * "in" = "path",
  31. * "required" = "true",
  32. * "type" = "string"
  33. * },
  34. * {
  35. * "name" = "language",
  36. * "in" = "path",
  37. * "required" = "true",
  38. * "type" = "string"
  39. * }
  40. * }
  41. * }
  42. * }
  43. * },
  44. * collectionOperations={
  45. * "get"
  46. * },
  47. * attributes={
  48. * "pagination_enabled"=true
  49. * }
  50. * )
  51. * @ApiFilter(SearchFilter::class, strategy="partial", properties={"scope.namespace": "exact", "language.languageKey": "exact", "translationKey": "partial"})
  52. */
  53. class TranslationUnit
  54. {
  55. /**
  56. * @ORM\Id
  57. * @ORM\GeneratedValue
  58. * @ORM\Column(type="integer")
  59. */
  60. private $id;
  61. /**
  62. * @var string
  63. * @ORM\Column(name="translation_key",type="text",length=255)
  64. * @Assert\NotBlank()
  65. */
  66. private $key;
  67. /**
  68. * @ORM\Column(name="translation_value",type="text", nullable=true)
  69. * @var string
  70. */
  71. private $value;
  72. /**
  73. * @var string
  74. * @ORM\Column(name="note",type="text", nullable=true)
  75. */
  76. private $note;
  77. /**
  78. * @var string
  79. * @ORM\Column(name="context",type="text", nullable=true)
  80. */
  81. private $context;
  82. /**
  83. * The DateTime of the creation date
  84. * @ORM\Column(type="datetime")
  85. * @var \DateTime $created
  86. * @Gedmo\Timestampable(on="create")
  87. */
  88. private $created;
  89. /**
  90. * The DateTime of the creation date
  91. * @ORM\Column(type="datetime",nullable=true)
  92. * @var \DateTime $created
  93. * @Gedmo\Timestampable(on="update")
  94. */
  95. private $lastModified;
  96. /**
  97. * The DateTime of the deletion date
  98. * @ORM\Column(type="datetime",nullable=true)
  99. * @var \DateTime $created
  100. */
  101. private $deletedAt;
  102. /**
  103. * @ORM\ManyToOne(targetEntity="Roothirsch\CoreBundle\Translation\Entity\TranslationUnit", inversedBy="translations", cascade={"persist"}, fetch="EAGER")
  104. * @var TranslationUnit
  105. */
  106. private $source;
  107. /**
  108. * @var ArrayCollection
  109. * @ORM\OneToMany(targetEntity="Roothirsch\CoreBundle\Translation\Entity\TranslationUnit", mappedBy="source", cascade={"persist", "remove"}, orphanRemoval=true)
  110. */
  111. private $translations;
  112. /**
  113. * @ORM\ManyToOne(targetEntity="Roothirsch\CoreBundle\Translation\Entity\TranslationScope", inversedBy="translations", fetch="EAGER")
  114. * @ApiSubresource
  115. * @var Scope
  116. */
  117. private $scope;
  118. /**
  119. * @ORM\ManyToOne(targetEntity="Roothirsch\CoreBundle\Translation\Entity\Language", fetch="EAGER", cascade={"remove"})
  120. * @ORM\JoinColumn(onDelete="CASCADE")
  121. * @var Language
  122. * @ApiSubresource
  123. */
  124. private $language;
  125. /**
  126. * @var bool
  127. * @ORM\Column(type="boolean")
  128. */
  129. private $complete = false;
  130. public function __construct()
  131. {
  132. $this->translations = new ArrayCollection();
  133. }
  134. /**
  135. * @return string
  136. */
  137. public function getId()
  138. {
  139. return $this->id;
  140. }
  141. /**
  142. * @param string $id
  143. */
  144. public function setId($id)
  145. {
  146. $this->id = $id;
  147. }
  148. /**
  149. * @return string
  150. */
  151. public function getKey()
  152. {
  153. return $this->key;
  154. }
  155. /**
  156. * @param string $key
  157. */
  158. public function setKey($key)
  159. {
  160. $this->key = $key;
  161. }
  162. /**
  163. * @return string
  164. */
  165. public function getValue()
  166. {
  167. return $this->value;
  168. }
  169. /**
  170. * @param string $value
  171. */
  172. public function setValue($value)
  173. {
  174. $this->value = $value;
  175. }
  176. /**
  177. * @return string
  178. */
  179. public function getNote()
  180. {
  181. return $this->note;
  182. }
  183. /**
  184. * @param string $note
  185. */
  186. public function setNote($note)
  187. {
  188. $this->note = $note;
  189. }
  190. /**
  191. * @return \DateTime
  192. */
  193. public function getCreated()
  194. {
  195. return $this->created;
  196. }
  197. /**
  198. * @param \DateTime $created
  199. */
  200. public function setCreated($created)
  201. {
  202. $this->created = $created;
  203. }
  204. /**
  205. * @return \DateTime
  206. */
  207. public function getLastModified()
  208. {
  209. return $this->lastModified;
  210. }
  211. /**
  212. * @param \DateTime $lastModified
  213. */
  214. public function setLastModified($lastModified)
  215. {
  216. $this->lastModified = $lastModified;
  217. }
  218. /**
  219. * @return \DateTime
  220. */
  221. public function getDeletedAt()
  222. {
  223. return $this->deletedAt;
  224. }
  225. /**
  226. * @param \DateTime $deletedAt
  227. */
  228. public function setDeletedAt($deletedAt)
  229. {
  230. $this->deletedAt = $deletedAt;
  231. }
  232. /**
  233. * @return Scope
  234. */
  235. public function getScope()
  236. {
  237. return $this->scope;
  238. }
  239. /**
  240. * @param Scope $scope
  241. */
  242. public function setScope($scope)
  243. {
  244. $this->scope = $scope;
  245. }
  246. /**
  247. * @return Language
  248. */
  249. public function getLanguage()
  250. {
  251. return $this->language;
  252. }
  253. /**
  254. * @param Language $language
  255. */
  256. public function setLanguage($language)
  257. {
  258. $this->language = $language;
  259. }
  260. /**
  261. * @return TranslationUnit
  262. */
  263. public function getSource()
  264. {
  265. return $this->source;
  266. }
  267. /**
  268. * @param TranslationUnit $source
  269. */
  270. public function setSource($source)
  271. {
  272. $this->source = $source;
  273. $source->getTranslations()->add($this);
  274. }
  275. /**
  276. * @return mixed
  277. */
  278. public function getTranslations()
  279. {
  280. return $this->translations;
  281. }
  282. /**
  283. * @return mixed
  284. */
  285. public function getTranslationFor($language)
  286. {
  287. if ($this->getLanguage() == $language || $this->getLanguage()->getLanguageKey() == $language) {
  288. return $this->getValue();
  289. }
  290. foreach ($this->translations as $translation) {
  291. if ($translation->getLanguage() == $language || $translation->getLanguage()->getLanguageKey() == $language) {
  292. return $translation->getValue();
  293. }
  294. }
  295. }
  296. /**
  297. * @param mixed $translations
  298. */
  299. public function setTranslations($translations)
  300. {
  301. $this->translations = $translations;
  302. }
  303. /**
  304. * @param TranslationUnit $translationUnit
  305. */
  306. public function addTranslation($translationUnit)
  307. {
  308. $this->translations->add($translationUnit);
  309. }
  310. /**
  311. * @return string
  312. */
  313. public function getContext()
  314. {
  315. return $this->context;
  316. }
  317. /**
  318. * @param string $context
  319. */
  320. public function setContext($context)
  321. {
  322. $this->context = $context;
  323. }
  324. /**
  325. * @return bool
  326. */
  327. public function isComplete(): bool
  328. {
  329. return $this->complete;
  330. }
  331. /**
  332. * @param bool $complete
  333. */
  334. public function setComplete(bool $complete): void
  335. {
  336. $this->complete = $complete;
  337. }
  338. }