src/Entity/Transport.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use App\Entity\Behaviors\TranslatableTrait;
  10. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  11. /**
  12. * @ORM\Entity(repositoryClass="App\Repository\TransportRepository")
  13. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  14. * @Vich\Uploadable()
  15. */
  16. class Transport implements TranslatableInterface
  17. {
  18. use TranslatableTrait;
  19. /**
  20. * @ORM\Id()
  21. * @ORM\GeneratedValue()
  22. * @ORM\Column(type="integer")
  23. */
  24. private $id;
  25. /**
  26. * @Vich\UploadableField(mapping="transport_logo", fileNameProperty="image")
  27. * @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
  28. * @var File|null
  29. */
  30. private $imageFile;
  31. /**
  32. * @ORM\Column(type="string", length=199, nullable=true)
  33. */
  34. private $image;
  35. /**
  36. * @ORM\Column(type="boolean")
  37. */
  38. private $isActive = true;
  39. /**
  40. * @ORM\Column(type="boolean",nullable=true)
  41. */
  42. private $isPersonal = false;
  43. /**
  44. * @ORM\Column(type="string", length=190)
  45. */
  46. private $code;
  47. /**
  48. * @ORM\Column(type="integer", nullable=false)
  49. */
  50. private $priority = 9;
  51. /**
  52. * @ORM\Column(type="datetime")
  53. */
  54. private $createts;
  55. /**
  56. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  57. * @ORM\JoinColumn(nullable=false)
  58. */
  59. private $createUser;
  60. /**
  61. * @ORM\Column(type="datetime", nullable=true)
  62. */
  63. private $editts;
  64. /**
  65. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  66. */
  67. private $editUser;
  68. /**
  69. * @ORM\ManyToMany(targetEntity="App\Entity\Payment", inversedBy="transports")
  70. * @ORM\JoinTable(name="transport_payment")
  71. */
  72. private $payments;
  73. /**
  74. * @ORM\OneToMany(targetEntity="App\Entity\Pricelist", mappedBy="transport", cascade={"persist", "remove"}, orphanRemoval=true, indexBy="currency")
  75. */
  76. private $pricelists;
  77. /**
  78. * @ORM\Column(type="array", nullable=true)
  79. */
  80. private $country = [];
  81. public function __construct()
  82. {
  83. $this->payments = new ArrayCollection();
  84. $this->pricelists = new ArrayCollection();
  85. }
  86. public function checkPricelists($currencies){
  87. $diff = array_diff($currencies,array_keys($this->getPricelists()->toArray()));
  88. if(count($diff)>0){
  89. foreach ($diff as $curr){
  90. $price = new Pricelist($curr);
  91. $this->addPricelist($price);
  92. }
  93. }
  94. }
  95. public function getId(): ?int
  96. {
  97. return $this->id;
  98. }
  99. public function getCode(): ?string
  100. {
  101. return $this->code;
  102. }
  103. public function setCode(string $code): self
  104. {
  105. $this->code = $code;
  106. return $this;
  107. }
  108. public function getCreatets(): ?\DateTimeInterface
  109. {
  110. return $this->createts;
  111. }
  112. public function setCreatets(\DateTimeInterface $createts): self
  113. {
  114. $this->createts = $createts;
  115. return $this;
  116. }
  117. public function getCreateUser(): ?User
  118. {
  119. return $this->createUser;
  120. }
  121. public function setCreateUser(?User $createUser): self
  122. {
  123. $this->createUser = $createUser;
  124. return $this;
  125. }
  126. public function getEditts(): ?\DateTimeInterface
  127. {
  128. return $this->editts;
  129. }
  130. public function setEditts(?\DateTimeInterface $editts): self
  131. {
  132. $this->editts = $editts;
  133. return $this;
  134. }
  135. public function getEditUser(): ?User
  136. {
  137. return $this->editUser;
  138. }
  139. public function setEditUser(?User $editUser): self
  140. {
  141. $this->editUser = $editUser;
  142. return $this;
  143. }
  144. public function getImage(): ?string
  145. {
  146. return $this->image;
  147. }
  148. public function setImage(?string $image): self
  149. {
  150. $this->image = $image;
  151. return $this;
  152. }
  153. public function getIsActive(): ?bool
  154. {
  155. return $this->isActive;
  156. }
  157. public function setIsActive(bool $isActive): self
  158. {
  159. $this->isActive = $isActive;
  160. return $this;
  161. }
  162. /**
  163. * Get ImageFile
  164. *
  165. * @return null|File
  166. */
  167. public function getImageFile()
  168. {
  169. return $this->imageFile;
  170. }
  171. /**
  172. * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  173. */
  174. public function setImageFile(?File $imageFile = null): void
  175. {
  176. $this->imageFile = $imageFile;
  177. if (null !== $imageFile) {
  178. $this->editts = new \DateTime();
  179. }
  180. }
  181. /**
  182. * @return Collection|Payment[]
  183. */
  184. public function getPayments(): Collection
  185. {
  186. return $this->payments;
  187. }
  188. public function getPaymentsArray(): array
  189. {
  190. $ret = [];
  191. foreach ( $this->payments as $payment ) {
  192. $ret[]=$payment->getId();
  193. }
  194. return $ret;
  195. }
  196. public function addPayment(Payment $payment): self
  197. {
  198. if (!$this->payments->contains($payment)) {
  199. $this->payments[] = $payment;
  200. $payment->addTransport($this);
  201. }
  202. return $this;
  203. }
  204. public function removePayment(Payment $payment): self
  205. {
  206. if ($this->payments->contains($payment)) {
  207. $this->payments->removeElement($payment);
  208. $payment->removeTransport($this);
  209. }
  210. return $this;
  211. }
  212. /**
  213. * @return Collection|Pricelist[]
  214. */
  215. public function getPricelists(): Collection
  216. {
  217. return $this->pricelists;
  218. }
  219. public function addPricelist(Pricelist $pricelist): self
  220. {
  221. if (!$this->pricelists->contains($pricelist)) {
  222. $this->pricelists[] = $pricelist;
  223. $pricelist->setTransport($this);
  224. }
  225. return $this;
  226. }
  227. public function removePricelist(Pricelist $pricelist): self
  228. {
  229. if ($this->pricelists->contains($pricelist)) {
  230. $this->pricelists->removeElement($pricelist);
  231. // set the owning side to null (unless already changed)
  232. if ($pricelist->getTransport() === $this) {
  233. $pricelist->setTransport(null);
  234. }
  235. }
  236. return $this;
  237. }
  238. /**
  239. * Get Country
  240. *
  241. * @return mixed
  242. */
  243. public function getCountry()
  244. {
  245. return $this->country;
  246. }
  247. /**
  248. * Set Country
  249. *
  250. * @param mixed $country
  251. */
  252. public function setCountry( $country )
  253. {
  254. $this->country = $country;
  255. }
  256. public function __call($method, $arguments)
  257. {
  258. $ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
  259. if(empty($ret)) {
  260. $ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
  261. }
  262. return $ret;
  263. }
  264. /**
  265. * Get isPersonal
  266. *
  267. * @return mixed
  268. */
  269. public function getisPersonal()
  270. {
  271. return $this->isPersonal;
  272. }
  273. /**
  274. * Set IsPersonal
  275. *
  276. * @param mixed $isPersonal
  277. */
  278. public function setIsPersonal( $isPersonal )
  279. {
  280. $this->isPersonal = $isPersonal;
  281. }
  282. /**
  283. * @return int
  284. */
  285. public function getPriority(): int
  286. {
  287. return $this->priority;
  288. }
  289. /**
  290. * @param int $priority
  291. */
  292. public function setPriority(int $priority): void
  293. {
  294. $this->priority = $priority;
  295. }
  296. }