src/Entity/Commande.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CommandeRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. #[ORM\Entity(repositoryClassCommandeRepository::class)]
  10. class Commande
  11. {
  12.     public const STATUS_ARRAY = [
  13.         'En cours' => 'En cours',
  14.         'Valide' => 'Valide'
  15.     ];
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null;
  20.     #[ORM\Column(typeTypes::DATE_MUTABLE)]
  21.     private ?\DateTimeInterface $date null;
  22.     #[ORM\Column(length255)]
  23.     private ?string $etat 'En cours';
  24.     #[ORM\Column]
  25.     private ?float $totalPrice null;
  26.     #[ORM\Column(typeTypes::TEXT)]
  27.     private ?string $motifs null;
  28.     #[ORM\Column(length255)]
  29.     private ?string $email;
  30.     #[ORM\Column(length255)]
  31.     private ?string $tel;
  32.     #[ORM\Column(length255)]
  33.     private ?string $adresse;
  34.     #[ORM\OneToMany(mappedBy'Commande'targetEntityCommandArticle::class, cascade: ['persist''remove'])]
  35.     private $commandes;
  36.     #[ORM\ManyToOne(inversedBy'commande'targetEntityUser::class, cascade: ['persist'])]
  37.     private ?User $user null;
  38.     #[ORM\ManyToOne(inversedBy'commande'targetEntityGouvernorat::class, cascade: ['persist'])]
  39.     private $gouvernorat;
  40.     #[ORM\Column(length255nullabletrue)]
  41.     private ?string $adresse_UNITE null
  42.     #[ORM\Column(length255nullabletrue)]
  43.     private ?string $CODE_POSTAL_UNITE null;
  44.     public function getAdresseUNITE(): ?string
  45.     {
  46.         return $this->adresse_UNITE;
  47.     }
  48.     public function setAdresseUNITE(?string $adresse_UNITE): void
  49.     {
  50.         $this->adresse_UNITE $adresse_UNITE;
  51.     }
  52.     public function getCODEPOSTALUNITE(): ?string
  53.     {
  54.         return $this->CODE_POSTAL_UNITE;
  55.     }
  56.     public function setCODEPOSTALUNITE(?string $CODE_POSTAL_UNITE): void
  57.     {
  58.         $this->CODE_POSTAL_UNITE $CODE_POSTAL_UNITE;
  59.     }
  60.     
  61.     public function __construct()
  62.     {
  63.         $this->commandes = new ArrayCollection();
  64.     }
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getMotifs(): ?string
  70.     {
  71.         return $this->motifs;
  72.     }
  73.     public function setMotifs(?string $motifs): self
  74.     {
  75.         $this->motifs $motifs;
  76.         return $this;
  77.     }
  78.     public function getDate(): ?\DateTimeInterface
  79.     {
  80.         return $this->date;
  81.     }
  82.     public function setDate(\DateTimeInterface $date): self
  83.     {
  84.         $this->date $date;
  85.         return $this;
  86.     }
  87.     public function getEtat(): ?string
  88.     {
  89.         return $this->etat;
  90.     }
  91.     public function setEtat(string $etat): self
  92.     {
  93.         $this->etat $etat;
  94.         return $this;
  95.     }
  96.     public function getTel(): ?string
  97.     {
  98.         return $this->tel;
  99.     }
  100.     public function setTel(string $tel): self
  101.     {
  102.         $this->tel $tel;
  103.         return $this;
  104.     }
  105.     public function getAdresse(): ?string
  106.     {
  107.         return $this->adresse;
  108.     }
  109.     public function setAdresse(string $adresse): self
  110.     {
  111.         $this->adresse $adresse;
  112.         return $this;
  113.     }
  114.     public function getEmail(): ?string
  115.     {
  116.         return $this->email;
  117.     }
  118.     public function setEmail(string $email): self
  119.     {
  120.         $this->email $email;
  121.         return $this;
  122.     }
  123.     public function getTotalPrice(): ?float
  124.     {
  125.         return $this->totalPrice;
  126.     }
  127.     public function setTotalPrice(float $totalPrice): self
  128.     {
  129.         $this->totalPrice $totalPrice;
  130.         return $this;
  131.     }
  132.     /**
  133.      * @return Collection<int, CommandArticle>
  134.      */
  135.     public function getCommandes(): Collection
  136.     {
  137.         return $this->commandes;
  138.     }
  139.     public function addCommande(CommandArticle $commade): ?self
  140.     {
  141.         if (!$this->commandes->contains($commade)) {
  142.             $this->commandes->add($commade);
  143.             $commade->setCommande($this);
  144.         }
  145.         return $this;
  146.     }
  147.     public function removeCommnade(CommandArticle $commande): self
  148.     {
  149.         if ($this->commandes->removeElement($commande)) {
  150.             // set the owning side to null (unless already changed)
  151.             if ($commande->getCommande() === $this) {
  152.                 $commande->setCommande(null);
  153.             }
  154.         }
  155.         return $this;
  156.     }
  157.     public function getUser(): ?User
  158.     {
  159.         return $this->user;
  160.     }
  161.     public function setUser(?User $user): self
  162.     {
  163.         $this->user $user;
  164.         return $this;
  165.     }
  166.     public function removeCommande(CommandArticle $commande): self
  167.     {
  168.         if ($this->commandes->removeElement($commande)) {
  169.             // set the owning side to null (unless already changed)
  170.             if ($commande->getCommande() === $this) {
  171.                 $commande->setCommande(null);
  172.             }
  173.         }
  174.         return $this;
  175.     }
  176.     public function getExportData()
  177.     {
  178.         $result="";
  179.         $donnees $this->getCommandes();
  180.         
  181.         foreach ($donnees as $key => $obj) {  
  182.             $result $result.'article:'.$obj->getArticle()->getTitre()." x ".$obj->getQuantite()."\n";
  183.         }
  184.         
  185.         return \array_merge([
  186.             'id' => $this->getId(),
  187.             'Date' => $this->getDate()->format('d/m/Y'),
  188.             'Etat' => $this->getEtat(),
  189.             'totalPrice' => $this->getTotalPrice(),
  190.            // 'motifs' => $this->getMotifs() ?? '',
  191.             'email' => $this->getEmail() ?? '',
  192.             'tel' => $this->getTel() ?? '',
  193.             'Liste des articles' => $result,
  194.         ]);
  195.     }
  196.     public function getGouvernorat(): ?Gouvernorat
  197.     {
  198.         return $this->gouvernorat;
  199.     }
  200.     public function setGouvernorat(?Gouvernorat $gouvernorat): self
  201.     {
  202.         $this->gouvernorat $gouvernorat;
  203.         return $this;
  204.     }
  205. }