src/Entity/Brand.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Application\Store;
  4. use Cocur\Slugify\Slugify;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use App\Entity\Behaviors\TranslatableTrait;
  13. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  14. use JMS\Serializer\Annotation as Serializer;
  15. /**
  16. * @ORM\Entity(repositoryClass="App\Repository\BrandRepository")
  17. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  18. * @UniqueEntity(fields={"name"}, message="Tato značka je již vytvořena!")
  19. * @Vich\Uploadable()
  20. */
  21. class Brand implements TranslatableInterface
  22. {
  23. use TranslatableTrait;
  24. /**
  25. * @ORM\Id()
  26. * @ORM\GeneratedValue()
  27. * @ORM\Column(type="integer")
  28. */
  29. private $id;
  30. /**
  31. * @Assert\NotBlank()
  32. * @Serializer\Groups({"api"})
  33. * @Serializer\SerializedName("brand")
  34. * @ORM\Column(type="string", length=190, unique=true)
  35. */
  36. private $name;
  37. /**
  38. * @ORM\Column(type="string", length=190, unique=true)
  39. */
  40. private $slug;
  41. /**
  42. * @Vich\UploadableField(mapping="brand_logo", fileNameProperty="image")
  43. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  44. * @var File|null
  45. */
  46. private $imageFile;
  47. /**
  48. * @ORM\Column(type="string", length=199, nullable=true)
  49. */
  50. private $image;
  51. /**
  52. * @ORM\Column(type="string", length=100, nullable=true)
  53. */
  54. private $groupBrands;
  55. /**
  56. * @ORM\Column(type="datetime")
  57. */
  58. private $createts;
  59. /**
  60. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  61. * @ORM\JoinColumn(nullable=false)
  62. */
  63. private $createUser;
  64. /**
  65. * @ORM\Column(type="datetime", nullable=true)
  66. */
  67. private $editts;
  68. /**
  69. * @ORM\Column(type="boolean")
  70. */
  71. private $atHomePage = false;
  72. /**
  73. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  74. */
  75. private $editUser;
  76. /**
  77. * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="brand")
  78. */
  79. private $products;
  80. /**
  81. * @ORM\ManyToMany(targetEntity="App\Entity\Application\Store", mappedBy="brands")
  82. */
  83. private $stores;
  84. public function __construct()
  85. {
  86. $this->stores = new ArrayCollection();
  87. }
  88. public function getId(): ?int
  89. {
  90. return $this->id;
  91. }
  92. public function getName(): ?string
  93. {
  94. return $this->name;
  95. }
  96. public function setName(string $name): self
  97. {
  98. $this->name = $name;
  99. $this->setSlug(Slugify::create()->slugify($name));
  100. return $this;
  101. }
  102. public function getSlug(): ?string
  103. {
  104. return $this->slug;
  105. }
  106. public function setSlug(string $slug): self
  107. {
  108. $this->slug = $slug;
  109. return $this;
  110. }
  111. public function getImage(): ?string
  112. {
  113. return $this->image;
  114. }
  115. public function setImage(?string $image): self
  116. {
  117. $this->image = $image;
  118. return $this;
  119. }
  120. public function getCreatets(): ?\DateTimeInterface
  121. {
  122. return $this->createts;
  123. }
  124. public function setCreatets(\DateTimeInterface $createts): self
  125. {
  126. $this->createts = $createts;
  127. return $this;
  128. }
  129. public function getCreateUser(): ?User
  130. {
  131. return $this->createUser;
  132. }
  133. public function setCreateUser(?User $createUser): self
  134. {
  135. $this->createUser = $createUser;
  136. return $this;
  137. }
  138. public function getEditts(): ?\DateTimeInterface
  139. {
  140. return $this->editts;
  141. }
  142. public function setEditts(?\DateTimeInterface $editts): self
  143. {
  144. $this->editts = $editts;
  145. return $this;
  146. }
  147. public function getEditUser(): ?User
  148. {
  149. return $this->editUser;
  150. }
  151. public function setEditUser(?User $editUser): self
  152. {
  153. $this->editUser = $editUser;
  154. return $this;
  155. }
  156. public function __call($method, $arguments)
  157. {
  158. $ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
  159. if(empty($ret)) {
  160. $ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
  161. }
  162. return $ret;
  163. }
  164. /**
  165. * Get ImageFile
  166. *
  167. * @return null|File
  168. */
  169. public function getImageFile()
  170. {
  171. return $this->imageFile;
  172. }
  173. /**
  174. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  175. */
  176. public function setImageFile(?File $imageFile = null): void
  177. {
  178. $this->imageFile = $imageFile;
  179. if (null !== $imageFile) {
  180. $this->editts = new \DateTime();
  181. }
  182. }
  183. /**
  184. * Get AtHomePage
  185. *
  186. * @return mixed
  187. */
  188. public function getAtHomePage()
  189. {
  190. return $this->atHomePage;
  191. }
  192. /**
  193. * Set AtHomePage
  194. *
  195. * @param mixed $atHomePage
  196. */
  197. public function setAtHomePage( $atHomePage )
  198. {
  199. $this->atHomePage = $atHomePage;
  200. }
  201. /**
  202. * Get Products
  203. *
  204. * @return mixed
  205. */
  206. public function getProducts()
  207. {
  208. return $this->products;
  209. }
  210. /**
  211. * Set Products
  212. *
  213. * @param mixed $products
  214. */
  215. public function setProducts( $products )
  216. {
  217. $this->products = $products;
  218. }
  219. /**
  220. * Get GroupBrands
  221. *
  222. * @return mixed
  223. */
  224. public function getGroupBrands()
  225. {
  226. return $this->groupBrands;
  227. }
  228. /**
  229. * Set GroupBrands
  230. *
  231. * @param mixed $groupBrands
  232. */
  233. public function setGroupBrands( $groupBrands )
  234. {
  235. $this->groupBrands = $groupBrands;
  236. }
  237. /**
  238. * @return Collection|Store[]
  239. */
  240. public function getStores(): Collection
  241. {
  242. return $this->stores;
  243. }
  244. public function addStore(Store $store): self
  245. {
  246. if (!$this->stores->contains($store)) {
  247. $this->stores[] = $store;
  248. $store->addBrand($this);
  249. }
  250. return $this;
  251. }
  252. public function removeStore(Store $store): self
  253. {
  254. if ($this->stores->contains($store)) {
  255. $this->stores->removeElement($store);
  256. }
  257. return $this;
  258. }
  259. }