<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Exception;
use function array_values;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Id as Id;
use Doctrine\ORM\PersistentCollection;
use function implode;
use function is_null;
/**
* Shops
*
* @ORM\Table(name="shops", indexes={@ORM\Index(name="fk_shops_cities_idx", columns={"city"}), @ORM\Index(name="fk_shops_shoptypes1_idx", columns={"type"}), @ORM\Index(name="fk_shops_shoppingareas1_idx", columns={"shopping_area"}), @ORM\Index(name="fk_shops_shoppingmalls1_idx", columns={"shopping_mall"})})
* @ORM\Entity(repositoryClass="App\Repository\ShopRepository")
*/
class Shop
{
/**
* @var int
*
* @ORM\Column(name="shop_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
* @ORM\Column(name="_id", type="string", nullable=true)
*/
protected $_id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* @var string|null
*
* @ORM\Column(name="street", type="string", length=255, nullable=true)
*/
private $street;
/**
* @var string|null
*
* @ORM\Column(name="opening_hr", type="string", length=255, nullable=true)
*/
private $openingHr;
/**
* @var string|null
*
* @ORM\Column(name="www", type="string", length=255, nullable=true)
*/
private $www;
/**
* @var string|null
*
* @ORM\Column(name="zip", type="string", length=255, nullable=true)
*/
private $zip;
/**
* @var string|null
*
* @ORM\Column(name="sale_info", type="string", length=255, nullable=true)
*/
private $saleInfo;
/**
* @var string|null
*
* @ORM\Column(name="personal_note", type="string", length=255, nullable=true)
*/
private $personalNote;
/**
* @var string|null
*
* @ORM\Column(name="apigeo", type="string", length=255, nullable=true)
*/
private $apigeo;
/**
* @var string|null
*
* @ORM\Column(name="apitime", type="string", length=255, nullable=true)
*/
private $apitime;
/**
* @var bool
*
* @ORM\Column(name="is_active", type="boolean", nullable=false)
*/
private $isActive;
/**
* @var bool
*
* @ORM\Column(name="is_deleted", type="boolean", nullable=false)
*/
private $isDeleted;
/**
* @var string|null
*
* @ORM\Column(name="extent", type="string", length=45, nullable=true)
*/
private $extent;
/**
* @var string|null
*
* @ORM\Column(name="extent_label", type="string", length=45, nullable=true)
*/
private $extentLabel;
/**
* @var string|null
*
* @ORM\Column(name="yt_video", type="string", length=45, nullable=true)
*/
private $ytVideo;
/**
* @var float|null
*
* @ORM\Column(name="latitude", type="float", precision=10, scale=0, nullable=true)
*/
private $latitude;
/**
* @var float|null
*
* @ORM\Column(name="longitude", type="float", precision=10, scale=0, nullable=true)
*/
private $longitude;
/**
* @var string|null
*
* @ORM\Column(name="sale_info_article", type="string", length=255, nullable=true)
*/
private $saleInfoArticle;
/**
* @var \App\Entity\City
*
* @ORM\ManyToOne(targetEntity="App\Entity\City")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="city", referencedColumnName="city_id")
* })
*/
private $city;
/**
* @var \App\Entity\Shoppingarea
*
* @ORM\ManyToOne(targetEntity="App\Entity\Shoppingarea")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="shopping_area", referencedColumnName="shoppingarea_id")
* })
*/
private $shoppingArea;
/**
* @var Shoppingmall
*
* @ORM\ManyToOne(targetEntity="App\Entity\Shoppingmall")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="shopping_mall", referencedColumnName="shoppingmall_id")
* })
*/
private $shoppingMall;
/**
* @var \App\Entity\Shoptype
*
* @ORM\ManyToOne(targetEntity="App\Entity\Shoptype")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="type", referencedColumnName="shoptype_id")
* })
*/
private $type;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="App\Entity\Article", mappedBy="shops")
*/
private $article;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="App\Entity\Brand", inversedBy="shops")
* @ORM\JoinTable(name="shop_has_brand",
* joinColumns={
* @ORM\JoinColumn(name="shop_id", referencedColumnName="shop_id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="brand_id", referencedColumnName="brand_id")
* }
* )
*/
private $brands;
/**
* @var \Doctrine\ORM\PersistentCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\ShopHasCategories", mappedBy="shop", cascade={"persist"})
*/
private $shopHasCategories;
// /**
// * @var \Doctrine\Common\Collections\Collection
// *
// * @ORM\OneToMany(targetEntity="App\Entity\History", mappedBy="shop", fetch="EXTRA_LAZY")
// *
// */
// private $histories;
/**
* Created Date
* @var DateTime|null
*
* @ORM\Column(name="created_at", type="datetimetz", nullable=true)
*/
private $createdAt;
/**
* Updated Date
* @var DateTime|null
*
* @ORM\Column(name="updated_at", type="datetimetz", nullable=true)
*/
private $updatedAt;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="App\Entity\Shopkind", inversedBy="shops")
* @ORM\JoinTable(name="shop_has_shopkind",
* joinColumns={
* @ORM\JoinColumn(name="shop_id", referencedColumnName="shop_id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="shopkind_id", referencedColumnName="shopkind_id")
* }
* )
*/
private $shopkinds;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isNew;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $isNewDate;
/**
* @ORM\OneToOne(targetEntity="App\Entity\CompanyHasShop", mappedBy="shop")
*/
private $companyHasShop;
/**
* Constructor
*/
public function __construct()
{
$this->brands = new \Doctrine\Common\Collections\ArrayCollection();
$this->histories = new \Doctrine\Common\Collections\ArrayCollection();
$this->shopHasCategories = new \Doctrine\Common\Collections\ArrayCollection();
$this->shopkinds = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @param $name
* @return mixed
*/
public function __get($name)
{
if (property_exists($this, $name)) {
return $this->$name;
} else {
return null;
}
}
/************************************************************************************************************/
/****** COLLECTIONS METHODS *********************************************************************************/
/************************************************************************************************************/
/**
* @param \App\Entity\Brand $brand
* @return bool
*/
public function addBrand(Brand $brand)
{
return $this->brands->add($brand);
}
public function removeBrand(Brand $brand)
{
return $this->brands->remove($brand);
}
/**
* @param Category $category
* @param null $isPrimary
* @return $this|false
*/
public function addCategory(Category $category, $isPrimary = null)
{
if(false === $this->hasCategory($category)){
$shopHasCategory = new ShopHasCategories();
$shopHasCategory->setCategory($category);
$shopHasCategory->setShop($this);
if($isPrimary === true){
$this->clearPrimaryCategory();
$shopHasCategory->setIsPrimary(true);
}
$this->shopHasCategories->add($shopHasCategory);
return $this;
}
return false;
}
/**
* @param Category $category
* @return bool
*/
public function removeCategory(Category $category)
{
if(true === $this->hasCategory($category)){
$shopHasCategoryForDelete = null;
/** @var ShopHasCategories $shopHasCategory */
foreach($this->shopHasCategories as $shopHasCategory){
if($shopHasCategory->getCategory()->getId() === $category->getId()){
$shopHasCategoryForDelete = $shopHasCategory;
}
}
$this->shopHasCategories->removeElement($shopHasCategoryForDelete);
return true;
}
return false;
}
/**
*
*/
public function clearPrimaryCategory(){
/** @var ShopHasCategories $shopHasCategory */
foreach ($this->shopHasCategories as $shopHasCategory) {
$shopHasCategory->setIsPrimary(false);
}
}
/**
* @param \App\Entity\Shopkind $shopkind
* @return bool
*/
public function addShopkind(Shopkind $shopkind)
{
return $this->shopkinds->add($shopkind);
}
/**
* @param \App\Entity\Shopkind $shopkind
* @return bool
*/
public function removeShopkind(Shopkind $shopkind)
{
return $this->shopkinds->remove($shopkind);
}
/**
* @return \Doctrine\Common\Collections\Collection|\App\Entity\Brand[]
*/
public function getBrands(): \Doctrine\Common\Collections\Collection
{
return $this->brands;
}
/**
* @return \Doctrine\Common\Collections\Collection|\App\Entity\History[]
*/
public function getHistories(): ?\Doctrine\Common\Collections\Collection
{
return $this->histories;
}
/**
* @return Collection
*/
public function getShopHasCategories(): Collection
{
return $this->shopHasCategories;
}
/**
* @return \Doctrine\Common\Collections\Collection|\App\Entity\Shopkind[]
*/
public function getShopkinds(): Collection
{
return $this->shopkinds;
}
/**
* @param $shopkinds \Doctrine\Common\Collections\Collection|\App\Entity\Shopkind[]
*/
public function setShopkinds($shopkinds): void
{
$this->shopkinds = $shopkinds;
}
/**
* @return array
*/
protected function getShopkindsStrings()
{
$return = [];
foreach ($this->getShopkinds() as $shopkind) {
$return[] = (string)$shopkind;
}
return $return;
}
/**
* @return array
*/
protected function getShopHasCategoriesStrings()
{
$return = [];
foreach ($this->getShopHasCategories() as $shopHasCategory) {
$return[] = (string)$shopHasCategory;
}
return $return;
}
/************************************************************************************************************/
/****** GETTERS & SETTERS ***********************************************************************************/
/************************************************************************************************************/
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string
*/
public function getMongoId(): ?string
{
return $this->_id;
}
/**
* @return string
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return string|null
*/
public function getStreet(): ?string
{
return $this->street;
}
/**
* @param string|null $street
*/
public function setStreet(?string $street): void
{
$this->street = $street;
}
/**
* @return string|null
*/
public function getOpeningHr(): ?string
{
return $this->openingHr;
}
/**
* @param string|null $openingHr
*/
public function setOpeningHr(?string $openingHr): void
{
$this->openingHr = $openingHr;
}
/**
* @return string|null
*/
public function getWww(): ?string
{
return $this->www;
}
/**
* @param string|null $www
*/
public function setWww(?string $www): void
{
$this->www = $www;
}
/**
* @return string|null
*/
public function getZip(): ?string
{
return $this->zip;
}
/**
* @param string|null $zip
*/
public function setZip(?string $zip): void
{
$this->zip = $zip;
}
/**
* @return string|null
*/
public function getSaleInfo(): ?string
{
return $this->saleInfo;
}
/**
* @param string|null $saleInfo
*/
public function setSaleInfo(?string $saleInfo): void
{
$this->saleInfo = $saleInfo;
}
/**
* @return string|null
*/
public function getPersonalNote(): ?string
{
return $this->personalNote;
}
/**
* @param string|null $personalNote
*/
public function setPersonalNote(?string $personalNote): void
{
$this->personalNote = $personalNote;
}
/**
* @return string|null
*/
public function getApigeo(): ?string
{
return $this->apigeo;
}
/**
* @param string|null $apigeo
*/
public function setApigeo(?string $apigeo): void
{
$this->apigeo = $apigeo;
}
/**
* @return string|null
*/
public function getApitime(): ?string
{
return $this->apitime;
}
/**
* @param string|null $apitime
*/
public function setApitime(?string $apitime): void
{
$this->apitime = $apitime;
}
/**
* @return bool
*/
public function isActive(): bool
{
return (boolean)$this->isActive;
}
/**
* @param bool $isActive
*/
public function setIsActive(bool $isActive): void
{
$this->isActive = $isActive;
}
/**
* @return bool
*/
public function isDeleted(): bool
{
return (boolean)$this->isDeleted;
}
/**
* @param bool $isDeleted
*/
public function setIsDeleted(bool $isDeleted): void
{
$this->isDeleted = $isDeleted;
}
/**
* @return string|null
*/
public function getExtent(): ?string
{
return $this->extent;
}
/**
* @param string|null $extent
*/
public function setExtent(?string $extent): void
{
$this->extent = $extent;
}
/**
* @return string|null
*/
public function getExtentLabel(): ?string
{
return $this->extentLabel;
}
/**
* @param string|null $extentLabel
*/
public function setExtentLabel(?string $extentLabel): void
{
$this->extentLabel = $extentLabel;
}
/**
* @return string|null
*/
public function getYtVideo(): ?string
{
return $this->ytVideo;
}
/**
* @param string|null $ytVideo
*/
public function setYtVideo(?string $ytVideo): void
{
$this->ytVideo = $ytVideo;
}
/**
* @return float|null
*/
public function getLatitude(): ?float
{
$shoppingmall = $this->getShoppingMall();
if(isset($shoppingmall)){
return $shoppingmall->getLatitude();
}
return $this->latitude;
}
/**
* @param float|null $latitude
*/
public function setLatitude(?float $latitude): void
{
$this->latitude = $latitude;
}
/**
* @return float|null
*/
public function getLongitude(): ?float
{
$shoppingmall = $this->getShoppingMall();
if(isset($shoppingmall)){
return $shoppingmall->getLongitude();
}
return $this->longitude;
}
/**
* @param float|null $longitude
*/
public function setLongitude(?float $longitude): void
{
$this->longitude = $longitude;
}
/**
* @return string|null
*/
public function getSaleInfoArticle(): ?string
{
return $this->saleInfoArticle;
}
/**
* @param string|null $saleInfoArticle
*/
public function setSaleInfoArticle(?string $saleInfoArticle): void
{
$this->saleInfoArticle = $saleInfoArticle;
}
/**
* @return \App\Entity\City
*/
public function getCity(): ?\App\Entity\City
{
return $this->city;
}
/**
* @param \App\Entity\City $city
*/
public function setCity(\App\Entity\City $city): void
{
$this->city = $city;
}
/**
* @return \App\Entity\Shoppingarea
*/
public function getShoppingArea(): ?\App\Entity\Shoppingarea
{
return $this->shoppingArea;
}
/**
* @param \App\Entity\Shoppingarea $shoppingArea
*/
public function setShoppingArea(\App\Entity\Shoppingarea $shoppingArea): void
{
$this->shoppingArea = $shoppingArea;
}
/**
* @return \App\Entity\Shoppingmall
*/
public function getShoppingMall()
{
return $this->shoppingMall;
}
/**
* @param \App\Entity\Shoppingmall $shoppingMall
*/
public function setShoppingMall(\App\Entity\Shoppingmall $shoppingMall): void
{
$this->shoppingMall = $shoppingMall;
}
/**
* @return \App\Entity\Shoptype
*/
public function getType(): ?\App\Entity\Shoptype
{
return $this->type;
}
/**
* @param \App\Entity\Shoptype $type
*/
public function setType(\App\Entity\Shoptype $type): void
{
$this->type = $type;
}
/**
* Return data in array. Used by REST API
*
* @return array
*/
public function toArray($onlyValue = false)
{
$return = [
'id' => $this->getId(),
'name' => $this->getName(),
'type' => (string)$this->getType(),
'brands' => count($this->getBrands()),
'shopkinds' => implode(', ', $this->getShopkindsStrings()),
'categories' => implode(', ', $this->getShopHasCategoriesStrings()),
'street' => $this->getStreet(),
'city' => (string)$this->getCity(),
'shoppingMall' => (string)$this->getShoppingMall(),
'zip' => $this->getZip(),
'extent' => $this->getExtent(),
'extentLabel' => $this->getExtentLabel(),
'shoppingArea' => (string)$this->getShoppingArea(),
'www' => $this->getWww(),
'openingHr' => $this->getOpeningHr(),
'isNew' => $this->getIsNew(),
'latitude' => $this->getLatitude(),
'longitude' => $this->getLongitude(),
'apigeo' => $this->getApigeo(),
'apitime' => $this->getApitime(),
];
if ($onlyValue) {
return array_values($return);
} else {
return $return;
}
}
public function __toString()
{
return '('.$this->getId().') - '.$this->getName();
}
public function getIsNew(): ?bool
{
return $this->isNew;
}
public function setIsNew(?bool $isNew): self
{
$this->isNew = $isNew;
return $this;
}
public function getIsNewDate(): ?\DateTimeInterface
{
return $this->isNewDate;
}
public function setIsNewDate(?\DateTimeInterface $isNewDate): self
{
$this->isNewDate = $isNewDate;
return $this;
}
/**
* @return \App\Entity\Category|null
*/
public function getPrimaryCategory()
{
/** @var \App\Entity\ShopHasCategories $shopHasCategory */
foreach ($this->shopHasCategories as $shopHasCategory) {
if ($shopHasCategory->isPrimary()) {
return $shopHasCategory->getCategory();
}
}
}
/**
* @param Category $category
*
* @return bool
*/
public function setPrimaryCategory(Category $category)
{
if($this->hasCategory($category)){
/** @var ShopHasCategories $shopHasCategory */
foreach ($this->shopHasCategories as $shopHasCategory) {
if($shopHasCategory->getCategory()->getId() == $category->getId()){
$shopHasCategory->setIsPrimary(true);
}else{
$shopHasCategory->setIsPrimary(false);
}
}
}
return false;
}
/**
* @param Category $category
* @return bool
*/
public function hasCategory(Category $category)
{
/** @var \App\Entity\ShopHasCategories $shopHasCategory */
foreach ($this->shopHasCategories as $shopHasCategory) {
if($shopHasCategory->getCategory()->getId() === $category->getId()){
return true;
}
}
return false;
}
/**
* @return \App\Entity\Company|null
*/
public function getCompany()
{
// $chs = $this->getCompanyHasShop();
// if(is_null($chs)){
// return $chs->getCompany();
// }
return null;
}
/**
* @param \App\Entity\Company $company
* @return $this
* @throws \Exception
*/
public function setCompany(Company $company): self
{
throw new Exception('Method is deprecated. Please use setCompanyHasShop method');
}
/**
* @return CompanyHasShop|null
*/
public function getCompanyHasShop(): ?Collection
{
return $this->companyHasShop;
}
/**
* @param $companyHasShop
* @return $this
*/
public function setCompanyHasShop($companyHasShop): self
{
$this->companyHasShop = $companyHasShop;
return $this;
}
/**
* @return DateTime|null
*/
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
/**
* @param string|null $createdAt
*/
public function setCreatedAt(?string $createdAt): void
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime|null
*/
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
/**
* @param string|null $updatedAt
*/
public function setUpdatedAt(?string $updatedAt): void
{
$this->updatedAt = $updatedAt;
}
}