<?php
namespace App\Entity;
use Cocur\Slugify\Slugify;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Behaviors\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\DealerRepository")
* @ORM\EntityListeners({"App\Listener\EntityListener"})
* @Vich\Uploadable()
*/
class Dealer implements TranslatableInterface
{
use TranslatableTrait;
public const FEED_TYPE=[
'FREEPORT' => 'Freeport feed',
'PRODES' => 'Prodes Google feed',
'SHOPTET' => 'Shoptet feed',
'SHOPTET_CSV' => 'Shoptet feed CSV'
];
public const COUNT_APP_PRODUCTS = 20;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Vich\UploadableField(mapping="dealer_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="string", length=199, nullable=true)
*/
private $code;
/**
* @ORM\Column(type="boolean")
*/
private $isActive = true;
/**
* @ORM\Column(type="string", length=190)
*/
private $name;
/**
* @ORM\Column(type="string", length=190)
*/
private $slug;
/**
* @ORM\Column(type="string", length=190, nullable=true)
*/
private $companyName;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $ico;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $dic;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $street;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $city;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $zip;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $streetNumber;
/**
* @ORM\Column(type="string", length=190, nullable=false)
*/
private $phone;
/**
* @ORM\Column(type="string", length=190, nullable=false)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=190, nullable=false)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=190, nullable=false)
*/
private $email;
/**
* @ORM\Column(type="string", length=190, nullable=false)
*/
private $orderEmail;
/**
* @ORM\Column(type="float")
*/
private $course;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $freeDelivery;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $orderFrom;
/**
* @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\OneToMany(targetEntity="App\Entity\OrderItem", mappedBy="dealer", orphanRemoval=false)
*/
private $orderItems;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Order", mappedBy="dealer", orphanRemoval=false)
*/
private $orders;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="dealers")
*/
private $users;
/**
* @ORM\OneToMany(targetEntity=ClickAndCollectItem::class, mappedBy="dealer")
*/
private $clickAndCollectItems;
/**
* @ORM\OneToMany(targetEntity=LogImport::class, mappedBy="dealer", orphanRemoval=true)
* @ORM\OrderBy({"id"="DESC"})
*/
private $logImports;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $urlFeed;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $feedType;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastReloadFeed;
/**
* @ORM\Column(type="boolean")
*/
private $reloadFeed = true;
/**
* Odeslat objednávky do jejich systému
*
* @ORM\Column(type="boolean")
*/
private $sendExternal = false;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $compareCategories;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="dealer")
*/
private $products;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Application\AppProduct", mappedBy="dealer")
*/
private $appProducts;
/**
* @var ArrayCollection $activeBrands
*/
private $activeBrands;
/**
* @ORM\OneToMany(targetEntity=DealerBank::class, mappedBy="dealer",cascade={"persist", "remove"}, orphanRemoval=true, indexBy="currency")
*/
private $banks;
/**
* @ORM\Column(type="integer", length=3)
*/
private $countAppProducts = self::COUNT_APP_PRODUCTS;
/**
* @ORM\OneToMany(targetEntity=Reclamation::class, mappedBy="dealer", orphanRemoval=true)
*/
private $reclamations;
public function __construct()
{
$this->orderItems = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->users = new ArrayCollection();
$this->clickAndCollectItems = new ArrayCollection();
$this->logImports = new ArrayCollection();
$this->appProducts = new ArrayCollection();
$this->activeBrands = new ArrayCollection();
$this->banks = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->reclamations = new ArrayCollection();
}
/**
* checkCollections - Nasetování povinných arrayCollections
*
* @param $currencies
* @param $locales
*/
public function checkCollections($currencies, $locales){
$diff = array_diff($currencies,array_keys($this->getBanks()->toArray()));
if(count($diff)>0){
foreach ($diff as $curr){
$bank = new DealerBank($curr);
$this->addBank($bank);
}
}
foreach ( $locales as $locale ) {
if($this->getTranslations()->get($locale) === null){
$this->translate($locale)->setPersonalNote(' ');
}
}
$this->mergeNewTranslations();
}
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;
}
public function getId(): ?int
{
return $this->id;
}
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;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
$this->setSlug(Slugify::create()->slugify($name));
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(?string $companyName): self
{
$this->companyName = $companyName;
return $this;
}
public function getIco(): ?string
{
return $this->ico;
}
public function setIco(?string $ico): self
{
$this->ico = $ico;
return $this;
}
public function getDic(): ?string
{
return $this->dic;
}
public function setDic(?string $dic): self
{
$this->dic = $dic;
return $this;
}
/**
* Get Phone
*
* @return mixed
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set Phone
*
* @param mixed $phone
*/
public function setPhone( $phone )
{
$this->phone = $phone;
}
public function getStreet(): ?string
{
return $this->street;
}
public function setStreet(?string $street): self
{
$this->street = $street;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getZip(): ?string
{
return $this->zip;
}
public function setZip(?string $zip): self
{
$this->zip = $zip;
return $this;
}
public function getStreetNumber(): ?string
{
return $this->streetNumber;
}
public function setStreetNumber(?string $streetNumber): self
{
$this->streetNumber = $streetNumber;
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;
}
/**
* Get Email
*
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* Set Email
*
* @param mixed $email
*/
public function setEmail( $email )
{
$this->email = $email;
}
/**
* 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|OrderItem[]
*/
public function getOrderItems(): Collection
{
return $this->orderItems;
}
public function addOrderItem(OrderItem $orderItem): self
{
if (!$this->orderItems->contains($orderItem)) {
$this->orderItems[] = $orderItem;
$orderItem->setOrder($this);
}
return $this;
}
public function removeOrderItem(OrderItem $orderItem): self
{
if ($this->orderItems->contains($orderItem)) {
$this->orderItems->removeElement($orderItem);
// set the owning side to null (unless already changed)
if ($orderItem->getOrder() === $this) {
$orderItem->setOrder(null);
}
}
return $this;
}
/**
* @return Collection|Order[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setDealer($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->contains($order)) {
$this->orders->removeElement($order);
// set the owning side to null (unless already changed)
if ($order->getDealer() === $this) {
$order->setDealer(null);
}
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->contains($user)) {
$this->users->removeElement($user);
}
return $this;
}
/**
* Get Course
*
* @return mixed
*/
public function getCourse()
{
return $this->course;
}
/**
* Set Course
*
* @param mixed $course
*/
public function setCourse( $course )
{
$this->course = $course;
}
/**
* @return Collection|ClickAndCollectItem[]
*/
public function getClickAndCollectItems(): Collection
{
return $this->clickAndCollectItems;
}
public function addClickAndCollectItem(ClickAndCollectItem $clickAndCollectItem): self
{
if (!$this->clickAndCollectItems->contains($clickAndCollectItem)) {
$this->clickAndCollectItems[] = $clickAndCollectItem;
$clickAndCollectItem->setDealer($this);
}
return $this;
}
public function removeClickAndCollectItem(ClickAndCollectItem $clickAndCollectItem): self
{
if ($this->clickAndCollectItems->contains($clickAndCollectItem)) {
$this->clickAndCollectItems->removeElement($clickAndCollectItem);
// set the owning side to null (unless already changed)
if ($clickAndCollectItem->getDealer() === $this) {
$clickAndCollectItem->setDealer(null);
}
}
return $this;
}
/**
* @return Collection|LogImport[]
*/
public function getLogImports(): Collection
{
return $this->logImports;
}
public function addLogImport(LogImport $logImport): self
{
if (!$this->logImports->contains($logImport)) {
$this->logImports[] = $logImport;
$logImport->setDealer($this);
}
return $this;
}
public function removeLogImport(LogImport $logImport): self
{
if ($this->logImports->contains($logImport)) {
$this->logImports->removeElement($logImport);
// set the owning side to null (unless already changed)
if ($logImport->getDealer() === $this) {
$logImport->setDealer(null);
}
}
return $this;
}
/**
* Get UrlFeed
*
* @return mixed
*/
public function getUrlFeed()
{
return $this->urlFeed;
}
/**
* Set UrlFeed
*
* @param mixed $urlFeed
*/
public function setUrlFeed( $urlFeed )
{
$this->urlFeed = $urlFeed;
}
/**
* Get CompareCategories
*
* @return mixed
*/
public function getCompareCategories()
{
return $this->compareCategories;
}
/**
* Set CompareCategories
*
* @param mixed $compareCategories
*/
public function setCompareCategories( $compareCategories )
{
$this->compareCategories = $compareCategories;
}
/**
* Get OrderEmail
*
* @return mixed
*/
public function getOrderEmail()
{
return $this->orderEmail;
}
/**
* Set OrderEmail
*
* @param mixed $orderEmail
*/
public function setOrderEmail( $orderEmail )
{
$this->orderEmail = $orderEmail;
}
/**
* Get FreeDelivery
*
* @return mixed
*/
public function getFreeDelivery()
{
return $this->freeDelivery;
}
/**
* Set FreeDelivery
*
* @param mixed $freeDelivery
*/
public function setFreeDelivery( $freeDelivery )
{
$this->freeDelivery = $freeDelivery;
}
/**
* Get Products
*
* @return mixed
*/
public function getProducts()
{
return $this->products;
}
/**
* Set Products
*
* @param mixed $products
*/
public function setProducts( $products )
{
$this->products = $products;
}
public function getActiveBrands(): ?Collection
{
return $this->activeBrands;
}
public function addActiveBrand(Brand $brand): self
{
if($this->activeBrands === null){
$this->activeBrands = new ArrayCollection();
}
if (!$this->activeBrands->contains($brand)) {
$this->activeBrands[] = $brand;
}
return $this;
}
/**
* Get FeedType
*
* @return mixed
*/
public function getFeedType()
{
return $this->feedType;
}
/**
* Set FeedType
*
* @param mixed $feedType
*/
public function setFeedType( $feedType )
{
$this->feedType = $feedType;
}
/**
* @return Collection|DealerBank[]
*/
public function getBanks(): Collection
{
return $this->banks;
}
public function addBank(DealerBank $bank): self
{
if (!$this->banks->contains($bank)) {
$this->banks[] = $bank;
$bank->setDealer($this);
}
return $this;
}
public function removeBank(DealerBank $bank): self
{
if ($this->banks->removeElement($bank)) {
// set the owning side to null (unless already changed)
if ($bank->getDealer() === $this) {
$bank->setDealer(null);
}
}
return $this;
}
/**
* Get FirstName
*
* @return mixed
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* Set FirstName
*
* @param mixed $firstName
*/
public function setFirstName( $firstName )
{
$this->firstName = $firstName;
}
/**
* Get LastName
*
* @return mixed
*/
public function getLastName()
{
return $this->lastName;
}
/**
* Set LastName
*
* @param mixed $lastName
*/
public function setLastName( $lastName )
{
$this->lastName = $lastName;
}
public function getFullName()
{
return sprintf('%s %s',$this->lastName,$this->firstName);
}
/**
* Get LastReloadFeed
*
* @return mixed
*/
public function getLastReloadFeed()
{
return $this->lastReloadFeed;
}
/**
* Set LastReloadFeed
*
* @param mixed $lastReloadFeed
*/
public function setLastReloadFeed( $lastReloadFeed )
{
$this->lastReloadFeed = $lastReloadFeed;
}
/**
* Get ReloadFeed
*
* @return mixed
*/
public function getReloadFeed()
{
return $this->reloadFeed;
}
/**
* Set ReloadFeed
*
* @param mixed $reloadFeed
*/
public function setReloadFeed( $reloadFeed )
{
$this->reloadFeed = $reloadFeed;
}
/**
* Get SendExternal
*
* @return mixed
*/
public function getSendExternal()
{
return $this->sendExternal;
}
/**
* Set SendExternal
*
* @param mixed $sendExternal
*/
public function setSendExternal( $sendExternal )
{
$this->sendExternal = $sendExternal;
}
/**
* Get CountAppProducts
*
* @return mixed
*/
public function getCountAppProducts()
{
return $this->countAppProducts;
}
/**
* Set CountAppProducts
*
* @param mixed $countAppProducts
*/
public function setCountAppProducts( $countAppProducts )
{
$this->countAppProducts = $countAppProducts;
}
/**
* Get Products
*
* @return mixed
*/
public function getAppProducts()
{
return $this->appProducts;
}
/**
* Set AppProducts
*
* @param mixed $appProducts
*/
public function setAppProducts( $appProducts )
{
$this->appProducts = $appProducts;
}
/**
* @return Collection|Reclamation[]
*/
public function getReclamations(): Collection
{
return $this->reclamations;
}
public function addReclamation(Reclamation $reclamation): self
{
if (!$this->reclamations->contains($reclamation)) {
$this->reclamations[] = $reclamation;
$reclamation->setDealer($this);
}
return $this;
}
public function removeReclamation(Reclamation $reclamation): self
{
if ($this->reclamations->removeElement($reclamation)) {
// set the owning side to null (unless already changed)
if ($reclamation->getDealer() === $this) {
$reclamation->setDealer(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getCode()
{
return $this->code;
}
/**
* @param mixed $code
*/
public function setCode($code): void
{
$this->code = $code;
}
/**
* @return mixed
*/
public function getOrderFrom()
{
return $this->orderFrom;
}
/**
* @param mixed $orderFrom
*/
public function setOrderFrom($orderFrom): void
{
$this->orderFrom = $orderFrom;
}
}