src/Entity/Application/Store.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Application;
  3. use App\Entity\Brand;
  4. use App\Entity\User;
  5. use App\Entity\Web\Career;
  6. use App\Repository\Application\StoreRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use JMS\Serializer\Annotation as Serializer;
  11. use App\Entity\Behaviors\TranslatableTrait;
  12. use App\Entity\Behaviors\SluggableTrait;
  13. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  14. use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
  15. use Symfony\Component\HttpFoundation\File\File;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  18. /**
  19. *
  20. * @ORM\Table(name="app_store",
  21. * uniqueConstraints={@ORM\UniqueConstraint(name="hash", columns={"hash"})}
  22. * )
  23. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  24. * @ORM\Entity(repositoryClass=StoreRepository::class)
  25. * @Vich\Uploadable()
  26. */
  27. class Store implements TranslatableInterface, SluggableInterface
  28. {
  29. public const DAY_LIMIT = 1;
  30. use SluggableTrait;
  31. use TranslatableTrait;
  32. /**
  33. * @ORM\Id
  34. * @ORM\GeneratedValue
  35. * @ORM\Column(type="integer")
  36. */
  37. private $id;
  38. /**
  39. * @ORM\Column(type="string", nullable=true, length=100)
  40. */
  41. private $hash;
  42. /**
  43. * @Vich\UploadableField(mapping="store_logo", fileNameProperty="logo")
  44. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  45. * @var File|null
  46. */
  47. private $logoFile;
  48. /**
  49. * @Serializer\Groups({"api"})
  50. * @Serializer\SerializedName("logo")
  51. * @ORM\Column(type="string", length=255, nullable=true)
  52. */
  53. private $logo;
  54. /**
  55. * @Vich\UploadableField(mapping="store_map_image", fileNameProperty="map")
  56. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  57. * @var File|null
  58. */
  59. private $mapFile;
  60. /**
  61. * @Serializer\Groups({"api"})
  62. * @Serializer\SerializedName("map")
  63. * @ORM\Column(type="string", length=255, nullable=true)
  64. */
  65. private $map;
  66. /**
  67. * @Vich\UploadableField(mapping="store_offer_image", fileNameProperty="offerImage")
  68. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  69. * @var File|null
  70. */
  71. private $offerImageFile;
  72. /**
  73. * @Serializer\Groups({"api"})
  74. * @Serializer\SerializedName("map")
  75. * @ORM\Column(type="string", length=255, nullable=true)
  76. */
  77. private $offerImage;
  78. /**
  79. * @Serializer\Groups({"api"})
  80. * @Serializer\SerializedName("email")
  81. * @ORM\Column(type="string", length=150, nullable=true)
  82. */
  83. private $email;
  84. /**
  85. * @Serializer\Groups({"api"})
  86. * @Serializer\SerializedName("web")
  87. * @ORM\Column(type="string", length=150, nullable=true)
  88. */
  89. private $web;
  90. /**
  91. * @Serializer\Groups({"api"})
  92. * @Serializer\SerializedName("shopNumber")
  93. * @ORM\Column(type="array",nullable=true)
  94. */
  95. private ?array $shopNumber;
  96. /**
  97. * @Serializer\Groups({"api"})
  98. * @Serializer\SerializedName("vip")
  99. * @ORM\Column(type="boolean")
  100. */
  101. private $vip;
  102. /**
  103. * @Serializer\Groups({"api"})
  104. * @Serializer\SerializedName("vipDiscount")
  105. * @ORM\Column(type="integer")
  106. */
  107. private $vipDiscount = 10;
  108. /**
  109. * @ORM\Column(type="date",nullable=true)
  110. */
  111. private $vipEndDate;
  112. /**
  113. * @ORM\Column(type="integer")
  114. */
  115. private $points = 5;
  116. /**
  117. * @Vich\UploadableField(mapping="store_image", fileNameProperty="image")
  118. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  119. * @var File|null
  120. */
  121. private $imageFile;
  122. /**
  123. * @Serializer\Groups({"api"})
  124. * @Serializer\SerializedName("image")
  125. * @ORM\Column(type="string", length=255, nullable=true)
  126. */
  127. private $image;
  128. /**
  129. * @Serializer\Groups({"api"})
  130. * @Serializer\SerializedName("phone")
  131. * @ORM\Column(type="string", length=100, nullable=true)
  132. */
  133. private $phone;
  134. /**
  135. * @Serializer\Groups({"api"})
  136. * @Serializer\SerializedName("firstName")
  137. * @ORM\Column(type="string", length=100, nullable=true)
  138. */
  139. private $firstName;
  140. /**
  141. * @Serializer\Groups({"api"})
  142. * @Serializer\SerializedName("lastName")
  143. * @ORM\Column(type="string", length=100, nullable=true)
  144. */
  145. private $lastName;
  146. /**
  147. * @ORM\Column(type="array", nullable=true)
  148. */
  149. private $openHours = [];
  150. /**
  151. * @Serializer\Groups({"api","pointsHistory"})
  152. * @Serializer\SerializedName("name")
  153. * @ORM\Column(type="string", length=150)
  154. */
  155. private $name;
  156. /**
  157. * @ORM\Column(type="boolean")
  158. */
  159. private $isActive = true;
  160. /**
  161. * @ORM\Column(type="datetime")
  162. */
  163. private $createts;
  164. /**
  165. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  166. * @ORM\JoinColumn(nullable=true)
  167. */
  168. private $createUser;
  169. /**
  170. * @ORM\Column(type="datetime", nullable=true)
  171. */
  172. private $editts;
  173. /**
  174. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  175. */
  176. private $editUser;
  177. /**
  178. * @Vich\UploadableField(mapping="store_qr", fileNameProperty="qr")
  179. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  180. * @var File|null
  181. */
  182. private $qrFile;
  183. /**
  184. * @ORM\Column(type="text", nullable=true)
  185. */
  186. private $qr;
  187. /**
  188. * @Serializer\Groups({"api"})
  189. * @Serializer\SerializedName("categories")
  190. * @ORM\ManyToMany(targetEntity="App\Entity\Application\Category", inversedBy="stores")
  191. * @ORM\JoinTable(name="app_store_category")
  192. */
  193. private $category;
  194. /**
  195. * @ORM\ManyToMany(targetEntity="App\Entity\Brand", inversedBy="stores")
  196. * @ORM\JoinTable(name="app_store_brands")
  197. */
  198. private $brands;
  199. /**
  200. * @ORM\OneToMany(targetEntity=Offer::class, mappedBy="store")
  201. */
  202. private $offers;
  203. /**
  204. * @ORM\OneToMany(targetEntity=Career::class, mappedBy="store")
  205. */
  206. private $careers;
  207. /**
  208. * @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="stores")
  209. */
  210. private $users;
  211. /**
  212. * @ORM\OneToMany(targetEntity=Points::class, mappedBy="store")
  213. */
  214. private $pointsHistory;
  215. /**
  216. * @ORM\OneToMany(targetEntity="App\Entity\Application\StoreImage", mappedBy="store", cascade={"persist", "remove"}, orphanRemoval=true)
  217. * @ORM\OrderBy({"orderBy" = "ASC"})
  218. */
  219. private $storeImages;
  220. /**
  221. * @Serializer\VirtualProperty()
  222. * @Serializer\Groups({"api"})
  223. * @Serializer\Inline()
  224. */
  225. public function getVirtualName()
  226. {
  227. return $this->translate();
  228. }
  229. /**
  230. * @Serializer\VirtualProperty()
  231. * @Serializer\Groups({"api"})
  232. * @Serializer\SerializedName("openHours")
  233. */
  234. public function getVirtualOpenHoursToday()
  235. {
  236. return implode(' - ', $this->getOpenHours()[date('N') - 1]);
  237. }
  238. public function __construct()
  239. {
  240. $this->offers = new ArrayCollection();
  241. $this->pointsHistory = new ArrayCollection();
  242. $this->category = new ArrayCollection();
  243. $this->brands = new ArrayCollection();
  244. $this->users = new ArrayCollection();
  245. $this->careers = new ArrayCollection();
  246. $this->storeImages = new ArrayCollection();
  247. }
  248. public function checkCollections($locales)
  249. {
  250. foreach ($locales as $locale) {
  251. if ($this->getTranslations()->get($locale) === null) {
  252. $this->translate($locale)->setDescription(' ');
  253. }
  254. }
  255. $this->mergeNewTranslations();
  256. }
  257. public function getId(): ?int
  258. {
  259. return $this->id;
  260. }
  261. public function getLogo(): ?string
  262. {
  263. return $this->logo;
  264. }
  265. public function setLogo(?string $logo): self
  266. {
  267. $this->logo = $logo;
  268. return $this;
  269. }
  270. public function getEmail(): ?string
  271. {
  272. return $this->email;
  273. }
  274. public function setEmail(?string $email): self
  275. {
  276. $this->email = $email;
  277. return $this;
  278. }
  279. public function getWeb(): ?string
  280. {
  281. return $this->web;
  282. }
  283. public function setWeb(?string $web): self
  284. {
  285. $this->web = $web;
  286. return $this;
  287. }
  288. public function getVip(): ?bool
  289. {
  290. return $this->vip;
  291. }
  292. public function setVip(bool $vip): self
  293. {
  294. $this->vip = $vip;
  295. return $this;
  296. }
  297. public function getPoints(): ?int
  298. {
  299. return $this->points;
  300. }
  301. public function setPoints(int $points): self
  302. {
  303. $this->points = $points;
  304. return $this;
  305. }
  306. public function getImage(): ?string
  307. {
  308. return $this->image;
  309. }
  310. public function setImage(?string $image): self
  311. {
  312. $this->image = $image;
  313. return $this;
  314. }
  315. public function getPhone(): ?string
  316. {
  317. return $this->phone;
  318. }
  319. public function setPhone(?string $phone): self
  320. {
  321. $this->phone = $phone;
  322. return $this;
  323. }
  324. public function getFirstName(): ?string
  325. {
  326. return $this->firstName;
  327. }
  328. public function setFirstName(?string $firstName): self
  329. {
  330. $this->firstName = $firstName;
  331. return $this;
  332. }
  333. public function getLastName(): ?string
  334. {
  335. return $this->lastName;
  336. }
  337. public function setLastName(?string $lastName): self
  338. {
  339. $this->lastName = $lastName;
  340. return $this;
  341. }
  342. public function getOpenHours(): ?array
  343. {
  344. return $this->openHours;
  345. }
  346. public function setOpenHours(?array $openHours): self
  347. {
  348. $this->openHours = $openHours;
  349. return $this;
  350. }
  351. public function getName(): ?string
  352. {
  353. return $this->name;
  354. }
  355. public function setName(string $name): self
  356. {
  357. $this->name = $name;
  358. return $this;
  359. }
  360. public function getCreatets(): ?\DateTimeInterface
  361. {
  362. return $this->createts;
  363. }
  364. public function setCreatets(\DateTimeInterface $createts): self
  365. {
  366. $this->createts = $createts;
  367. return $this;
  368. }
  369. public function getCreateUser(): ?User
  370. {
  371. return $this->createUser;
  372. }
  373. public function setCreateUser(?User $createUser): self
  374. {
  375. $this->createUser = $createUser;
  376. return $this;
  377. }
  378. public function getEditts(): ?\DateTimeInterface
  379. {
  380. return $this->editts;
  381. }
  382. public function setEditts(?\DateTimeInterface $editts): self
  383. {
  384. $this->editts = $editts;
  385. return $this;
  386. }
  387. public function getEditUser(): ?User
  388. {
  389. return $this->editUser;
  390. }
  391. public function setEditUser(?User $editUser): self
  392. {
  393. $this->editUser = $editUser;
  394. return $this;
  395. }
  396. public function __call($method, $arguments)
  397. {
  398. $ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
  399. if (empty($ret)) {
  400. $ret = call_user_func_array([$this->translate(\Locale::getDefault()), $method], $arguments);
  401. }
  402. return $ret;
  403. }
  404. /**
  405. * Get LogoFile
  406. *
  407. * @return null|File
  408. */
  409. public function getLogoFile(): ?File
  410. {
  411. return $this->logoFile;
  412. }
  413. /**
  414. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $logoFile
  415. */
  416. public function setLogoFile(?File $logoFile = null): void
  417. {
  418. $this->logoFile = $logoFile;
  419. if (null !== $logoFile) {
  420. $this->editts = new \DateTime();
  421. }
  422. }
  423. /**
  424. * Get ImageFile
  425. *
  426. * @return null|File
  427. */
  428. public function getImageFile(): ?File
  429. {
  430. return $this->imageFile;
  431. }
  432. /**
  433. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  434. */
  435. public function setImageFile(?File $imageFile = null): void
  436. {
  437. $this->imageFile = $imageFile;
  438. if (null !== $imageFile) {
  439. $this->editts = new \DateTime();
  440. }
  441. }
  442. /**
  443. * @return Collection|Category[]
  444. */
  445. public function getCategory(): Collection
  446. {
  447. return $this->category;
  448. }
  449. public function addCategory(Category $category): self
  450. {
  451. if (!$this->category->contains($category)) {
  452. $this->category[] = $category;
  453. $category->addStore($this);
  454. }
  455. return $this;
  456. }
  457. public function removeCategory(Category $category): self
  458. {
  459. if ($this->category->contains($category)) {
  460. $this->category->removeElement($category);
  461. $category->removeStore($this);
  462. }
  463. return $this;
  464. }
  465. /**
  466. * @return Collection|Brand[]
  467. */
  468. public function getBrands(): Collection
  469. {
  470. return $this->brands;
  471. }
  472. public function addBrand(Brand $brand): self
  473. {
  474. if (!$this->brands->contains($brand)) {
  475. $this->brands[] = $brand;
  476. $brand->addStore($this);
  477. }
  478. return $this;
  479. }
  480. public function removeBrand(Brand $brand): self
  481. {
  482. if ($this->brands->contains($brand)) {
  483. $this->brands->removeElement($brand);
  484. $brand->removeStore($this);
  485. }
  486. return $this;
  487. }
  488. /**
  489. * Get Qr
  490. *
  491. * @return mixed
  492. */
  493. public function getQr()
  494. {
  495. return $this->qr;
  496. }
  497. /**
  498. * Set Qr
  499. *
  500. * @param mixed $qr
  501. */
  502. public function setQr($qr)
  503. {
  504. $this->qr = $qr;
  505. }
  506. /**
  507. * Get QrFile
  508. *
  509. * @return null|File
  510. */
  511. public function getQrFile(): ?File
  512. {
  513. return $this->qrFile;
  514. }
  515. /**
  516. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $qrFile
  517. */
  518. public function setQrFile(?File $qrFile = null): void
  519. {
  520. $this->qrFile = $qrFile;
  521. if (null !== $qrFile) {
  522. $this->editts = new \DateTime();
  523. }
  524. }
  525. public function getActiveOffers(): Collection
  526. {
  527. return $this->getOffers()->filter(function (Offer $offer) {
  528. return $offer->getIsActive() && $offer->getIsPublic();
  529. });
  530. }
  531. /**
  532. * @return Collection|Offer[]
  533. */
  534. public function getOffers(): Collection
  535. {
  536. return $this->offers;
  537. }
  538. public function addOffer(Offer $offer): self
  539. {
  540. if (!$this->offers->contains($offer)) {
  541. $this->offers[] = $offer;
  542. $offer->setStore($this);
  543. }
  544. return $this;
  545. }
  546. public function removeOffer(Offer $offer): self
  547. {
  548. if ($this->offers->removeElement($offer)) {
  549. // set the owning side to null (unless already changed)
  550. if ($offer->getStore() === $this) {
  551. $offer->setStore(null);
  552. }
  553. }
  554. return $this;
  555. }
  556. /**
  557. * @return Collection|Career[]
  558. */
  559. public function getCareers(): Collection
  560. {
  561. return $this->careers;
  562. }
  563. public function addCareer(Career $career): self
  564. {
  565. if (!$this->careers->contains($career)) {
  566. $this->careers[] = $career;
  567. $career->setStore($this);
  568. }
  569. return $this;
  570. }
  571. public function removeCareer(Career $career): self
  572. {
  573. if ($this->careers->removeElement($career)) {
  574. // set the owning side to null (unless already changed)
  575. if ($career->getStore() === $this) {
  576. $career->setStore(null);
  577. }
  578. }
  579. return $this;
  580. }
  581. /**
  582. * Get Hash
  583. *
  584. * @return mixed
  585. */
  586. public function getHash()
  587. {
  588. return $this->hash;
  589. }
  590. /**
  591. * Set Hash
  592. *
  593. * @param mixed $hash
  594. */
  595. public function setHash($hash)
  596. {
  597. $this->hash = $hash;
  598. }
  599. /**
  600. * Get isActive
  601. *
  602. * @return mixed
  603. */
  604. public function getisActive()
  605. {
  606. return $this->isActive;
  607. }
  608. /**
  609. * Set IsActive
  610. *
  611. * @param mixed $isActive
  612. */
  613. public function setIsActive($isActive)
  614. {
  615. $this->isActive = $isActive;
  616. }
  617. /**
  618. * @return Collection|Points[]
  619. */
  620. public function getPointsHistory(): Collection
  621. {
  622. return $this->pointsHistory;
  623. }
  624. public function addPointsHistory(Points $pointsHistory): self
  625. {
  626. if (!$this->pointsHistory->contains($pointsHistory)) {
  627. $this->pointsHistory[] = $pointsHistory;
  628. $pointsHistory->setStore($this);
  629. }
  630. return $this;
  631. }
  632. public function removePointsHistory(Points $pointsHistory): self
  633. {
  634. if ($this->pointsHistory->removeElement($pointsHistory)) {
  635. // set the owning side to null (unless already changed)
  636. if ($pointsHistory->getStore() === $this) {
  637. $pointsHistory->setStore(null);
  638. }
  639. }
  640. return $this;
  641. }
  642. /**
  643. * Get VipDiscount
  644. *
  645. * @return mixed
  646. */
  647. public function getVipDiscount()
  648. {
  649. return $this->vipDiscount;
  650. }
  651. /**
  652. * Set VipDiscount
  653. *
  654. * @param mixed $vipDiscount
  655. */
  656. public function setVipDiscount($vipDiscount)
  657. {
  658. $this->vipDiscount = $vipDiscount;
  659. }
  660. /**
  661. * @return Collection|User[]
  662. */
  663. public function getUsers(): Collection
  664. {
  665. return $this->users;
  666. }
  667. public function addUser(User $user): self
  668. {
  669. if (!$this->users->contains($user)) {
  670. $this->users[] = $user;
  671. }
  672. return $this;
  673. }
  674. public function removeUser(User $user): self
  675. {
  676. if ($this->users->contains($user)) {
  677. $this->users->removeElement($user);
  678. }
  679. return $this;
  680. }
  681. /**
  682. * @return null|array
  683. */
  684. public function getShopNumber(): ?array
  685. {
  686. return $this->shopNumber;
  687. }
  688. /**
  689. * @param null|array $shopNumber
  690. */
  691. public function setShopNumber(?array $shopNumber): void
  692. {
  693. $this->shopNumber = $shopNumber;
  694. }
  695. /**
  696. * @return Collection|StoreImage[]
  697. */
  698. public function getStoreImages(): Collection
  699. {
  700. return $this->storeImages;
  701. }
  702. public function addStoreImage(StoreImage $storeImage): self
  703. {
  704. if (!$this->storeImages->contains($storeImage)) {
  705. $this->storeImages[] = $storeImage;
  706. $storeImage->setStore($this);
  707. }
  708. return $this;
  709. }
  710. public function removeStoreImage(StoreImage $storeImage): self
  711. {
  712. if ($this->storeImages->contains($storeImage)) {
  713. $this->storeImages->removeElement($storeImage);
  714. // set the owning side to null (unless already changed)
  715. if ($storeImage->getStore() === $this) {
  716. $storeImage->setStore(null);
  717. }
  718. }
  719. return $this;
  720. }
  721. /**
  722. * @return mixed
  723. */
  724. public function getVipEndDate()
  725. {
  726. if ($this->vipEndDate === null) {
  727. $this->vipEndDate = new \DateTime('last day of December this year');
  728. }
  729. return $this->vipEndDate;
  730. }
  731. /**
  732. * @param mixed $vipEndDate
  733. */
  734. public function setVipEndDate($vipEndDate): void
  735. {
  736. $this->vipEndDate = $vipEndDate;
  737. }
  738. /**
  739. * Get Map
  740. *
  741. * @return mixed
  742. */
  743. public function getMap()
  744. {
  745. return $this->map;
  746. }
  747. /**
  748. * Set Map
  749. *
  750. * @param mixed $map
  751. */
  752. public function setMap($map)
  753. {
  754. $this->map = $map;
  755. }
  756. /**
  757. * Get mapFile
  758. *
  759. * @return null|File
  760. */
  761. public function getMapFile(): ?File
  762. {
  763. return $this->mapFile;
  764. }
  765. /**
  766. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $mapFile
  767. */
  768. public function setMapFile(?File $mapFile = null): void
  769. {
  770. $this->mapFile = $mapFile;
  771. if (null !== $mapFile) {
  772. $this->editts = new \DateTime();
  773. }
  774. }
  775. /**
  776. * Get mapFile
  777. *
  778. * @return null|File
  779. */
  780. public function getOfferImageFile(): ?File
  781. {
  782. return $this->offerImageFile;
  783. }
  784. /**
  785. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $offerImage
  786. */
  787. public function setOfferImageFile(?File $offerImage = null): void
  788. {
  789. $this->offerImageFile = $offerImage;
  790. if (null !== $offerImage) {
  791. $this->editts = new \DateTime();
  792. }
  793. }
  794. /**
  795. * @return mixed
  796. */
  797. public function getOfferImage()
  798. {
  799. return $this->offerImage;
  800. }
  801. /**
  802. * @param mixed $offerImage
  803. */
  804. public function setOfferImage($offerImage): void
  805. {
  806. $this->offerImage = $offerImage;
  807. }
  808. public function getSluggableFields(): array
  809. {
  810. return ['name'];
  811. }
  812. }