src/Entity/Application/Bonus.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Application;
  3. use App\Repository\Application\BonusRepository;
  4. use App\Entity\User;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Entity\Behaviors\TranslatableTrait;
  9. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use JMS\Serializer\Annotation as Serializer;
  14. /**
  15. * @ORM\Table(name="app_bonus",
  16. * uniqueConstraints={@ORM\UniqueConstraint(name="hash", columns={"hash"})}
  17. * )
  18. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  19. * @ORM\Entity(repositoryClass=BonusRepository::class)
  20. * @Vich\Uploadable()
  21. */
  22. class Bonus implements TranslatableInterface
  23. {
  24. use TranslatableTrait;
  25. /**
  26. * @ORM\Id
  27. * @ORM\GeneratedValue
  28. * @ORM\Column(type="integer")
  29. */
  30. private $id;
  31. /**
  32. * @Serializer\Groups({"api"})
  33. * @Serializer\SerializedName("price")
  34. * @ORM\Column(type="integer")
  35. */
  36. private $price;
  37. /**
  38. * @Serializer\Groups({"api"})
  39. * @Serializer\SerializedName("hash")
  40. * @ORM\Column(type="string", nullable=true, length=100)
  41. */
  42. private $hash;
  43. /**
  44. * @Serializer\Groups({"api"})
  45. * @Serializer\SerializedName("dateFrom")
  46. * @ORM\Column(type="datetime", nullable=true)
  47. */
  48. private $dateFrom;
  49. /**
  50. * @Serializer\Groups({"api"})
  51. * @Serializer\SerializedName("dateTo")
  52. * @ORM\Column(type="datetime", nullable=true)
  53. */
  54. private $dateTo;
  55. /**
  56. * @Serializer\Groups({"api"})
  57. * @Serializer\SerializedName("count")
  58. * @ORM\Column(type="integer", nullable=true)
  59. */
  60. private $count = 0;
  61. /**
  62. * @Serializer\Groups({"api"})
  63. * @Serializer\SerializedName("used")
  64. * @ORM\Column(type="integer", nullable=true)
  65. */
  66. private $used = 0;
  67. /**
  68. * @ORM\Column(type="boolean")
  69. */
  70. private $isActive;
  71. /**
  72. * @ORM\Column(type="datetime")
  73. */
  74. private $createts;
  75. /**
  76. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  77. * @ORM\JoinColumn(nullable=true)
  78. */
  79. private $createUser;
  80. /**
  81. * @ORM\Column(type="datetime", nullable=true)
  82. */
  83. private $editts;
  84. /**
  85. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  86. */
  87. private $editUser;
  88. /**
  89. * @Vich\UploadableField(mapping="store_qr", fileNameProperty="qr")
  90. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  91. * @var File|null
  92. */
  93. private $qrFile;
  94. /**
  95. * @ORM\Column(type="text", nullable=true)
  96. */
  97. private $qr;
  98. /**
  99. * @ORM\OneToMany(targetEntity=Points::class, mappedBy="bonus")
  100. */
  101. private $pointsHistory;
  102. /**
  103. * @Vich\UploadableField(mapping="bonus_image", fileNameProperty="image")
  104. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  105. * @var File|null
  106. */
  107. private $imageFile;
  108. /**
  109. * @Serializer\Groups({"api"})
  110. * @Serializer\SerializedName("image")
  111. * @ORM\Column(type="string", length=255, nullable=true)
  112. */
  113. private $image;
  114. public function __construct()
  115. {
  116. $this->pointsHistory = new ArrayCollection();
  117. }
  118. /**
  119. * @Serializer\VirtualProperty()
  120. * @Serializer\Groups({"api","pointsHistory"})
  121. * @Serializer\Inline()
  122. */
  123. public function getVirtualName()
  124. {
  125. return $this->translate();
  126. }
  127. public function checkCollections($locales): void
  128. {
  129. foreach ( $locales as $locale ) {
  130. if($this->getTranslations()->get($locale) === null){
  131. $this->translate($locale)->setName(' ');
  132. }
  133. }
  134. $this->mergeNewTranslations();
  135. }
  136. public function getId(): ?int
  137. {
  138. return $this->id;
  139. }
  140. public function getPrice(): ?int
  141. {
  142. return $this->price;
  143. }
  144. public function setPrice(int $price): self
  145. {
  146. $this->price = $price;
  147. return $this;
  148. }
  149. public function getDateFrom()
  150. {
  151. return $this->dateFrom;
  152. }
  153. public function setDateFrom( $dateFrom): self
  154. {
  155. $this->dateFrom = $dateFrom;
  156. return $this;
  157. }
  158. public function getDateTo()
  159. {
  160. return $this->dateTo;
  161. }
  162. public function setDateTo( $dateTo): self
  163. {
  164. $this->dateTo = $dateTo;
  165. return $this;
  166. }
  167. public function getCount(): ?int
  168. {
  169. return $this->count;
  170. }
  171. public function setCount(?int $count): self
  172. {
  173. $this->count = $count;
  174. return $this;
  175. }
  176. public function getIsActive(): ?bool
  177. {
  178. return $this->isActive;
  179. }
  180. public function setIsActive(bool $isActive): self
  181. {
  182. $this->isActive = $isActive;
  183. return $this;
  184. }
  185. public function getCreatets(): ?\DateTimeInterface
  186. {
  187. return $this->createts;
  188. }
  189. public function setCreatets(\DateTimeInterface $createts): self
  190. {
  191. $this->createts = $createts;
  192. return $this;
  193. }
  194. public function getCreateUser(): ?User
  195. {
  196. return $this->createUser;
  197. }
  198. public function setCreateUser(?User $createUser): self
  199. {
  200. $this->createUser = $createUser;
  201. return $this;
  202. }
  203. public function getEditts(): ?\DateTimeInterface
  204. {
  205. return $this->editts;
  206. }
  207. public function setEditts(?\DateTimeInterface $editts): self
  208. {
  209. $this->editts = $editts;
  210. return $this;
  211. }
  212. public function getEditUser(): ?User
  213. {
  214. return $this->editUser;
  215. }
  216. public function setEditUser(?User $editUser): self
  217. {
  218. $this->editUser = $editUser;
  219. return $this;
  220. }
  221. /**
  222. * Get Qr
  223. *
  224. * @return mixed
  225. */
  226. public function getQr()
  227. {
  228. return $this->qr;
  229. }
  230. /**
  231. * Set Qr
  232. *
  233. * @param mixed $qr
  234. */
  235. public function setQr( $qr )
  236. {
  237. $this->qr = $qr;
  238. }
  239. /**
  240. * Get QrFile
  241. *
  242. * @return null|File
  243. */
  244. public function getQrFile(): ?File
  245. {
  246. return $this->qrFile;
  247. }
  248. /**
  249. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $qrFile
  250. */
  251. public function setQrFile(?File $qrFile = null): void
  252. {
  253. $this->qrFile = $qrFile;
  254. if (null !== $qrFile) {
  255. $this->editts = new \DateTime();
  256. }
  257. }
  258. public function __call($method, $arguments)
  259. {
  260. $ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
  261. if(empty($ret)) {
  262. $ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
  263. }
  264. return $ret;
  265. }
  266. /**
  267. * Get Hash
  268. *
  269. * @return mixed
  270. */
  271. public function getHash()
  272. {
  273. return $this->hash;
  274. }
  275. /**
  276. * Set Hash
  277. *
  278. * @param mixed $hash
  279. */
  280. public function setHash( $hash )
  281. {
  282. $this->hash = $hash;
  283. }
  284. /**
  285. * @return Collection|Points[]
  286. */
  287. public function getPointsHistory(): Collection
  288. {
  289. return $this->pointsHistory;
  290. }
  291. public function addPointsHistory(Points $pointsHistory): self
  292. {
  293. if (!$this->pointsHistory->contains($pointsHistory)) {
  294. $this->pointsHistory[] = $pointsHistory;
  295. $pointsHistory->setBonus($this);
  296. }
  297. return $this;
  298. }
  299. public function removePointsHistory(Points $pointsHistory): self
  300. {
  301. if ($this->pointsHistory->removeElement($pointsHistory)) {
  302. // set the owning side to null (unless already changed)
  303. if ($pointsHistory->getBonus() === $this) {
  304. $pointsHistory->setBonus(null);
  305. }
  306. }
  307. return $this;
  308. }
  309. /**
  310. * Get Used
  311. *
  312. * @return mixed
  313. */
  314. public function getUsed()
  315. {
  316. return $this->used;
  317. }
  318. /**
  319. * Set Used
  320. *
  321. * @param mixed $used
  322. */
  323. public function setUsed( $used )
  324. {
  325. $this->used = $used;
  326. }
  327. /**
  328. * Get ImageFile
  329. *
  330. * @return null|File
  331. */
  332. public function getImageFile(): ?File
  333. {
  334. return $this->imageFile;
  335. }
  336. /**
  337. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  338. */
  339. public function setImageFile(?File $imageFile = null): void
  340. {
  341. $this->imageFile = $imageFile;
  342. if (null !== $imageFile) {
  343. $this->editts = new \DateTime();
  344. }
  345. }
  346. public function getImage(): ?string
  347. {
  348. return $this->image;
  349. }
  350. public function setImage(?string $image): self
  351. {
  352. $this->image = $image;
  353. return $this;
  354. }
  355. }