src/Entity/Web/TopCategory.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Web;
  3. use App\Entity\Application\Offer;
  4. use App\Entity\User;
  5. use App\Repository\Web\TopCategoryRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Entity\Behaviors\TranslatableTrait;
  9. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  10. use Doctrine\Common\Collections\Collection;
  11. use JMS\Serializer\Annotation as Serializer;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16. * @ORM\Table(name="web_category")
  17. * @ORM\Entity(repositoryClass=TopCategoryRepository::class)
  18. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  19. * @Vich\Uploadable()
  20. */
  21. class TopCategory implements TranslatableInterface
  22. {
  23. use TranslatableTrait;
  24. /**
  25. * @ORM\Id
  26. * @ORM\GeneratedValue
  27. * @Serializer\Groups({"api"})
  28. * @Serializer\SerializedName("id")
  29. * @ORM\Column(type="integer")
  30. */
  31. private $id;
  32. /**
  33. * @Serializer\Groups({"api"})
  34. * @Serializer\SerializedName("orderBy")
  35. * @ORM\Column(type="integer")
  36. */
  37. private $orderBy;
  38. /**
  39. * @ORM\Column(type="datetime")
  40. */
  41. private $createts;
  42. /**
  43. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  44. * @ORM\JoinColumn(nullable=true)
  45. */
  46. private $createUser;
  47. /**
  48. * @ORM\Column(type="datetime", nullable=true)
  49. */
  50. private $editts;
  51. /**
  52. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  53. */
  54. private $editUser;
  55. /**
  56. * @Vich\UploadableField(mapping="category", fileNameProperty="image")
  57. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  58. * @var File|null
  59. */
  60. private $imageFile;
  61. /**
  62. * @ORM\Column(type="string", length=255, nullable=true)
  63. */
  64. private $image;
  65. /**
  66. * @ORM\OneToMany(targetEntity=Offer::class, mappedBy="topCategory")
  67. */
  68. private $offers;
  69. /**
  70. * @Serializer\VirtualProperty()
  71. * @Serializer\Groups({"api"})
  72. * @Serializer\Inline()
  73. */
  74. public function getVirtualName()
  75. {
  76. return $this->translate();
  77. }
  78. public function __construct()
  79. {
  80. $this->stores = new ArrayCollection();
  81. $this->offers = new ArrayCollection();
  82. }
  83. public function checkCollections($locales){
  84. foreach ( $locales as $locale ) {
  85. if($this->getTranslations()->get($locale) === null){
  86. $this->translate($locale)->setName(' ');
  87. }
  88. }
  89. $this->mergeNewTranslations();
  90. }
  91. public function getId(): ?int
  92. {
  93. return $this->id;
  94. }
  95. public function getOrderBy(): ?int
  96. {
  97. return $this->orderBy;
  98. }
  99. public function setOrderBy(int $orderBy): self
  100. {
  101. $this->orderBy = $orderBy;
  102. return $this;
  103. }
  104. public function getCreatets(): ?\DateTimeInterface
  105. {
  106. return $this->createts;
  107. }
  108. public function setCreatets(\DateTimeInterface $createts): self
  109. {
  110. $this->createts = $createts;
  111. return $this;
  112. }
  113. public function getCreateUser(): ?User
  114. {
  115. return $this->createUser;
  116. }
  117. public function setCreateUser(?User $createUser): self
  118. {
  119. $this->createUser = $createUser;
  120. return $this;
  121. }
  122. public function getEditts(): ?\DateTimeInterface
  123. {
  124. return $this->editts;
  125. }
  126. public function setEditts(?\DateTimeInterface $editts): self
  127. {
  128. $this->editts = $editts;
  129. return $this;
  130. }
  131. public function getEditUser(): ?User
  132. {
  133. return $this->editUser;
  134. }
  135. public function setEditUser(?User $editUser): self
  136. {
  137. $this->editUser = $editUser;
  138. return $this;
  139. }
  140. public function __call($method, $arguments)
  141. {
  142. $ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
  143. if(empty($ret)) {
  144. $ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
  145. }
  146. return $ret;
  147. }
  148. /**
  149. * Get ImageFile
  150. *
  151. * @return null|File
  152. */
  153. public function getImageFile(): ?File
  154. {
  155. return $this->imageFile;
  156. }
  157. /**
  158. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  159. */
  160. public function setImageFile(?File $imageFile = null): void
  161. {
  162. $this->imageFile = $imageFile;
  163. if (null !== $imageFile) {
  164. $this->editts = new \DateTime();
  165. }
  166. }
  167. /**
  168. * @return mixed
  169. */
  170. public function getImage()
  171. {
  172. return $this->image;
  173. }
  174. /**
  175. * @param mixed $image
  176. */
  177. public function setImage($image): void
  178. {
  179. $this->image = $image;
  180. }
  181. /**
  182. * @return Collection|Offer[]
  183. */
  184. public function getOffers(): Collection
  185. {
  186. return $this->offers;
  187. }
  188. public function addOffer(Offer $offer): self
  189. {
  190. if (!$this->offers->contains($offer)) {
  191. $this->offers[] = $offer;
  192. $offer->setCategory($this);
  193. }
  194. return $this;
  195. }
  196. public function removeOffer(Offer $offer): self
  197. {
  198. if ($this->offers->removeElement($offer) && $offer->getCategory() === $this) {
  199. $offer->setCategory(null);
  200. }
  201. return $this;
  202. }
  203. public function getActiveOffers(): Collection
  204. {
  205. return $this->getOffers()->filter(function (Offer $offer) {
  206. return $offer->getIsActive() && $offer->getIsPublic();
  207. });
  208. }
  209. }