<?php
namespace App\Entity\Application;
use App\Entity\Brand;
use App\Entity\User;
use App\Entity\Web\Career;
use App\Repository\Application\StoreRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use App\Entity\Behaviors\TranslatableTrait;
use App\Entity\Behaviors\SluggableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
*
* @ORM\Table(name="app_store",
* uniqueConstraints={@ORM\UniqueConstraint(name="hash", columns={"hash"})}
* )
* @ORM\EntityListeners({"App\Listener\EntityListener"})
* @ORM\Entity(repositoryClass=StoreRepository::class)
* @Vich\Uploadable()
*/
class Store implements TranslatableInterface, SluggableInterface
{
public const DAY_LIMIT = 1;
use SluggableTrait;
use TranslatableTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", nullable=true, length=100)
*/
private $hash;
/**
* @Vich\UploadableField(mapping="store_logo", fileNameProperty="logo")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $logoFile;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("logo")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $logo;
/**
* @Vich\UploadableField(mapping="store_map_image", fileNameProperty="map")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $mapFile;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("map")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $map;
/**
* @Vich\UploadableField(mapping="store_offer_image", fileNameProperty="offerImage")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $offerImageFile;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("map")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $offerImage;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("email")
* @ORM\Column(type="string", length=150, nullable=true)
*/
private $email;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("web")
* @ORM\Column(type="string", length=150, nullable=true)
*/
private $web;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("shopNumber")
* @ORM\Column(type="array",nullable=true)
*/
private ?array $shopNumber;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("vip")
* @ORM\Column(type="boolean")
*/
private $vip;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("vipDiscount")
* @ORM\Column(type="integer")
*/
private $vipDiscount = 10;
/**
* @ORM\Column(type="date",nullable=true)
*/
private $vipEndDate;
/**
* @ORM\Column(type="integer")
*/
private $points = 5;
/**
* @Vich\UploadableField(mapping="store_image", fileNameProperty="image")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $imageFile;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("image")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("phone")
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $phone;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("firstName")
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $firstName;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("lastName")
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $lastName;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $openHours = [];
/**
* @Serializer\Groups({"api","pointsHistory"})
* @Serializer\SerializedName("name")
* @ORM\Column(type="string", length=150)
*/
private $name;
/**
* @ORM\Column(type="boolean")
*/
private $isActive = true;
/**
* @ORM\Column(type="datetime")
*/
private $createts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(nullable=true)
*/
private $createUser;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
*/
private $editUser;
/**
* @Vich\UploadableField(mapping="store_qr", fileNameProperty="qr")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $qrFile;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $qr;
/**
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("categories")
* @ORM\ManyToMany(targetEntity="App\Entity\Application\Category", inversedBy="stores")
* @ORM\JoinTable(name="app_store_category")
*/
private $category;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Brand", inversedBy="stores")
* @ORM\JoinTable(name="app_store_brands")
*/
private $brands;
/**
* @ORM\OneToMany(targetEntity=Offer::class, mappedBy="store")
*/
private $offers;
/**
* @ORM\OneToMany(targetEntity=Career::class, mappedBy="store")
*/
private $careers;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="stores")
*/
private $users;
/**
* @ORM\OneToMany(targetEntity=Points::class, mappedBy="store")
*/
private $pointsHistory;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Application\StoreImage", mappedBy="store", cascade={"persist", "remove"}, orphanRemoval=true)
* @ORM\OrderBy({"orderBy" = "ASC"})
*/
private $storeImages;
/**
* @Serializer\VirtualProperty()
* @Serializer\Groups({"api"})
* @Serializer\Inline()
*/
public function getVirtualName()
{
return $this->translate();
}
/**
* @Serializer\VirtualProperty()
* @Serializer\Groups({"api"})
* @Serializer\SerializedName("openHours")
*/
public function getVirtualOpenHoursToday()
{
return implode(' - ', $this->getOpenHours()[date('N') - 1]);
}
public function __construct()
{
$this->offers = new ArrayCollection();
$this->pointsHistory = new ArrayCollection();
$this->category = new ArrayCollection();
$this->brands = new ArrayCollection();
$this->users = new ArrayCollection();
$this->careers = new ArrayCollection();
$this->storeImages = new ArrayCollection();
}
public function checkCollections($locales)
{
foreach ($locales as $locale) {
if ($this->getTranslations()->get($locale) === null) {
$this->translate($locale)->setDescription(' ');
}
}
$this->mergeNewTranslations();
}
public function getId(): ?int
{
return $this->id;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): self
{
$this->logo = $logo;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getWeb(): ?string
{
return $this->web;
}
public function setWeb(?string $web): self
{
$this->web = $web;
return $this;
}
public function getVip(): ?bool
{
return $this->vip;
}
public function setVip(bool $vip): self
{
$this->vip = $vip;
return $this;
}
public function getPoints(): ?int
{
return $this->points;
}
public function setPoints(int $points): self
{
$this->points = $points;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getOpenHours(): ?array
{
return $this->openHours;
}
public function setOpenHours(?array $openHours): self
{
$this->openHours = $openHours;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
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 __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 LogoFile
*
* @return null|File
*/
public function getLogoFile(): ?File
{
return $this->logoFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $logoFile
*/
public function setLogoFile(?File $logoFile = null): void
{
$this->logoFile = $logoFile;
if (null !== $logoFile) {
$this->editts = new \DateTime();
}
}
/**
* Get ImageFile
*
* @return null|File
*/
public function getImageFile(): ?File
{
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|Category[]
*/
public function getCategory(): Collection
{
return $this->category;
}
public function addCategory(Category $category): self
{
if (!$this->category->contains($category)) {
$this->category[] = $category;
$category->addStore($this);
}
return $this;
}
public function removeCategory(Category $category): self
{
if ($this->category->contains($category)) {
$this->category->removeElement($category);
$category->removeStore($this);
}
return $this;
}
/**
* @return Collection|Brand[]
*/
public function getBrands(): Collection
{
return $this->brands;
}
public function addBrand(Brand $brand): self
{
if (!$this->brands->contains($brand)) {
$this->brands[] = $brand;
$brand->addStore($this);
}
return $this;
}
public function removeBrand(Brand $brand): self
{
if ($this->brands->contains($brand)) {
$this->brands->removeElement($brand);
$brand->removeStore($this);
}
return $this;
}
/**
* Get Qr
*
* @return mixed
*/
public function getQr()
{
return $this->qr;
}
/**
* Set Qr
*
* @param mixed $qr
*/
public function setQr($qr)
{
$this->qr = $qr;
}
/**
* Get QrFile
*
* @return null|File
*/
public function getQrFile(): ?File
{
return $this->qrFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $qrFile
*/
public function setQrFile(?File $qrFile = null): void
{
$this->qrFile = $qrFile;
if (null !== $qrFile) {
$this->editts = new \DateTime();
}
}
public function getActiveOffers(): Collection
{
return $this->getOffers()->filter(function (Offer $offer) {
return $offer->getIsActive() && $offer->getIsPublic();
});
}
/**
* @return Collection|Offer[]
*/
public function getOffers(): Collection
{
return $this->offers;
}
public function addOffer(Offer $offer): self
{
if (!$this->offers->contains($offer)) {
$this->offers[] = $offer;
$offer->setStore($this);
}
return $this;
}
public function removeOffer(Offer $offer): self
{
if ($this->offers->removeElement($offer)) {
// set the owning side to null (unless already changed)
if ($offer->getStore() === $this) {
$offer->setStore(null);
}
}
return $this;
}
/**
* @return Collection|Career[]
*/
public function getCareers(): Collection
{
return $this->careers;
}
public function addCareer(Career $career): self
{
if (!$this->careers->contains($career)) {
$this->careers[] = $career;
$career->setStore($this);
}
return $this;
}
public function removeCareer(Career $career): self
{
if ($this->careers->removeElement($career)) {
// set the owning side to null (unless already changed)
if ($career->getStore() === $this) {
$career->setStore(null);
}
}
return $this;
}
/**
* Get Hash
*
* @return mixed
*/
public function getHash()
{
return $this->hash;
}
/**
* Set Hash
*
* @param mixed $hash
*/
public function setHash($hash)
{
$this->hash = $hash;
}
/**
* Get isActive
*
* @return mixed
*/
public function getisActive()
{
return $this->isActive;
}
/**
* Set IsActive
*
* @param mixed $isActive
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
}
/**
* @return Collection|Points[]
*/
public function getPointsHistory(): Collection
{
return $this->pointsHistory;
}
public function addPointsHistory(Points $pointsHistory): self
{
if (!$this->pointsHistory->contains($pointsHistory)) {
$this->pointsHistory[] = $pointsHistory;
$pointsHistory->setStore($this);
}
return $this;
}
public function removePointsHistory(Points $pointsHistory): self
{
if ($this->pointsHistory->removeElement($pointsHistory)) {
// set the owning side to null (unless already changed)
if ($pointsHistory->getStore() === $this) {
$pointsHistory->setStore(null);
}
}
return $this;
}
/**
* Get VipDiscount
*
* @return mixed
*/
public function getVipDiscount()
{
return $this->vipDiscount;
}
/**
* Set VipDiscount
*
* @param mixed $vipDiscount
*/
public function setVipDiscount($vipDiscount)
{
$this->vipDiscount = $vipDiscount;
}
/**
* @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;
}
/**
* @return null|array
*/
public function getShopNumber(): ?array
{
return $this->shopNumber;
}
/**
* @param null|array $shopNumber
*/
public function setShopNumber(?array $shopNumber): void
{
$this->shopNumber = $shopNumber;
}
/**
* @return Collection|StoreImage[]
*/
public function getStoreImages(): Collection
{
return $this->storeImages;
}
public function addStoreImage(StoreImage $storeImage): self
{
if (!$this->storeImages->contains($storeImage)) {
$this->storeImages[] = $storeImage;
$storeImage->setStore($this);
}
return $this;
}
public function removeStoreImage(StoreImage $storeImage): self
{
if ($this->storeImages->contains($storeImage)) {
$this->storeImages->removeElement($storeImage);
// set the owning side to null (unless already changed)
if ($storeImage->getStore() === $this) {
$storeImage->setStore(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getVipEndDate()
{
if ($this->vipEndDate === null) {
$this->vipEndDate = new \DateTime('last day of December this year');
}
return $this->vipEndDate;
}
/**
* @param mixed $vipEndDate
*/
public function setVipEndDate($vipEndDate): void
{
$this->vipEndDate = $vipEndDate;
}
/**
* Get Map
*
* @return mixed
*/
public function getMap()
{
return $this->map;
}
/**
* Set Map
*
* @param mixed $map
*/
public function setMap($map)
{
$this->map = $map;
}
/**
* Get mapFile
*
* @return null|File
*/
public function getMapFile(): ?File
{
return $this->mapFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $mapFile
*/
public function setMapFile(?File $mapFile = null): void
{
$this->mapFile = $mapFile;
if (null !== $mapFile) {
$this->editts = new \DateTime();
}
}
/**
* Get mapFile
*
* @return null|File
*/
public function getOfferImageFile(): ?File
{
return $this->offerImageFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $offerImage
*/
public function setOfferImageFile(?File $offerImage = null): void
{
$this->offerImageFile = $offerImage;
if (null !== $offerImage) {
$this->editts = new \DateTime();
}
}
/**
* @return mixed
*/
public function getOfferImage()
{
return $this->offerImage;
}
/**
* @param mixed $offerImage
*/
public function setOfferImage($offerImage): void
{
$this->offerImage = $offerImage;
}
public function getSluggableFields(): array
{
return ['name'];
}
}