src/Entity/ProductFeaturing.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator\Constraints as AppAssert;
  4. use App\Model\ProductFeaturing as ProductFeaturingModel;
  5. use DateTime;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * ProductFeaturing
  11.  *
  12.  * @ORM\Table(name="product_featuring")
  13.  * @ORM\Entity(repositoryClass="App\Repository\ProductFeaturingRepository")
  14.  * @ORM\HasLifecycleCallbacks()
  15.  * @AppAssert\ProductFeaturing
  16.  */
  17. class ProductFeaturing
  18. {
  19.     /**
  20.      * @var int
  21.      *
  22.      * @ORM\Column(name="id", type="integer")
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue(strategy="AUTO")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @var string
  29.      *
  30.      * @ORM\Column(name="title", type="string", length=255)
  31.      * @Assert\NotBlank
  32.      */
  33.     private $title;
  34.     /**
  35.      * @var string
  36.      *
  37.      * @ORM\Column(name="subtitle", type="string", length=255, nullable=true)
  38.      */
  39.     private $subtitle;
  40.     /**
  41.      * @var string
  42.      *
  43.      * @ORM\Column(name="description", type="text", nullable=true)
  44.      */
  45.     protected $description;
  46.     /**
  47.      * @ORM\ManyToMany(targetEntity="App\Entity\Supplier")
  48.      * @ORM\JoinTable(name="malys_product_feature_supplier_to_avoid")
  49.      */
  50.     protected $ruleSuppliersToAvoid;
  51.     /**
  52.      * @var integer
  53.      *
  54.      * @ORM\Column(name="rotation_rythm", type="integer")
  55.      * @Assert\NotBlank
  56.      * @Assert\GreaterThanOrEqual(
  57.      *     value = 1
  58.      * )
  59.      */
  60.     protected $rotationRythm 2;
  61.     /**
  62.      * @var string
  63.      *
  64.      * @ORM\Column(name="listing_type", type="string", length=255)
  65.      * @Assert\NotBlank
  66.      * @Assert\Choice(callback="getAvailableListingTypes")
  67.      */
  68.     protected $listingType;
  69.     /**
  70.      * @var DateTime
  71.      *
  72.      * @ORM\Column(name="start", type="datetime", nullable=false)
  73.      * @Assert\NotBlank
  74.      * @Assert\DateTime()
  75.      */
  76.     protected $start;
  77.     /**
  78.      * @var DateTime
  79.      *
  80.      * @ORM\Column(name="end", type="datetime", nullable=false)
  81.      * @Assert\NotBlank
  82.      * @Assert\DateTime()
  83.      * @Assert\GreaterThan(propertyPath="start")
  84.      */
  85.     protected $end;
  86.     /**
  87.      *
  88.      * @ORM\ManyToOne(targetEntity="Tag")
  89.      * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
  90.      */
  91.     protected $tag;
  92.     /**
  93.      *
  94.      * @ORM\ManyToOne(targetEntity="Supplier")
  95.      * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
  96.      */
  97.     protected $supplier;
  98.     /**
  99.      * @var DateTime
  100.      *
  101.      * @ORM\Column(name="createdAt", type="datetime", nullable=false)
  102.      */
  103.     protected $createdAt;
  104.     /**
  105.      * @var DateTime
  106.      *
  107.      * @ORM\Column(name="updatedAt", type="datetime", nullable=false)
  108.      */
  109.     protected $updatedAt;
  110.     /**
  111.      * @var boolean
  112.      *
  113.      * @ORM\Column(name="enabled", type="boolean" )
  114.      */
  115.     protected $enabled true;
  116.     /**
  117.      * @ORM\OneToMany(targetEntity="App\Entity\ProductFeaturingRotation", mappedBy="productFeaturing", cascade={"all"}, orphanRemoval=true)
  118.      * @ORM\OrderBy({"priority" = "ASC"})
  119.      * @Assert\Valid
  120.      */
  121.     protected $rotations;
  122.     /**
  123.      * @var integer
  124.      *
  125.      * @ORM\Column(name="priority", type="integer")
  126.      * @Assert\NotBlank
  127.      * @Assert\GreaterThanOrEqual(
  128.      *     value = 1
  129.      * )
  130.      */
  131.     protected $priority 10;
  132.     /**
  133.      * @var string
  134.      *
  135.      * @ORM\Column(name="color_scheme", type="string", length=255, nullable=true)
  136.      * @Assert\NotBlank
  137.      * @Assert\Choice(callback="getAvailableColorSchemes")
  138.      */
  139.     private $colorScheme;
  140.     /**
  141.      * @var string
  142.      *
  143.      * @ORM\Column(name="title_icon", type="string", length=255, nullable=false)
  144.      */
  145.     protected $titleIcon;
  146.     public function __construct()
  147.     {
  148.         // Defaut stat
  149.         $start = new DateTime();
  150.         $this->setStart($start);
  151.         // Default end
  152.         $end = new DateTime();
  153.         $end->modify('+7 days');
  154.         $end->setTime(235959);
  155.         $this->setEnd($end);
  156.         $this->rotations = new ArrayCollection();
  157.     }
  158.     public function getAvailableColorSchemes()
  159.     {
  160.         return ProductFeaturingModel::availableColorSchemesKey();
  161.     }
  162.     public static function getAvailableListingTypes()
  163.     {
  164.         return ProductFeaturingModel::availableTypesKeys();
  165.     }
  166.     /**
  167.      * Get id.
  168.      *
  169.      * @return int
  170.      */
  171.     public function getId()
  172.     {
  173.         return $this->id;
  174.     }
  175.     /**
  176.      * Set title.
  177.      *
  178.      * @param string $title
  179.      *
  180.      * @return ProductFeaturing
  181.      */
  182.     public function setTitle($title)
  183.     {
  184.         $this->title $title;
  185.         return $this;
  186.     }
  187.     /**
  188.      * Get title.
  189.      *
  190.      * @return string
  191.      */
  192.     public function getTitle()
  193.     {
  194.         return $this->title;
  195.     }
  196.     /**
  197.      * @return DateTime
  198.      */
  199.     public function getCreatedAt()
  200.     {
  201.         return $this->createdAt;
  202.     }
  203.     /**
  204.      * Set createdAt
  205.      *
  206.      * @return Message
  207.      * @ORM\PrePersist
  208.      */
  209.     public function setCreatedAt()
  210.     {
  211.         $this->createdAt = new DateTime();
  212.         $this->updatedAt = new DateTime();
  213.         return $this;
  214.     }
  215.     /**
  216.      * @return DateTime
  217.      */
  218.     public function getUpdatedAt()
  219.     {
  220.         return $this->updatedAt;
  221.     }
  222.     /**
  223.      * Set updatedAt
  224.      *
  225.      * @return Message
  226.      * @ORM\PreUpdate
  227.      */
  228.     public function setUpdatedAt()
  229.     {
  230.         $this->updatedAt = new DateTime();
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return string
  235.      */
  236.     public function getSubtitle()
  237.     {
  238.         return $this->subtitle;
  239.     }
  240.     /**
  241.      * @param string $subtitle
  242.      */
  243.     public function setSubtitle(string $subtitle null)
  244.     {
  245.         $this->subtitle $subtitle;
  246.     }
  247.     /**
  248.      * @return string
  249.      */
  250.     public function getDescription()
  251.     {
  252.         return $this->description;
  253.     }
  254.     /**
  255.      * @param string $description
  256.      */
  257.     public function setDescription(string $description null)
  258.     {
  259.         $this->description $description;
  260.     }
  261.     /**
  262.      * @return mixed
  263.      */
  264.     public function getRuleSuppliersToAvoid()
  265.     {
  266.         return $this->ruleSuppliersToAvoid;
  267.     }
  268.     /**
  269.      * @param mixed $ruleSuppliersToAvoid
  270.      */
  271.     public function setRuleSuppliersToAvoid($ruleSuppliersToAvoid)
  272.     {
  273.         $this->ruleSuppliersToAvoid $ruleSuppliersToAvoid;
  274.     }
  275.     /**
  276.      * @return int
  277.      */
  278.     public function getRotationRythm(): int
  279.     {
  280.         return $this->rotationRythm;
  281.     }
  282.     /**
  283.      * @param int $rotationRythm
  284.      */
  285.     public function setRotationRythm(int $rotationRythm)
  286.     {
  287.         $this->rotationRythm $rotationRythm;
  288.     }
  289.     /**
  290.      * @return string
  291.      */
  292.     public function getListingType()
  293.     {
  294.         return $this->listingType;
  295.     }
  296.     /**
  297.      * @param string $listingType
  298.      */
  299.     public function setListingType(string $listingType)
  300.     {
  301.         $this->listingType $listingType;
  302.     }
  303.     /**
  304.      * @return DateTime
  305.      */
  306.     public function getStart()
  307.     {
  308.         return $this->start;
  309.     }
  310.     /**
  311.      * @param DateTime $start
  312.      */
  313.     public function setStart(DateTime $start)
  314.     {
  315.         $this->start $start;
  316.     }
  317.     /**
  318.      * @return DateTime
  319.      */
  320.     public function getEnd()
  321.     {
  322.         return $this->end;
  323.     }
  324.     /**
  325.      * @param DateTime $end
  326.      */
  327.     public function setEnd(DateTime $end)
  328.     {
  329.         $this->end $end;
  330.     }
  331.     /**
  332.      * @return bool
  333.      */
  334.     public function isEnabled(): bool
  335.     {
  336.         return $this->enabled;
  337.     }
  338.     /**
  339.      * @param bool $enabled
  340.      */
  341.     public function setEnabled(bool $enabled)
  342.     {
  343.         $this->enabled $enabled;
  344.     }
  345.     /**
  346.      * @return Category
  347.      */
  348.     public function getTag()
  349.     {
  350.         return $this->tag;
  351.     }
  352.     /**
  353.      * @param Category $tag
  354.      */
  355.     public function setTag(Tag $tag)
  356.     {
  357.         $this->tag $tag;
  358.     }
  359.     /**
  360.      * @return mixed
  361.      */
  362.     public function getRotations()
  363.     {
  364.         return $this->rotations;
  365.     }
  366.     /**
  367.      * @param mixed $rotations
  368.      */
  369.     public function setRotations($rotations)
  370.     {
  371.         $this->rotations $rotations;
  372.     }
  373.     public function addRotation(ProductFeaturingRotation $rotation)
  374.     {
  375.         $this->rotations->add($rotation);
  376.         $rotation->setProductFeaturing($this);
  377.         return $this;
  378.     }
  379.     public function removeRotation(ProductFeaturingRotation $rotation)
  380.     {
  381.         $this->rotations->removeElement($rotation);
  382.         $rotation->setProductFeaturing(null);
  383.         return $this;
  384.     }
  385.     /**
  386.      * @return mixed
  387.      */
  388.     public function getSupplier()
  389.     {
  390.         return $this->supplier;
  391.     }
  392.     /**
  393.      * @param mixed $supplier
  394.      */
  395.     public function setSupplier(Supplier $supplier)
  396.     {
  397.         $this->supplier $supplier;
  398.     }
  399.     /**
  400.      * @return int
  401.      */
  402.     public function getPriority()
  403.     {
  404.         return $this->priority;
  405.     }
  406.     /**
  407.      * @param int $priority
  408.      */
  409.     public function setPriority(int $priority)
  410.     {
  411.         $this->priority $priority;
  412.     }
  413.     /**
  414.      * @return string
  415.      */
  416.     public function getColorScheme()
  417.     {
  418.         return $this->colorScheme;
  419.     }
  420.     /**
  421.      * @param string $colorScheme
  422.      */
  423.     public function setColorScheme(string $colorScheme)
  424.     {
  425.         $this->colorScheme $colorScheme;
  426.     }
  427.     /**
  428.      * @return string
  429.      */
  430.     public function getTitleIcon()
  431.     {
  432.         return $this->titleIcon;
  433.     }
  434.     /**
  435.      * @param string $titleIcon
  436.      */
  437.     public function setTitleIcon(string $titleIcon)
  438.     {
  439.         $this->titleIcon $titleIcon;
  440.     }
  441. }