<?php
namespace App\Entity\Gos;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Table()
* @ORM\Entity(repositoryClass="App\Repository\PaymentSystemRepository")
* @ORM\HasLifecycleCallbacks
*/
class PaymentSystem
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var bool
*
* @ORM\Column(name="isActive", type="boolean", nullable=true)
*/
private $isActive;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $name;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(unique=true)
*/
private $slug;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Gos\Notify", mappedBy="paymentSystem")
*/
private $notify;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\PortalSettings", mappedBy="paymentSystem")
*/
private $portalSettings;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Gos\ProductVariant", mappedBy="paymentSystem")
*/
private $productVariant;
/**
* @ORM\OneToMany(targetEntity="PaymentOptions", mappedBy="paymentSystem", fetch="EAGER")
*/
private $paymentOptions;
/**
* @ORM\OneToMany(targetEntity="Cart", mappedBy="paymentSystem")
*/
private $cart;
/**
* @ORM\OneToMany(targetEntity="Orders", mappedBy="paymentSystem")
*/
private $orders;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/** @ORM\PrePersist() */
public function prePersist()
{
$this->createdAt = new \DateTime();
}
/** @ORM\PreUpdate() */
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
public function __construct()
{
$this->notify = new ArrayCollection();
$this->portalSettings = new ArrayCollection();
$this->productVariant = new ArrayCollection();
$this->cart = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->paymentOptions = new ArrayCollection();
}
public function __toString()
{
return (string)$this->name;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set isActive
*
* @param boolean $isActive
*
* @return PaymentSystem
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set name
*
* @param string $name
*
* @return PaymentSystem
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName(Country $country = null)
{
if ($country)
{
$paymentOptions = $this->getPaymentOptions($country);
if ($paymentOptions && !empty($paymentOptions->getPaymentName()))
{
return $paymentOptions->getPaymentName();
}
}
return $this->name;
}
/**
* Set slug
*
* @param string $slug
*
* @return PaymentSystem
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
*
* @return PaymentSystem
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*
* @return PaymentSystem
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Add notify
*
* @param \App\Entity\Gos\Notify $notify
*
* @return PaymentSystem
*/
public function addNotify(\App\Entity\Gos\Notify $notify)
{
$this->notify[] = $notify;
return $this;
}
/**
* Remove notify
*
* @param \App\Entity\Gos\Notify $notify
*/
public function removeNotify(\App\Entity\Gos\Notify $notify)
{
$this->notify->removeElement($notify);
}
/**
* Get notify
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getNotify()
{
return $this->notify;
}
/**
* Add portalSetting
*
* @param \App\Entity\Gos\PortalSettings $portalSetting
*
* @return PaymentSystem
*/
public function addPortalSetting(\App\Entity\Gos\PortalSettings $portalSetting)
{
$this->portalSettings[] = $portalSetting;
return $this;
}
/**
* Remove portalSetting
*
* @param \App\Entity\Gos\PortalSettings $portalSetting
*/
public function removePortalSetting(\App\Entity\Gos\PortalSettings $portalSetting)
{
$this->portalSettings->removeElement($portalSetting);
}
/**
* Get portalSettings
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getPortalSettings()
{
return $this->portalSettings;
}
/**
* @return Collection|ProductVariant[]
*/
public function getProductVariant(): Collection
{
return $this->productVariant;
}
public function addProductVariant(ProductVariant $productVariant): self
{
if (!$this->productVariant->contains($productVariant)) {
$this->productVariant[] = $productVariant;
$productVariant->addPaymentSystem($this);
}
return $this;
}
public function removeProductVariant(ProductVariant $productVariant): self
{
if ($this->productVariant->contains($productVariant)) {
$this->productVariant->removeElement($productVariant);
$productVariant->removePaymentSystem($this);
}
return $this;
}
public function getIcon()
{
if (!is_null($this->getPaymentOptions()) && !($this->getPaymentOptions() instanceof Collection))
return $this->getPaymentOptions()->getIcon();
return null;
}
/**
* @return Collection|Cart[]
*/
public function getCart(): Collection
{
return $this->cart;
}
public function addCart(Cart $cart): self
{
if (!$this->cart->contains($cart)) {
$this->cart[] = $cart;
$cart->setPaymentSystem($this);
}
return $this;
}
public function removeCart(Cart $cart): self
{
if ($this->cart->contains($cart)) {
$this->cart->removeElement($cart);
// set the owning side to null (unless already changed)
if ($cart->getPaymentSystem() === $this) {
$cart->setPaymentSystem(null);
}
}
return $this;
}
/**
* @return Collection|Orders[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Orders $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setPaymentSystem($this);
}
return $this;
}
public function removeOrder(Orders $order): self
{
if ($this->orders->contains($order)) {
$this->orders->removeElement($order);
// set the owning side to null (unless already changed)
if ($order->getPaymentSystem() === $this) {
$order->setPaymentSystem(null);
}
}
return $this;
}
public function getPaymentOptions(Country $country = null)
{
if ($country)
{
foreach ($this->paymentOptions as $paymentOption)
{
if ($paymentOption->getCountry()->contains($country))
{
return $paymentOption;
}
}
}
return null;
}
public function addPaymentOption(PaymentOptions $paymentOption): self
{
if (!$this->paymentOptions->contains($paymentOption)) {
$this->paymentOptions[] = $paymentOption;
$paymentOption->setPaymentSystem($this);
}
return $this;
}
public function removePaymentOption(PaymentOptions $paymentOption): self
{
if ($this->paymentOptions->contains($paymentOption)) {
$this->paymentOptions->removeElement($paymentOption);
// set the owning side to null (unless already changed)
if ($paymentOption->getPaymentSystem() === $this) {
$paymentOption->setPaymentSystem(null);
}
}
return $this;
}
public function getPosition(Country $country = null, PortalSettings $portalSettings = null): ?int
{
if ($portalSettings && $portalSettings->getDefaultPaymentSystem() &&
$portalSettings->getDefaultPaymentSystem() === $this) return -1;
if ($country)
{
$paymentOptions = $this->getPaymentOptions($country);
if ($paymentOptions)
{
return $paymentOptions->getPosition();
}
}
return 0;
}
}