src/Entity/Application/Offer.php line 24

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