<?php
namespace App\Entity;
use App\Validator\Constraints as AppAssert;
use App\Model\ProductFeaturing as ProductFeaturingModel;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* ProductFeaturing
*
* @ORM\Table(name="product_featuring")
* @ORM\Entity(repositoryClass="App\Repository\ProductFeaturingRepository")
* @ORM\HasLifecycleCallbacks()
* @AppAssert\ProductFeaturing
*/
class ProductFeaturing
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
* @Assert\NotBlank
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="subtitle", type="string", length=255, nullable=true)
*/
private $subtitle;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
protected $description;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Supplier")
* @ORM\JoinTable(name="malys_product_feature_supplier_to_avoid")
*/
protected $ruleSuppliersToAvoid;
/**
* @var integer
*
* @ORM\Column(name="rotation_rythm", type="integer")
* @Assert\NotBlank
* @Assert\GreaterThanOrEqual(
* value = 1
* )
*/
protected $rotationRythm = 2;
/**
* @var string
*
* @ORM\Column(name="listing_type", type="string", length=255)
* @Assert\NotBlank
* @Assert\Choice(callback="getAvailableListingTypes")
*/
protected $listingType;
/**
* @var DateTime
*
* @ORM\Column(name="start", type="datetime", nullable=false)
* @Assert\NotBlank
* @Assert\DateTime()
*/
protected $start;
/**
* @var DateTime
*
* @ORM\Column(name="end", type="datetime", nullable=false)
* @Assert\NotBlank
* @Assert\DateTime()
* @Assert\GreaterThan(propertyPath="start")
*/
protected $end;
/**
*
* @ORM\ManyToOne(targetEntity="Tag")
* @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
*/
protected $tag;
/**
*
* @ORM\ManyToOne(targetEntity="Supplier")
* @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
*/
protected $supplier;
/**
* @var DateTime
*
* @ORM\Column(name="createdAt", type="datetime", nullable=false)
*/
protected $createdAt;
/**
* @var DateTime
*
* @ORM\Column(name="updatedAt", type="datetime", nullable=false)
*/
protected $updatedAt;
/**
* @var boolean
*
* @ORM\Column(name="enabled", type="boolean" )
*/
protected $enabled = true;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductFeaturingRotation", mappedBy="productFeaturing", cascade={"all"}, orphanRemoval=true)
* @ORM\OrderBy({"priority" = "ASC"})
* @Assert\Valid
*/
protected $rotations;
/**
* @var integer
*
* @ORM\Column(name="priority", type="integer")
* @Assert\NotBlank
* @Assert\GreaterThanOrEqual(
* value = 1
* )
*/
protected $priority = 10;
/**
* @var string
*
* @ORM\Column(name="color_scheme", type="string", length=255, nullable=true)
* @Assert\NotBlank
* @Assert\Choice(callback="getAvailableColorSchemes")
*/
private $colorScheme;
/**
* @var string
*
* @ORM\Column(name="title_icon", type="string", length=255, nullable=false)
*/
protected $titleIcon;
public function __construct()
{
// Defaut stat
$start = new DateTime();
$this->setStart($start);
// Default end
$end = new DateTime();
$end->modify('+7 days');
$end->setTime(23, 59, 59);
$this->setEnd($end);
$this->rotations = new ArrayCollection();
}
public function getAvailableColorSchemes()
{
return ProductFeaturingModel::availableColorSchemesKey();
}
public static function getAvailableListingTypes()
{
return ProductFeaturingModel::availableTypesKeys();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set title.
*
* @param string $title
*
* @return ProductFeaturing
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title.
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @return DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set createdAt
*
* @return Message
* @ORM\PrePersist
*/
public function setCreatedAt()
{
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
return $this;
}
/**
* @return DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set updatedAt
*
* @return Message
* @ORM\PreUpdate
*/
public function setUpdatedAt()
{
$this->updatedAt = new DateTime();
return $this;
}
/**
* @return string
*/
public function getSubtitle()
{
return $this->subtitle;
}
/**
* @param string $subtitle
*/
public function setSubtitle(string $subtitle = null)
{
$this->subtitle = $subtitle;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription(string $description = null)
{
$this->description = $description;
}
/**
* @return mixed
*/
public function getRuleSuppliersToAvoid()
{
return $this->ruleSuppliersToAvoid;
}
/**
* @param mixed $ruleSuppliersToAvoid
*/
public function setRuleSuppliersToAvoid($ruleSuppliersToAvoid)
{
$this->ruleSuppliersToAvoid = $ruleSuppliersToAvoid;
}
/**
* @return int
*/
public function getRotationRythm(): int
{
return $this->rotationRythm;
}
/**
* @param int $rotationRythm
*/
public function setRotationRythm(int $rotationRythm)
{
$this->rotationRythm = $rotationRythm;
}
/**
* @return string
*/
public function getListingType()
{
return $this->listingType;
}
/**
* @param string $listingType
*/
public function setListingType(string $listingType)
{
$this->listingType = $listingType;
}
/**
* @return DateTime
*/
public function getStart()
{
return $this->start;
}
/**
* @param DateTime $start
*/
public function setStart(DateTime $start)
{
$this->start = $start;
}
/**
* @return DateTime
*/
public function getEnd()
{
return $this->end;
}
/**
* @param DateTime $end
*/
public function setEnd(DateTime $end)
{
$this->end = $end;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* @param bool $enabled
*/
public function setEnabled(bool $enabled)
{
$this->enabled = $enabled;
}
/**
* @return Category
*/
public function getTag()
{
return $this->tag;
}
/**
* @param Category $tag
*/
public function setTag(Tag $tag)
{
$this->tag = $tag;
}
/**
* @return mixed
*/
public function getRotations()
{
return $this->rotations;
}
/**
* @param mixed $rotations
*/
public function setRotations($rotations)
{
$this->rotations = $rotations;
}
public function addRotation(ProductFeaturingRotation $rotation)
{
$this->rotations->add($rotation);
$rotation->setProductFeaturing($this);
return $this;
}
public function removeRotation(ProductFeaturingRotation $rotation)
{
$this->rotations->removeElement($rotation);
$rotation->setProductFeaturing(null);
return $this;
}
/**
* @return mixed
*/
public function getSupplier()
{
return $this->supplier;
}
/**
* @param mixed $supplier
*/
public function setSupplier(Supplier $supplier)
{
$this->supplier = $supplier;
}
/**
* @return int
*/
public function getPriority()
{
return $this->priority;
}
/**
* @param int $priority
*/
public function setPriority(int $priority)
{
$this->priority = $priority;
}
/**
* @return string
*/
public function getColorScheme()
{
return $this->colorScheme;
}
/**
* @param string $colorScheme
*/
public function setColorScheme(string $colorScheme)
{
$this->colorScheme = $colorScheme;
}
/**
* @return string
*/
public function getTitleIcon()
{
return $this->titleIcon;
}
/**
* @param string $titleIcon
*/
public function setTitleIcon(string $titleIcon)
{
$this->titleIcon = $titleIcon;
}
}