src/Entity/Application/Banner.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Application;
  3. use App\Repository\Application\BannerRepository;
  4. use JMS\Serializer\Annotation as Serializer;
  5. use App\Entity\User;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Entity\Behaviors\TranslatableTrait;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13. * @ORM\Table(name="app_banner")
  14. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  15. * @ORM\Entity(repositoryClass=BannerRepository::class)
  16. * @Vich\Uploadable()
  17. */
  18. class Banner implements TranslatableInterface
  19. {
  20. use TranslatableTrait;
  21. /**
  22. * @ORM\Id
  23. * @ORM\GeneratedValue
  24. * @ORM\Column(type="integer")
  25. */
  26. private $id;
  27. /**
  28. * @Serializer\Groups({"api"})
  29. * @Serializer\SerializedName("dateFrom")
  30. * @ORM\Column(type="datetime")
  31. */
  32. private $dateFrom;
  33. /**
  34. * @Serializer\Groups({"api"})
  35. * @Serializer\SerializedName("dateTo")
  36. * @ORM\Column(type="datetime")
  37. */
  38. private $dateTo;
  39. /**
  40. * @Vich\UploadableField(mapping="banner_image", fileNameProperty="image")
  41. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  42. * @var File|null
  43. */
  44. private $imageFile;
  45. /**
  46. * @Serializer\Groups({"api"})
  47. * @Serializer\SerializedName("image")
  48. *
  49. * @ORM\Column(type="string", length=255, nullable=true)
  50. */
  51. private $image;
  52. /**
  53. * @ORM\Column(type="boolean")
  54. */
  55. private $isActive;
  56. /**
  57. * @ORM\Column(type="boolean", nullable=true)
  58. * @Serializer\Groups({"api"})
  59. * @Serializer\SerializedName("hideDates")
  60. */
  61. private $hideDates = false;
  62. /**
  63. * @Serializer\Groups({"api"})
  64. * @Serializer\SerializedName("orderBy")
  65. * @ORM\Column(type="integer", nullable=true)
  66. */
  67. private $orderBy;
  68. /**
  69. * @ORM\Column(type="datetime")
  70. */
  71. private $createts;
  72. /**
  73. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  74. * @ORM\JoinColumn(nullable=true)
  75. */
  76. private $createUser;
  77. /**
  78. * @ORM\Column(type="datetime", nullable=true)
  79. */
  80. private $editts;
  81. /**
  82. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  83. */
  84. private $editUser;
  85. /**
  86. * @Serializer\VirtualProperty()
  87. * @Serializer\Groups({"api"})
  88. * @Serializer\Inline()
  89. */
  90. public function getVirtualName()
  91. {
  92. return $this->translate();
  93. }
  94. public function __construct() {
  95. $this->setDateFrom(new \DateTime());
  96. $this->setDateTo(new \DateTime());
  97. }
  98. public function checkCollections($locales): void
  99. {
  100. foreach ( $locales as $locale ) {
  101. if($this->getTranslations()->get($locale) === null){
  102. $this->translate($locale)->setName(' ');
  103. }
  104. }
  105. $this->mergeNewTranslations();
  106. }
  107. public function getId(): ?int
  108. {
  109. return $this->id;
  110. }
  111. /**
  112. * Get DateFrom
  113. *
  114. * @return mixed
  115. */
  116. public function getDateFrom()
  117. {
  118. return $this->dateFrom;
  119. }
  120. /**
  121. * Set DateFrom
  122. *
  123. * @param mixed $dateFrom
  124. */
  125. public function setDateFrom( $dateFrom )
  126. {
  127. $this->dateFrom = $dateFrom;
  128. }
  129. /**
  130. * Get DateTo
  131. *
  132. * @return mixed
  133. */
  134. public function getDateTo()
  135. {
  136. return $this->dateTo;
  137. }
  138. /**
  139. * Set DateTo
  140. *
  141. * @param mixed $dateTo
  142. */
  143. public function setDateTo( $dateTo ): void
  144. {
  145. $this->dateTo = $dateTo;
  146. }
  147. public function getImage(): ?string
  148. {
  149. return $this->image;
  150. }
  151. public function setImage(?string $image): self
  152. {
  153. $this->image = $image;
  154. return $this;
  155. }
  156. public function getIsActive(): ?bool
  157. {
  158. return $this->isActive;
  159. }
  160. public function setIsActive(bool $isActive): self
  161. {
  162. $this->isActive = $isActive;
  163. return $this;
  164. }
  165. public function getCreatets(): ?\DateTimeInterface
  166. {
  167. return $this->createts;
  168. }
  169. public function setCreatets(\DateTimeInterface $createts): self
  170. {
  171. $this->createts = $createts;
  172. return $this;
  173. }
  174. public function getCreateUser(): ?User
  175. {
  176. return $this->createUser;
  177. }
  178. public function setCreateUser(?User $createUser): self
  179. {
  180. $this->createUser = $createUser;
  181. return $this;
  182. }
  183. public function getEditts(): ?\DateTimeInterface
  184. {
  185. return $this->editts;
  186. }
  187. public function setEditts(?\DateTimeInterface $editts): self
  188. {
  189. $this->editts = $editts;
  190. return $this;
  191. }
  192. public function getEditUser(): ?User
  193. {
  194. return $this->editUser;
  195. }
  196. public function setEditUser(?User $editUser): self
  197. {
  198. $this->editUser = $editUser;
  199. return $this;
  200. }
  201. public function __call($method, $arguments)
  202. {
  203. $ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
  204. if(empty($ret)) {
  205. $ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
  206. }
  207. return $ret;
  208. }
  209. /**
  210. * Get ImageFile
  211. *
  212. * @return null|File
  213. */
  214. public function getImageFile(): ?File
  215. {
  216. return $this->imageFile;
  217. }
  218. /**
  219. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  220. */
  221. public function setImageFile(?File $imageFile = null): void
  222. {
  223. $this->imageFile = $imageFile;
  224. if (null !== $imageFile) {
  225. $this->editts = new \DateTime();
  226. }
  227. }
  228. /**
  229. * Get OrderBy
  230. *
  231. * @return mixed
  232. */
  233. public function getOrderBy()
  234. {
  235. return $this->orderBy;
  236. }
  237. /**
  238. * Set OrderBy
  239. *
  240. * @param mixed $orderBy
  241. */
  242. public function setOrderBy( $orderBy )
  243. {
  244. $this->orderBy = $orderBy;
  245. }
  246. /**
  247. * @return bool
  248. */
  249. public function isHideDates(): bool
  250. {
  251. return $this->hideDates;
  252. }
  253. /**
  254. * @param bool $hideDates
  255. */
  256. public function setHideDates(bool $hideDates): void
  257. {
  258. $this->hideDates = $hideDates;
  259. }
  260. }