src/Entity/Web/CareerTranslation.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Web;
  3. use Doctrine\ORM\Event\LifecycleEventArgs;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Entity\Behaviors\TranslationTrait;
  6. use App\Entity\Behaviors\SluggableTrait;
  7. use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
  8. use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
  9. use Doctrine\ORM\Mapping\Index;
  10. /**
  11. * @ORM\Table(name="web_career_translation",uniqueConstraints={@ORM\UniqueConstraint(name="sluging", columns={"locale", "slug","randomint"})},
  12. * indexes={@Index(name="locale_slug", columns={"locale","slug","randomint"})})
  13. * @ORM\Entity(repositoryClass="App\Repository\TranslationRepository")
  14. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  15. */
  16. class CareerTranslation implements TranslationInterface, SluggableInterface
  17. {
  18. use TranslationTrait;
  19. use SluggableTrait;
  20. /**
  21. * @ORM\Column(type="string", length=2)
  22. */
  23. protected $locale;
  24. /**
  25. * @ORM\Column(type="string", length=255)
  26. */
  27. private string $name;
  28. /**
  29. * @ORM\Column(type="string", length=255)
  30. */
  31. private string $contactTime;
  32. /**
  33. * @ORM\Column(type="integer", nullable=true)
  34. */
  35. private ?int $randomint = null;
  36. /**
  37. * @ORM\Column(type="text")
  38. */
  39. private string $about = 'Vyplňte';
  40. /**
  41. * @ORM\Column(type="text")
  42. */
  43. private string $description = 'Vyplňte';
  44. /**
  45. * @ORM\Column(type="text", nullable=false)
  46. */
  47. private string $descriptionNeed = 'Vyplňte';
  48. /**
  49. * @ORM\Column(type="text", nullable=false)
  50. */
  51. private string $descriptionOffer = 'Vyplňte';
  52. /**
  53. * @ORM\Column(type="string", length=190)
  54. */
  55. protected $slug;
  56. /**
  57. * @ORM\Column(type="datetime")
  58. */
  59. private $createts;
  60. /**
  61. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  62. * @ORM\JoinColumn(nullable=false)
  63. */
  64. private $createUser;
  65. /**
  66. * @ORM\Column(type="datetime", nullable=true)
  67. */
  68. private $editts;
  69. /**
  70. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  71. */
  72. private $editUser;
  73. public function __construct($locale = null) {
  74. if($this->randomint === null){
  75. $this->randomint = time();
  76. }
  77. if($locale !== null){
  78. $this->setLocale($locale);
  79. }
  80. }
  81. public function getId(): ?int
  82. {
  83. return $this->id;
  84. }
  85. /**
  86. * @return string
  87. */
  88. public function getName(): string
  89. {
  90. return $this->name;
  91. }
  92. /**
  93. * @param string $name
  94. */
  95. public function setName(string $name): void
  96. {
  97. $this->name = $name;
  98. }
  99. /**
  100. * @return string
  101. */
  102. public function getDescription(): string
  103. {
  104. return $this->description;
  105. }
  106. /**
  107. * @param string $description
  108. */
  109. public function setDescription(string $description): void
  110. {
  111. $this->description = $description;
  112. }
  113. /**
  114. * @return string
  115. */
  116. public function getDescriptionNeed(): string
  117. {
  118. return $this->descriptionNeed;
  119. }
  120. /**
  121. * @param string $descriptionNeed
  122. */
  123. public function setDescriptionNeed(string $descriptionNeed): void
  124. {
  125. $this->descriptionNeed = $descriptionNeed;
  126. }
  127. /**
  128. * @return string
  129. */
  130. public function getDescriptionOffer(): string
  131. {
  132. return $this->descriptionOffer;
  133. }
  134. /**
  135. * @param string $descriptionOffer
  136. */
  137. public function setDescriptionOffer(string $descriptionOffer): void
  138. {
  139. $this->descriptionOffer = $descriptionOffer;
  140. }
  141. /**
  142. * @return string
  143. */
  144. public function getAbout(): string
  145. {
  146. return $this->about;
  147. }
  148. /**
  149. * @param string $about
  150. */
  151. public function setAbout(string $about): void
  152. {
  153. $this->about = $about;
  154. }
  155. /**
  156. * @return string
  157. */
  158. public function getContactTime(): string
  159. {
  160. return $this->contactTime;
  161. }
  162. /**
  163. * @param string $contactTime
  164. */
  165. public function setContactTime(string $contactTime): void
  166. {
  167. $this->contactTime = $contactTime;
  168. }
  169. /**
  170. * @return mixed
  171. */
  172. public function getCreatets()
  173. {
  174. return $this->createts;
  175. }
  176. /**
  177. * @param mixed $createts
  178. */
  179. public function setCreatets($createts): void
  180. {
  181. $this->createts = $createts;
  182. }
  183. /**
  184. * @return mixed
  185. */
  186. public function getCreateUser()
  187. {
  188. return $this->createUser;
  189. }
  190. /**
  191. * @param mixed $createUser
  192. */
  193. public function setCreateUser($createUser): void
  194. {
  195. $this->createUser = $createUser;
  196. }
  197. /**
  198. * @return mixed
  199. */
  200. public function getEditts()
  201. {
  202. return $this->editts;
  203. }
  204. /**
  205. * @param mixed $editts
  206. */
  207. public function setEditts($editts): void
  208. {
  209. $this->editts = $editts;
  210. }
  211. /**
  212. * @return mixed
  213. */
  214. public function getEditUser()
  215. {
  216. return $this->editUser;
  217. }
  218. /**
  219. * @param mixed $editUser
  220. */
  221. public function setEditUser($editUser): void
  222. {
  223. $this->editUser = $editUser;
  224. }
  225. public function getSluggableFields(): array
  226. {
  227. return ['name','randomint'];
  228. }
  229. /**
  230. * @ORM\PreUpdate()
  231. * @ORM\PrePersist()
  232. */
  233. public function updateSlug( LifecycleEventArgs $eventArgs )
  234. {
  235. $translatable = $this->getTranslatable();
  236. $oldSlug = $translatable->getSlug();
  237. if ( $this->getRegenerateSlugOnUpdate() || empty( $this->slug ) ) {
  238. $fields = $this->getSluggableFields();
  239. $values = [];
  240. foreach ( $fields as $field ) {
  241. if ( property_exists( $this, $field ) ) {
  242. $val = $this->{$field};
  243. } else {
  244. $methodName = 'get' . ucfirst( $field );
  245. if ( method_exists( $this, $methodName ) ) {
  246. $val = $this->{$methodName}();
  247. } else {
  248. $val = null;
  249. }
  250. }
  251. $values[] = $val;
  252. }
  253. $this->slug = $this->generateSlugValue( $values );
  254. if ( $oldSlug !== $this->slug ) {
  255. $repo = $eventArgs->getEntityManager()->getRepository( get_class( $this ) );
  256. $repo->updateSlug( $this );
  257. }
  258. }
  259. }
  260. public function getRandomint(): ?int
  261. {
  262. return $this->randomint;
  263. }
  264. public function setRandomint(?int $randomint): void
  265. {
  266. $this->randomint = $randomint;
  267. }
  268. }