<?php
namespace App\Entity;
use App\Validator\Constraints as AppAssert;
use App\Entity\Product\ConfirmedProduct;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use Symfony\Component\Validator\Constraints as Assert;
/**
* ProductFeaturing
*
* @ORM\Table(name="product_featuring_rotation")
* @ORM\Entity()
* @ORM\HasLifecycleCallbacks()
* @AppAssert\ProductFeaturingRotation
*/
class ProductFeaturingRotation
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var int
*
* @ORM\Column(name="priority", type="integer")
* @Assert\NotBlank()
* @Assert\GreaterThan(0)
*/
private $priority;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Product\ConfirmedProduct")
* @ORM\JoinTable(name="malys_product_feature_rotation_product",
* joinColumns={@ORM\JoinColumn(name="product_featuring_rotation_id", referencedColumnName="id", onDelete="cascade")}
* )
* @Assert\Count(min=1)
* @Assert\All(
* @Assert\Type("App\Entity\Product\ConfirmedProduct")
* )
*/
protected $products;
/**
* @var ProductFeaturing
*
* @ORM\ManyToOne(targetEntity="ProductFeaturing", inversedBy="rotations")
* @ORM\JoinColumn(name="product_featuring_id", referencedColumnName="id", onDelete="cascade")
*/
protected $productFeaturing;
/**
* @var DateTime
*
* @ORM\Column(name="createdAt", type="datetime", nullable=false)
* @Assert\DateTime()
*/
protected $createdAt;
/**
* @var DateTime
*
* @ORM\Column(name="updatedAt", type="datetime", nullable=false)
* @Assert\DateTime()
*/
protected $updatedAt;
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set createdAt
*
* @return ProductFeaturingRotation
* @throws Exception
* @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 ProductFeaturingRotation
* @throws Exception
* @ORM\PreUpdate
*/
public function setUpdatedAt()
{
$this->updatedAt = new DateTime();
return $this;
}
/**
* @return int
*/
public function getPriority()
{
return $this->priority;
}
/**
* @param int $priority
*/
public function setPriority(int $priority)
{
$this->priority = $priority;
}
/**
* @return mixed
*/
public function getProducts()
{
return $this->products;
}
/**
* @param mixed $products
*/
public function setProducts($products)
{
$this->products = $products;
}
public function addProduct(ConfirmedProduct $product)
{
if (!$this->products->contains($product)) {
$this->products->add($product);
}
return $this;
}
public function removeProduct(ConfirmedProduct $product)
{
$this->products->removeElement($product);
return $this;
}
/**
* @return ProductFeaturing
*/
public function getProductFeaturing(): ProductFeaturing
{
return $this->productFeaturing;
}
/**
* @param ProductFeaturing $productFeaturing
*/
public function setProductFeaturing($productFeaturing)
{
$this->productFeaturing = $productFeaturing;
}
}