src/Entity/CustomerGroup.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator\Constraints as AppAssert;
  4. use App\Entity\Product\ConfirmedProduct;
  5. use DateTime;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Exception;
  9. use JMS\Serializer\Annotation\ExclusionPolicy;
  10. use JMS\Serializer\Annotation\Expose;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * Class CustomerGroup
  14.  *
  15.  * @ORM\Entity(repositoryClass="App\Repository\CustomerGroupRepository")
  16.  * @ORM\Table(name="malys_customer_group")
  17.  * @ORM\HasLifecycleCallbacks()
  18.  * @AppAssert\CustomerGroup
  19.  * @ExclusionPolicy("all")
  20.  */
  21. class CustomerGroup
  22. {
  23.     /**
  24.      * @var integer
  25.      *
  26.      * @ORM\Column(name="id", type="integer")
  27.      * @ORM\Id
  28.      * @ORM\GeneratedValue(strategy="AUTO")
  29.      */
  30.     protected $id;
  31.     /**
  32.      * @var string
  33.      *
  34.      * @ORM\Column(name="name", type="string", length=255, nullable=false)
  35.      * @Assert\NotBlank
  36.      * @Expose
  37.      */
  38.     protected $name;
  39.     /**
  40.      * @var DateTime
  41.      *
  42.      * @ORM\Column(name="createdAt", type="datetime", nullable=false)
  43.      */
  44.     protected $createdAt;
  45.     /**
  46.      * @var DateTime
  47.      *
  48.      * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
  49.      */
  50.     protected $updatedAt;
  51.     /**
  52.      * @var ArrayCollection
  53.      * One CustomerGroup has Many Customers.
  54.      * @ORM\OneToMany(targetEntity="Customer", mappedBy="customerGroup", cascade={"refresh"})
  55.      */
  56.     protected $customers;
  57.     /**
  58.      * @var boolean
  59.      *
  60.      * @ORM\Column(name="useProdControl", type="boolean", options={"default" : false})
  61.      */
  62.     protected $useProdControl false;
  63.     /**
  64.      * @ORM\ManyToOne (targetEntity="User")
  65.      */
  66.     /**
  67.      * @ORM\ManyToMany (targetEntity="App\Entity\User", inversedBy="managedGroups")
  68.      * @ORM\JoinTable (name="malys_admin_customer_group")
  69.      * @Assert\Count (min=0, minMessage="Vous devez choisir au moins {{min}} administrateur")
  70.      */
  71.     protected $admins;
  72.     /**
  73.      * @ORM\ManyToMany(targetEntity="App\Entity\Product\ConfirmedProduct", inversedBy="mercuCustomerGroups")
  74.      * @ORM\JoinTable(
  75.      *     name="malys_customer_groups_products",
  76.      *     joinColumns={@ORM\JoinColumn(name="customer_group_id", referencedColumnName="id")},
  77.      *     inverseJoinColumns={@ORM\JoinColumn(name="product_id", referencedColumnName="id")}
  78.      * )
  79.      */
  80.     protected $mercuProducts;
  81.     /**
  82.      * @var ArrayCollection
  83.      * One CustomerGroup has Many GuestProducts.
  84.      * @ORM\OneToMany(targetEntity="App\Entity\Product\GuestProduct", mappedBy="byCustomerGroup", cascade={"remove"})
  85.      */
  86.     protected $guestProducts;
  87.     /**
  88.      * @var string
  89.      *
  90.      * @ORM\Column(name="source_system", type="string", nullable=true)
  91.      * @Expose
  92.      */
  93.     protected $sourceSystem;
  94.     public function __construct()
  95.     {
  96.         $this->mercuProducts = new ArrayCollection();
  97.         $this->admins        = new ArrayCollection();
  98.         $this->customers     = new ArrayCollection();
  99.     }
  100.     public function __toString()
  101.     {
  102.         return $this->name;
  103.     }
  104.     /**
  105.      * @return int
  106.      */
  107.     public function getId()
  108.     {
  109.         return $this->id;
  110.     }
  111.     /**
  112.      * @return DateTime
  113.      */
  114.     public function getCreatedAt()
  115.     {
  116.         return $this->createdAt;
  117.     }
  118.     /**
  119.      * Set createdAt
  120.      *
  121.      * @return CustomerGroup
  122.      * @throws Exception
  123.      * @ORM\PrePersist
  124.      */
  125.     public function setCreatedAt()
  126.     {
  127.         $this->createdAt = new DateTime();
  128.         $this->updatedAt = new DateTime();
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return DateTime
  133.      */
  134.     public function getUpdatedAt()
  135.     {
  136.         return $this->updatedAt;
  137.     }
  138.     /**
  139.      * Set updatedAt
  140.      *
  141.      * @return CustomerGroup
  142.      * @throws Exception
  143.      * @ORM\PreUpdate
  144.      */
  145.     public function setUpdatedAt()
  146.     {
  147.         $this->updatedAt = new DateTime();
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return ArrayCollection
  152.      */
  153.     public function getCustomers()
  154.     {
  155.         return $this->customers;
  156.     }
  157.     /**
  158.      * @param ArrayCollection $customers
  159.      */
  160.     public function setCustomers(ArrayCollection $customers)
  161.     {
  162.         $this->customers $customers;
  163.     }
  164.     /**
  165.      * @return string
  166.      */
  167.     public function getName()
  168.     {
  169.         return $this->name;
  170.     }
  171.     /**
  172.      * @param string $name
  173.      */
  174.     public function setName(string $name)
  175.     {
  176.         $this->name $name;
  177.     }
  178.     /**
  179.      * @return bool
  180.      */
  181.     public function getUseProdControl(): bool
  182.     {
  183.         return $this->useProdControl;
  184.     }
  185.     /**
  186.      * @param bool $useProdControl
  187.      */
  188.     public function setUseProdControl(bool $useProdControl): void
  189.     {
  190.         $this->useProdControl $useProdControl;
  191.     }
  192.     /**
  193.      * @return mixed
  194.      */
  195.     public function getMercuProducts()
  196.     {
  197.         return $this->mercuProducts;
  198.     }
  199.     /**
  200.      * @param mixed $mercuProducts
  201.      */
  202.     public function setMercuProducts($mercuProducts)
  203.     {
  204.         $this->mercuProducts $mercuProducts;
  205.     }
  206.     public function addMercuProduct(ConfirmedProduct $product)
  207.     {
  208.         if (! $this->mercuProducts->contains($product)) {
  209.             $this->mercuProducts->add($product);
  210.             $product->forceUpdateAt();
  211.         }
  212.         return $this;
  213.     }
  214.     public function removeMercuProduct(ConfirmedProduct $product)
  215.     {
  216.         if ($this->mercuProducts->contains($product)) {
  217.             $this->mercuProducts->removeElement($product);
  218.         }
  219.         return $this;
  220.     }
  221.     /**
  222.      * @return mixed
  223.      */
  224.     public function getAdmins()
  225.     {
  226.         return $this->admins;
  227.     }
  228.     /**
  229.      * @param mixed $admins
  230.      */
  231.     public function setAdmins($admins): void
  232.     {
  233.         $this->admins $admins;
  234.     }
  235.     public function addAdmin(User $user)
  236.     {
  237.         if (! $this->admins->contains($user)) {
  238.             $this->admins->add($user);
  239.         }
  240.     }
  241.     public function removeAdmin(User $user)
  242.     {
  243.         if ($this->admins->contains($user)) {
  244.             $this->admins->removeElement($user);
  245.         }
  246.     }
  247.     /**
  248.      * @return string
  249.      */
  250.     public function getSourceSystem(): ?string
  251.     {
  252.         return $this->sourceSystem;
  253.     }
  254.     /**
  255.      * @param string $sourceSystem
  256.      */
  257.     public function setSourceSystem(?string $sourceSystem): void
  258.     {
  259.         $this->sourceSystem $sourceSystem;
  260.     }
  261. }