src/Entity/CustomProductOrder.php line 21

Open in your IDE?
  1. <?php
  2.     namespace App\Entity;
  3.     use App\Repository\CustomProductOrderRepository;
  4.     use App\Traits\DateTrait;
  5.     use Doctrine\ORM\Mapping as ORM;
  6.     use JMS\Serializer\Annotation as Serializer;
  7.     use JMS\Serializer\Annotation\Expose;
  8.     use JMS\Serializer\Annotation\Groups;
  9.     use JMS\Serializer\Annotation\SerializedName;
  10.     use Symfony\Component\Validator\Constraints as Assert;
  11.     /**
  12.      * Commande d'un utilisateur pour un produit personnalisé
  13.      *
  14.      * @ORM\Entity(repositoryClass=CustomProductOrderRepository::class)
  15.      *
  16.      * @Serializer\ExclusionPolicy("ALL")
  17.      */
  18.     class CustomProductOrder
  19.     {
  20.         public const PENDING    0;
  21.         public const PROCESSING 1;
  22.         public const DONE       2;
  23.         public const CANCELED   3;
  24.         public const         STATUS = [self::PENDINGself::PROCESSINGself::DONEself::CANCELED];
  25.         /**
  26.          * @ORM\Id
  27.          * @ORM\GeneratedValue
  28.          * @ORM\Column(type="integer")
  29.          *
  30.          * @Expose
  31.          * @Groups({"customProductOrder:list"})
  32.          */
  33.         private ?int $id NULL;
  34.         /**
  35.          * Utilisateur qui passe la commande
  36.          *
  37.          * @ORM\ManyToOne(targetEntity=User::class, inversedBy="customProductOrders")
  38.          * @ORM\JoinColumn(nullable=false)
  39.          *
  40.          * @Expose
  41.          * @Groups({"customProductOrder:list"})
  42.          */
  43.         private ?User $user NULL;
  44.         /**
  45.          * Quantité commandée
  46.          *
  47.          * @ORM\Column(type="integer")
  48.          *
  49.          * @Assert\Positive
  50.          *
  51.          * @Expose
  52.          * @Groups({"customProductOrder:list"})
  53.          */
  54.         private ?int $quantity NULL;
  55.         /**
  56.          * Statut de la commande
  57.          *
  58.          * @ORM\Column(type="integer")
  59.          *
  60.          * @Assert\Choice(choices=CustomProductOrder::STATUS, message="Sélectionnez un statut valide")
  61.          *
  62.          * @Expose
  63.          * @Groups({"customProductOrder:list"})
  64.          */
  65.         private int $status 0;
  66.         /**
  67.          * Donnée du formulaire rempli par l'utilisateur
  68.          *
  69.          * @ORM\Column(type="json")
  70.          *
  71.          * @Assert\Json( message = "Vous avez entré un Json invalide" )
  72.          */
  73.         private ?string $formData NULL;
  74.         /**
  75.          * Produit commandé (figé à l'instant de la commande stocké en JSON)
  76.          *
  77.          * @ORM\Column(type="json")
  78.          *
  79.          * @Assert\Json( message = "Vous avez entré un Json invalide" )
  80.          *
  81.          */
  82.         private ?string $product NULL;
  83.         /**
  84.          * Type de produit
  85.          *
  86.          * @ORM\ManyToOne(targetEntity=CustomProductType::class, inversedBy="templates")
  87.          * @ORM\JoinColumn(nullable=false, name="type", referencedColumnName="slug")
  88.          *
  89.          * @Expose
  90.          * @Groups({"customProductOrder:list"})
  91.          */
  92.         private ?CustomProductType $type NULL;
  93.         use DateTrait;
  94.         public function getProductToArray(): array
  95.         {
  96.             return json_decode($this->productTRUE);
  97.         }
  98.         public function getFormDataToArray(): array
  99.         {
  100.             return json_decode($this->formDataTRUE);
  101.         }
  102.         /**
  103.          * Label du produit
  104.          *
  105.          * @Serializer\VirtualProperty()
  106.          * @SerializedName ("productLabel")
  107.          * @Groups ({"customProductOrder:list"})
  108.          *
  109.          * @return string
  110.          */
  111.         public function getProductLabel(): string
  112.         {
  113.             return $this->getProductToArray()[ 'label' ];
  114.         }
  115.         /**
  116.          * Description du produit
  117.          *
  118.          * @return string|null
  119.          */
  120.         public function getProductDescription(): ?string
  121.         {
  122.             return $this->getProductToArray()[ 'description' ];
  123.         }
  124.         /**
  125.          * Valeur (prix) du produit
  126.          *
  127.          * @return float
  128.          */
  129.         public function getProductValue(): float
  130.         {
  131.             return $this->getProductToArray()[ 'value' ] ?? 0;
  132.         }
  133.         /**
  134.          * Image du produit
  135.          *
  136.          * @return string|null
  137.          */
  138.         public function getProductImage(): ?string
  139.         {
  140.             return $this->getProductToArray()[ 'image' ];
  141.         }
  142.         /**
  143.          * Liste des contacts (email) quand il y a une demande pour ce produit
  144.          *
  145.          * @return array
  146.          */
  147.         public function getProductContacts(): array
  148.         {
  149.             return $this->getProductToArray()[ 'contacts' ];
  150.         }
  151.         public function getHumanizedStatus(): string
  152.         {
  153.             $labels = [
  154.                 'En attente de traitement',
  155.                 'En cours de traitement',
  156.                 'Traitée',
  157.                 'Annulée',
  158.             ];
  159.             return $labels$this->status ];
  160.         }
  161.         public function getId(): ?int
  162.         {
  163.             return $this->id;
  164.         }
  165.         public function getUser(): ?User
  166.         {
  167.             return $this->user;
  168.         }
  169.         public function setUser(?User $user): self
  170.         {
  171.             $this->user $user;
  172.             return $this;
  173.         }
  174.         public function getQuantity(): ?int
  175.         {
  176.             return $this->quantity;
  177.         }
  178.         public function setQuantity(int $quantity): self
  179.         {
  180.             $this->quantity $quantity;
  181.             return $this;
  182.         }
  183.         public function getStatus(): int
  184.         {
  185.             return $this->status;
  186.         }
  187.         public function setStatus(int $status): self
  188.         {
  189.             $this->status $status;
  190.             return $this;
  191.         }
  192.         public function getFormData(): ?string
  193.         {
  194.             return $this->formData;
  195.         }
  196.         public function setFormData(string $formData): self
  197.         {
  198.             $this->formData $formData;
  199.             return $this;
  200.         }
  201.         public function getProduct(): ?string
  202.         {
  203.             return $this->product;
  204.         }
  205.         public function setProduct(string $product): self
  206.         {
  207.             $this->product $product;
  208.             return $this;
  209.         }
  210.         public function getType(): ?CustomProductType
  211.         {
  212.             return $this->type;
  213.         }
  214.         public function setType(?CustomProductType $type): self
  215.         {
  216.             $this->type $type;
  217.             return $this;
  218.         }
  219.     }