<?php
namespace App\Entity\Ecommerce;
use App\Entity\Ecommerce\Abstracts\AbstractPurchasable;
use App\Entity\Room;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Cmf\Component\Routing\RouteReferrersInterface;
use WAM\Bundle\CoreBundle\Entity\Interfaces\SearchableEntityInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
use WAM\Bundle\CoreBundle\Annotation\SearchableFields;
use WAM\Bundle\CoreBundle\Annotation\AutocompleteFields;
use WAM\Bundle\CoreBundle\Model\Identifiable;
use WAM\Bundle\CoreBundle\Model\Translatable;
use WAM\Bundle\MediaBundle\Entity\Traits\GalleryTrait;
use WAM\Bundle\RoutingBundle\Entity\Interfaces\SeoBehaviourInterface;
use WAM\Bundle\RoutingBundle\Entity\Interfaces\SeoMetaReadInterface;
use WAM\Bundle\RoutingBundle\Entity\Traits\MultiRouteTrait;
use WAM\Bundle\RoutingBundle\Entity\Traits\SeoMetaTrait;
/**
* Class Gift.
*
* @SearchableFields(fields={
* "sku",
* "title",
* })
* @AutocompleteFields(fields={
* "sku",
* "title",
* })
*
* @author David Velasco <dvelasco@wearemarketing.com>
*
* @ORM\Entity()
*/
class Gift extends AbstractPurchasable implements TranslatableInterface, SearchableEntityInterface, RouteReferrersInterface, SeoMetaReadInterface, SeoBehaviourInterface
{
use Translatable;
use GalleryTrait;
use MultiRouteTrait;
const LIGHT_COLOR = 'white';
const DARK_COLOR = 'black';
/**
* @ORM\OneToMany(
* targetEntity="GiftHasExtra",
* mappedBy="gift",
* cascade={"persist"},
* orphanRemoval=true,
* )
*/
private $giftHasExtras;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Hotel")
* @ORM\JoinColumn(name="hotel_id", referencedColumnName="id", nullable=true)
*/
private $hotel;
/**
* Many Gifts have Many Rooms.
*
* @ORM\ManyToMany(targetEntity="App\Entity\Room")
* @ORM\JoinTable(name="app_gift_rooms",
* joinColumns={@ORM\JoinColumn(name="gift_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="room_id", referencedColumnName="id")}
* )
*/
private $rooms;
/**
* Many Gifts have Many Categories.
*
* @ORM\ManyToMany(targetEntity="App\Entity\Ecommerce\GiftCategory")
* @ORM\JoinTable(name="app_gift_gift_categories",
* joinColumns={@ORM\JoinColumn(name="gift_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")}
* )
*/
protected $giftCategories;
/**
* Many Gifts have Many Categories.
*
* @ORM\ManyToMany(targetEntity="App\Entity\Ecommerce\Gift")
* @ORM\JoinTable(name="app_gift_gift",
* joinColumns={@ORM\JoinColumn(name="gift1_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="gift2_id", referencedColumnName="id")}
* )
*/
protected $relatedGifts;
/**
* @ORM\Column(type="boolean")
*/
private $promoted = false;
/**
* @ORM\Column(type="integer")
*/
private $sales = 0;
/**
* @var string
*
* @ORM\Column(type="string", nullable=true)
*/
private $contactEmail;
/**
* @var string
*
* @ORM\Column(type="string", nullable=true)
*/
private $contactPhone;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Hotel")
* @ORM\JoinTable(name="app_gift__hotel")
*/
private Collection $hotels;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $titleColor = self::LIGHT_COLOR;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $shortTextColor = self::DARK_COLOR;
public function __construct()
{
parent::__construct();
$this->giftHasExtras = new ArrayCollection();
$this->rooms = new ArrayCollection();
$this->giftCategories = new ArrayCollection();
$this->relatedGifts= new ArrayCollection();
}
/**
* {@inheritdoc}
*/
public function setGiftHasExtras($giftHasExtras)
{
$this->giftHasExtras = new ArrayCollection();
foreach ($giftHasExtras as $giftHasExtra) {
$this->addGiftHasExtras($giftHasExtra);
}
}
/**
* {@inheritdoc}
*/
public function getGiftHasExtras()
{
return $this->giftHasExtras;
}
/**
* {@inheritdoc}
*/
public function addGiftHasExtras(GiftHasExtra $giftHasExtra)
{
$giftHasExtra->setGift($this);
$this->giftHasExtras[] = $giftHasExtra;
}
/**
* Getter for hotel.
*
* @return mixed
*/
public function getHotel()
{
if (!$this->getHotels()->isEmpty()) {
return $this->getHotels()->first();
}
}
/**
* Setter for hotel.
*
* @param mixed $hotel
*
* @return Gift
*/
public function setHotel($hotel)
{
$this->hotel = $hotel;
return $this;
}
/**
* @return string
*/
public function getContactEmail()
{
return $this->contactEmail;
}
/**
* @param string $contactEmail
*/
public function setContactEmail($contactEmail)
{
$this->contactEmail = $contactEmail;
}
/**
* @return string
*/
public function getContactPhone()
{
return $this->contactPhone;
}
/**
* @param string $contactPhone
*/
public function setContactPhone($contactPhone)
{
$this->contactPhone = $contactPhone;
}
public function setDescriptionList($descriptionList)
{
$this->translate(null, false)->setDescriptionList($descriptionList);
return $this;
}
public function getDescriptionList()
{
return $this->translate(null, false)->getDescriptionList();
}
public function setGiftTerms($giftTerms)
{
$this->translate(null, false)->setGiftTerms($giftTerms);
return $this;
}
public function getGiftTerms()
{
return $this->translate(null, false)->getGiftTerms();
}
public function setGiftConditions($giftConditions)
{
$this->translate(null, false)->setGiftConditions($giftConditions);
return $this;
}
public function getGiftConditions()
{
return $this->translate(null, false)->getGiftConditions();
}
public function setSubtitle($subtitle)
{
$this->translate(null, false)->setSubtitle($subtitle);
return $this;
}
public function getSubtitle()
{
return $this->translate(null, false)->getSubtitle();
}
public function setTitle($title): void
{
$this->translate(null, false)->setTitle($title);
}
public function getTitle(): string
{
return $this->translate(null, false)->getTitle();
}
/**
* Getter for rooms.
*
* @return mixed
*/
public function getRooms()
{
return $this->rooms;
}
/**
* Setter for rooms.
*
* @param mixed $rooms
*
* @return Gift
*/
public function setRooms($rooms)
{
$this->rooms = $rooms;
return $this;
}
/**
* @param Room $room
*
* @return $this Self Object
*/
public function addRoom(Room $room)
{
if (!$this->rooms->contains($room)) {
$this->rooms->add($room);
}
return $this;
}
/**
* @param Room $room
*
* @return $this Self Object
*/
public function removeRoom(Room $room)
{
$this->rooms->removeElement($room);
return $this;
}
public function getTranslatableContactEmail($locale = null)
{
return $this->translate($locale, false)->getContactEmail();
}
public function getTranslatableContactPhone($locale = null)
{
return $this->translate($locale, false)->getContactPhone();
}
/**
* Getter for relatedGifts.
*
* @return mixed
*/
public function getRelatedGifts()
{
return $this->relatedGifts;
}
/**
* Setter for relatedGifts.
*
* @param mixed $relatedGifts
*
* @return Gift
*/
public function setRelatedGifts($relatedGifts)
{
$this->relatedGifts = $relatedGifts;
return $this;
}
/**
* @param Gift $relatedGift
*
* @return $this Self Object
*/
public function addRelatedGift(Gift $relatedGift)
{
if (!$this->relatedGifts->contains($relatedGift)) {
$this->relatedGifts->add($relatedGift);
}
return $this;
}
/**
* @param Gift $relatedGift
*
* @return $this Self Object
*/
public function removeRelatedGift(Gift $relatedGift)
{
$this->relatedGifts->removeElement($relatedGift);
return $this;
}
/**
* Getter for categories.
*
* @return mixed
*/
public function getGiftCategories()
{
return $this->giftCategories;
}
/**
* Setter for categories.
*
* @param mixed $categories
*
* @return Gift
*/
public function setGiftCategories($categories)
{
$this->giftCategories = $categories;
return $this;
}
/**
* @param GiftCategory $category
*
* @return $this Self Object
*/
public function addGiftCategory(GiftCategory $category)
{
if (!$this->giftCategories->contains($category)) {
$this->giftCategories->add($category);
}
return $this;
}
/**
* @param GiftCategory $category
*
* @return $this Self Object
*/
public function removeGiftCategory(GiftCategory $category)
{
$this->giftCategories->removeElement($category);
return $this;
}
/**
* Getter for promoted.
*
* @return mixed
*/
public function getPromoted()
{
return $this->promoted;
}
/**
* Setter for promoted.
*
* @return Gift
*/
public function setPromoted($promoted)
{
$this->promoted = $promoted;
return $this;
}
public function isPromoted()
{
return $this->promoted;
}
/**
* @return mixed
*/
public function getSales()
{
return $this->sales;
}
/**
* @param mixed $sales
*/
public function setSales($sales)
{
$this->sales = $sales;
}
public function addSale()
{
$this->setSales($this->getSales() + 1);
}
public function setGiftInfo1($giftInfo1)
{
$this->translate(null, false)->setGiftInfo1($giftInfo1);
return $this;
}
public function getGiftInfo1()
{
return $this->translate(null, false)->getGiftInfo1();
}
public function setGiftInfo2($giftInfo2)
{
$this->translate(null, false)->setGiftInfo2($giftInfo2);
return $this;
}
public function getGiftInfo2()
{
return $this->translate(null, false)->getGiftInfo2();
}
public function setSlug($slug): self
{
$this->translate(null, false)->setSlug($slug);
return $this;
}
public function getSlug()
{
return $this->translate(null, false)->getSlug();
}
public function getAutocompleteString()
{
return $this->getTitle().' - '.$this->getSku();
}
public function getSeoTitle(): ?string
{
return $this->getTranslation()->getTitle();
}
public function getSeoDescription(): ?string
{
return $this->getTranslation()->getDescription();
}
/**
* @return Collection
*/
public function getHotels(): Collection
{
return $this->hotels;
}
/**
* @param Collection $hotels
*/
public function setHotels(Collection $hotels): void
{
$this->hotels = $hotels;
}
public function __toString()
{
return (string) $this->getTitle();
}
/**
* @return string|null
*/
public function getTitleColor(): ?string
{
return $this->titleColor;
}
/**
* @param string|null $titleColor
*/
public function setTitleColor(?string $titleColor): void
{
$this->titleColor = $titleColor;
}
/**
* @return string|null
*/
public function getShortTextColor(): ?string
{
return $this->shortTextColor;
}
/**
* @param string|null $shortTextColor
*/
public function setShortTextColor(?string $shortTextColor): void
{
$this->shortTextColor = $shortTextColor;
}
public static function getStyles(): array
{
return [
self::DARK_COLOR => self::DARK_COLOR,
self::LIGHT_COLOR => self::LIGHT_COLOR,
];
}
}