src/Entity/Commande.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CommandeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassCommandeRepository::class)]
  9. class Commande
  10. {
  11.     const COMMANDE_STATUS_NOT_DEFINED 'non défini';
  12.     const COMMANDE_STATUS_SAISIE 'saisie';
  13.     const COMMANDE_STATUS_DESACTIVER 'desactiver';
  14.     const COMMANDE_STATUS_ATTRIBUER 'attribuer';
  15.     const COMMANDE_STATUS_EDITER 'editer';
  16.     const COMMANDE_STATUS_LIVRER 'livrer';
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     private ?int $id null;
  21.     #[ORM\ManyToOne]
  22.     private ?Events $event null;
  23.     #[ORM\ManyToOne]
  24.     #[ORM\JoinColumn(nullablefalse)]
  25.     private ?Session $session null;
  26.     #[ORM\ManyToOne]
  27.     private ?Cour $cour null;
  28.     #[ORM\ManyToOne]
  29.     private ?Category $category null;
  30.     #[ORM\Column(nullabletrue)]
  31.     private ?int $nbr null;
  32.     #[ORM\Column(length255nullabletrue)]
  33.     private ?string $groupement null;
  34.     #[ORM\Column(length255nullabletrue)]
  35.     private ?string $statut null;
  36.     #[ORM\Column(nullabletrue)]
  37.     private ?float $prix_unitaire null;
  38.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  39.     private ?string $note null;
  40.     #[ORM\Column(nullabletrue)]
  41.     private ?bool $option_commande null;
  42.     #[ORM\ManyToOne(cascade: ['persist'], inversedBy'commandes')]
  43.     #[ORM\JoinColumn(nullablefalse)]
  44.     private ?Client $client null;
  45.     #[ORM\OneToMany(mappedBy'commande'targetEntityAttribution::class, orphanRemovaltrue)]
  46.     private $attributions;
  47.     #[ORM\OneToMany(mappedBy'commande'targetEntitySpectateur::class, orphanRemovaltrue)]
  48.     private Collection $spectateurs;
  49.     #[ORM\OneToMany(mappedBy'commande'targetEntityCommandeActions::class, orphanRemovaltrue)]
  50.     private Collection $commandeActions;
  51.     #[ORM\Column(nullabletrue)]
  52.     private ?bool $isPapier null;
  53.     #[ORM\Column(length255nullabletrue)]
  54.     private ?string $contactEmail null;
  55.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  56.     private ?string $noteCommande null;
  57.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  58.     private ?string $noteClient null;
  59.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  60.     private ?string $noteSpectateur null;
  61.     public function __construct()
  62.     {
  63.         $this->statut self::COMMANDE_STATUS_SAISIE;
  64.         $this->attributions = new ArrayCollection();
  65.         $this->spectateurs = new ArrayCollection();
  66.         $this->commandeActions = new ArrayCollection();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function getEvent(): ?Events
  73.     {
  74.         return $this->event;
  75.     }
  76.     public function setEvent(?Events $event): self
  77.     {
  78.         $this->event $event;
  79.         return $this;
  80.     }
  81.     public function getSession(): ?Session
  82.     {
  83.         return $this->session;
  84.     }
  85.     public function setSession(?Session $session): self
  86.     {
  87.         $this->session $session;
  88.         return $this;
  89.     }
  90.     public function getCour(): ?Cour
  91.     {
  92.         return $this->cour;
  93.     }
  94.     public function setCour(?Cour $cour): self
  95.     {
  96.         $this->cour $cour;
  97.         return $this;
  98.     }
  99.     public function getCategory(): ?Category
  100.     {
  101.         return $this->category;
  102.     }
  103.     public function setCategory(?Category $category): self
  104.     {
  105.         $this->category $category;
  106.         return $this;
  107.     }
  108.     public function getNbr(): ?int
  109.     {
  110.         return $this->nbr;
  111.     }
  112.     public function setNbr(?int $nbr): self
  113.     {
  114.         $this->nbr $nbr;
  115.         return $this;
  116.     }
  117.     public function getGroupement(): ?string
  118.     {
  119.         return $this->groupement;
  120.     }
  121.     public function setGroupement(?string $groupement): self
  122.     {
  123.         $this->groupement $groupement;
  124.         return $this;
  125.     }
  126.     public function getStatut(): ?string
  127.     {
  128.         return $this->statut;
  129.     }
  130.     public function setStatut(?string $statut): self
  131.     {
  132.         $this->statut $statut;
  133.         return $this;
  134.     }
  135.     public function getPrixUnitaire(): ?float
  136.     {
  137.         return $this->prix_unitaire;
  138.     }
  139.     public function setPrixUnitaire(?float $prix_unitaire): self
  140.     {
  141.         $this->prix_unitaire $prix_unitaire;
  142.         return $this;
  143.     }
  144.     public function getNote(): ?string
  145.     {
  146.         return $this->note;
  147.     }
  148.     public function setNote(?string $note): self
  149.     {
  150.         $this->note $note;
  151.         return $this;
  152.     }
  153.     public function isOptionCommande(): ?bool
  154.     {
  155.         return $this->option_commande;
  156.     }
  157.     public function setOptionCommande(?bool $option_commande): self
  158.     {
  159.         $this->option_commande $option_commande;
  160.         return $this;
  161.     }
  162.     public function getClient(): ?Client
  163.     {
  164.         return $this->client;
  165.     }
  166.     public function setClient(?Client $client): self
  167.     {
  168.         $this->client $client;
  169.         return $this;
  170.     }
  171.     public function getTotal(): float
  172.     {
  173.         return $this->prix_unitaire $this->nbr;
  174.     }
  175.     public function __toString(): string
  176.     {
  177.         // TODO: Implement __toString() method.
  178.         return $this->getSession()->getCodeSession();
  179.     }
  180.     /**
  181.      * @return Collection|Attribution[]
  182.      */
  183.     public function getAttributions(): Collection
  184.     {
  185.         return $this->attributions;
  186.     }
  187.     public function addAttribution(Attribution $attribution): self
  188.     {
  189.         if (!$this->attributions->contains($attribution)) {
  190.             $this->attributions[] = $attribution;
  191.             $attribution->setCommande($this);
  192.         }
  193.         return $this;
  194.     }
  195.     public function removeAttribution(Attribution $attribution): self
  196.     {
  197.         if ($this->attributions->contains($attribution)) {
  198.             $this->attributions->removeElement($attribution);
  199.             // set the owning side to null (unless already changed)
  200.             if ($attribution->getCommande() === $this) {
  201.                 $attribution->setCommande(null);
  202.             }
  203.         }
  204.         return $this;
  205.     }
  206.     /**
  207.      * @return Collection<int, Spectateur>
  208.      */
  209.     public function getSpectateurs(): Collection
  210.     {
  211.         return $this->spectateurs;
  212.     }
  213.     public function addSpectateur(Spectateur $spectateur): self
  214.     {
  215.         if (!$this->spectateurs->contains($spectateur)) {
  216.             $this->spectateurs->add($spectateur);
  217.             $spectateur->setCommande($this);
  218.         }
  219.         return $this;
  220.     }
  221.     public function removeSpectateur(Spectateur $spectateur): self
  222.     {
  223.         if ($this->spectateurs->removeElement($spectateur)) {
  224.             // set the owning side to null (unless already changed)
  225.             if ($spectateur->getCommande() === $this) {
  226.                 $spectateur->setCommande(null);
  227.             }
  228.         }
  229.         return $this;
  230.     }
  231.     /**
  232.      * @return Collection<int, CommandeActions>
  233.      */
  234.     public function getCommandeActions(): array
  235.     {
  236.         return array_reverse($this->commandeActions->toArray());
  237.     }
  238.     public function addCommandeAction(CommandeActions $commandeAction): self
  239.     {
  240.         if (!$this->commandeActions->contains($commandeAction)) {
  241.             $this->commandeActions->add($commandeAction);
  242.             $commandeAction->setCommande($this);
  243.         }
  244.         return $this;
  245.     }
  246.     public function removeCommandeAction(CommandeActions $commandeAction): self
  247.     {
  248.         if ($this->commandeActions->removeElement($commandeAction)) {
  249.             // set the owning side to null (unless already changed)
  250.             if ($commandeAction->getCommande() === $this) {
  251.                 $commandeAction->setCommande(null);
  252.             }
  253.         }
  254.         return $this;
  255.     }
  256.     public function isIsPapier(): ?bool
  257.     {
  258.         return $this->isPapier;
  259.     }
  260.     public function setIsPapier(?bool $isPapier): self
  261.     {
  262.         $this->isPapier $isPapier;
  263.         return $this;
  264.     }
  265.     public function getContactEmail(): ?string
  266.     {
  267.         return $this->contactEmail;
  268.     }
  269.     public function setContactEmail(?string $contactEmail): self
  270.     {
  271.         $this->contactEmail $contactEmail;
  272.         return $this;
  273.     }
  274.     public function getNoteCommande(): ?string
  275.     {
  276.         return $this->noteCommande;
  277.     }
  278.     public function setNoteCommande(?string $noteCommande): self
  279.     {
  280.         $this->noteCommande $noteCommande;
  281.         return $this;
  282.     }
  283.     public function getNoteClient(): ?string
  284.     {
  285.         return $this->noteClient;
  286.     }
  287.     public function setNoteClient(?string $noteClient): self
  288.     {
  289.         $this->noteClient $noteClient;
  290.         return $this;
  291.     }
  292.     public function getNoteSpectateur(): ?string
  293.     {
  294.         return $this->noteSpectateur;
  295.     }
  296.     public function setNoteSpectateur(?string $noteSpectateur): self
  297.     {
  298.         $this->noteSpectateur $noteSpectateur;
  299.         return $this;
  300.     }
  301.     public function getFormSpectateurs(): array
  302.     {
  303.         $spectateurs array_values(
  304.             array_filter(
  305.                 array_map(
  306.                     function ($spectateur) {
  307.                         if ($spectateur->isIsActive())
  308.                             return [
  309.                                 'nom' => $spectateur->getNom()
  310.                             ];
  311.                         return null;
  312.                     },
  313.                     $this->getSpectateurs()->toArray()
  314.                 ),
  315.                 function ($value) {
  316.                     return $value !== null;
  317.                 }
  318.             )
  319.         );
  320.         $result = [];
  321.         for ($i 1$i <= $this->nbr$i++) {
  322.             if (count($spectateurs) >= $i$result[] = $spectateurs[($i 1)]['nom'];
  323.             else $result[$i] = '';
  324.         }
  325.         return $result;
  326.     }
  327.     public function getHistoriqueSpectateur(): array
  328.     {
  329.         return array_values(
  330.             array_filter(
  331.                 array_map(
  332.                     function ($spectateur) {
  333.                         return [
  334.                             'id' => $spectateur->getId(),
  335.                             'nom' => $spectateur->getNom(),
  336.                             'date' => $spectateur->getLocalizedDate()
  337.                         ];
  338.                     },
  339.                     $this->getSpectateurs()->toArray()
  340.                 ),
  341.                 function ($value) {
  342.                     return $value !== null;
  343.                 }
  344.             )
  345.         );
  346.     }
  347.     public function getAllSpectateurToEmail(): ?string
  348.     {
  349.         $result '<ul>';
  350.         /** @var Spectateur $spectateur */
  351.         foreach ($this->getAttributions() as $attribution) {
  352.             $spectateur $attribution->getSpectateur();
  353.             $result .= '<li>' $spectateur->getNom() . '</li>';
  354.         }
  355.         $result .= '</ul>';
  356.         return $result;
  357.     }
  358.     public function getGroupedSpectateur(): array
  359.     {
  360.         $resultat = [];
  361.         $nbrs explode(','$this->groupement);
  362.         $attributions $this->getAttributions()->toArray();
  363.         $i 0;
  364.         $limit 0;
  365.         foreach ($nbrs as $index => $nbr) {
  366.             $limit += $nbr;
  367.             while ($i $limit) {
  368.                 if(isset($attributions[$i])) {
  369.                     $resultat['groupe_' $index][] = $attributions[$i];
  370.                 }
  371.                 $i++;
  372.             }
  373.         }
  374.         return $resultat;
  375.     }
  376.     public function getToAttribute(): ?Attribution
  377.     {
  378.         foreach ($this->getAttributions() as $attribution) {
  379.             if(is_null($attribution->getBillet())) return $attribution;
  380.         }
  381.         return null;
  382.     }
  383.     public function getNbNoms(): string
  384.     {
  385.         $saisie 0;
  386.         $spectateurs 0;
  387.         /** @var Spectateur $spectateur */
  388.         foreach ($this->getAttributions() as $attribution) {
  389.             $spectateur $attribution->getSpectateur();
  390.             $spectateurs++;
  391.             if($spectateur->getNom() !== ' ' && $spectateur->getNom() !== '' && !is_null($spectateur->getNom())) $saisie ++;
  392.         }
  393.         return $saisie.' / '.$spectateurs;
  394.     }
  395.     public function getNbrBilletSameStatus(): int
  396.     {
  397.         $count 0;
  398.         /** @var Attribution $attribution */
  399.         foreach ($this->attributions as $attribution) {
  400.             if($attribution->getStatut() == $this->statut$count++;
  401.         }
  402.         return $count;
  403.     }
  404.     public function getNoms(): string
  405.     {
  406.         $spectateurs $this->getSpectateurs();
  407.         $nb 0;
  408.         foreach ($spectateurs as $spectateur) {
  409.             if($spectateur->getNom() != " " && $spectateur->getNom() != ""$nb++;
  410.         }
  411.         return $nb.' / '.count($spectateurs);
  412.     }
  413.     public function getStock(): string
  414.     {
  415.         $stock 0;
  416.         foreach ($this->attributions as $attribution) {
  417.             if(is_null($attribution->getBillet())) $stock++;
  418.         }
  419.         return $stock.' / '.count($this->attributions);
  420.     }
  421. }