src/Entity/Application/Category.php line 25

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