<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Behaviors\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\TransportRepository")
* @ORM\EntityListeners({"App\Listener\EntityListener"})
* @Vich\Uploadable()
*/
class Transport implements TranslatableInterface
{
use TranslatableTrait;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Vich\UploadableField(mapping="transport_logo", fileNameProperty="image")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=199, nullable=true)
*/
private $image;
/**
* @ORM\Column(type="boolean")
*/
private $isActive = true;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private $isPersonal = false;
/**
* @ORM\Column(type="string", length=190)
*/
private $code;
/**
* @ORM\Column(type="integer", nullable=false)
*/
private $priority = 9;
/**
* @ORM\Column(type="datetime")
*/
private $createts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(nullable=false)
*/
private $createUser;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
*/
private $editUser;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Payment", inversedBy="transports")
* @ORM\JoinTable(name="transport_payment")
*/
private $payments;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Pricelist", mappedBy="transport", cascade={"persist", "remove"}, orphanRemoval=true, indexBy="currency")
*/
private $pricelists;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $country = [];
public function __construct()
{
$this->payments = new ArrayCollection();
$this->pricelists = new ArrayCollection();
}
public function checkPricelists($currencies){
$diff = array_diff($currencies,array_keys($this->getPricelists()->toArray()));
if(count($diff)>0){
foreach ($diff as $curr){
$price = new Pricelist($curr);
$this->addPricelist($price);
}
}
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getCreatets(): ?\DateTimeInterface
{
return $this->createts;
}
public function setCreatets(\DateTimeInterface $createts): self
{
$this->createts = $createts;
return $this;
}
public function getCreateUser(): ?User
{
return $this->createUser;
}
public function setCreateUser(?User $createUser): self
{
$this->createUser = $createUser;
return $this;
}
public function getEditts(): ?\DateTimeInterface
{
return $this->editts;
}
public function setEditts(?\DateTimeInterface $editts): self
{
$this->editts = $editts;
return $this;
}
public function getEditUser(): ?User
{
return $this->editUser;
}
public function setEditUser(?User $editUser): self
{
$this->editUser = $editUser;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
/**
* Get ImageFile
*
* @return null|File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
$this->editts = new \DateTime();
}
}
/**
* @return Collection|Payment[]
*/
public function getPayments(): Collection
{
return $this->payments;
}
public function getPaymentsArray(): array
{
$ret = [];
foreach ( $this->payments as $payment ) {
$ret[]=$payment->getId();
}
return $ret;
}
public function addPayment(Payment $payment): self
{
if (!$this->payments->contains($payment)) {
$this->payments[] = $payment;
$payment->addTransport($this);
}
return $this;
}
public function removePayment(Payment $payment): self
{
if ($this->payments->contains($payment)) {
$this->payments->removeElement($payment);
$payment->removeTransport($this);
}
return $this;
}
/**
* @return Collection|Pricelist[]
*/
public function getPricelists(): Collection
{
return $this->pricelists;
}
public function addPricelist(Pricelist $pricelist): self
{
if (!$this->pricelists->contains($pricelist)) {
$this->pricelists[] = $pricelist;
$pricelist->setTransport($this);
}
return $this;
}
public function removePricelist(Pricelist $pricelist): self
{
if ($this->pricelists->contains($pricelist)) {
$this->pricelists->removeElement($pricelist);
// set the owning side to null (unless already changed)
if ($pricelist->getTransport() === $this) {
$pricelist->setTransport(null);
}
}
return $this;
}
/**
* Get Country
*
* @return mixed
*/
public function getCountry()
{
return $this->country;
}
/**
* Set Country
*
* @param mixed $country
*/
public function setCountry( $country )
{
$this->country = $country;
}
public function __call($method, $arguments)
{
$ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
if(empty($ret)) {
$ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
}
return $ret;
}
/**
* Get isPersonal
*
* @return mixed
*/
public function getisPersonal()
{
return $this->isPersonal;
}
/**
* Set IsPersonal
*
* @param mixed $isPersonal
*/
public function setIsPersonal( $isPersonal )
{
$this->isPersonal = $isPersonal;
}
/**
* @return int
*/
public function getPriority(): int
{
return $this->priority;
}
/**
* @param int $priority
*/
public function setPriority(int $priority): void
{
$this->priority = $priority;
}
}