src/Entity/Project.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProjectRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassProjectRepository::class)]
  8. class Project
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length255nullabletrue)]
  15.     private ?string $slug null;
  16.     #[ORM\Column(length255nullabletrue)]
  17.     private ?string $url null;
  18.     #[ORM\OneToMany(mappedBy'project'targetEntityClientOrder::class, orphanRemovaltrue)]
  19.     private Collection $clientOrders;
  20.     #[ORM\OneToMany(mappedBy'project'targetEntityNielsenOrder::class, orphanRemovaltrue)]
  21.     private Collection $nielsenOrders;
  22.     #[ORM\Column(length255)]
  23.     private ?string $name null;
  24.     #[ORM\OneToOne(inversedBy'project'cascade: ['persist''remove'])]
  25.     private ?Magasin $magasin null;
  26.     #[ORM\OneToOne(mappedBy'project'cascade: ['persist''remove'])]
  27.     private ?ProjectSettings $projectSettings null;
  28.     #[ORM\Column(length255)]
  29.     private ?string $token null;
  30.     public function __construct()
  31.     {
  32.         $this->clientOrders = new ArrayCollection();
  33.         $this->nielsenOrders = new ArrayCollection();
  34.         $this->token bin2hex(random_bytes(16));
  35.     }
  36.     public function getChiffreAffaire(): float
  37.     {
  38.         return $this->getClientOrders()
  39.             ->reduce(fn(int $carryClientOrder $clientOrder) => $carry $clientOrder->getPrice(), 0);
  40.     }
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     public function getSlug(): ?string
  46.     {
  47.         return $this->slug;
  48.     }
  49.     public function setSlug(?string $slug): static
  50.     {
  51.         $this->slug $slug;
  52.         return $this;
  53.     }
  54.     public function getUrl(): ?string
  55.     {
  56.         return $this->url;
  57.     }
  58.     public function setUrl(?string $url): static
  59.     {
  60.         $this->url $url;
  61.         return $this;
  62.     }
  63.     /**
  64.      * @return Collection<int, ClientOrder>
  65.      */
  66.     public function getClientOrders(): Collection
  67.     {
  68.         return $this->clientOrders->filter(function(ClientOrder $clientOrder) {
  69.             return $clientOrder->isIsArchived() === false;
  70.         });
  71.     }
  72.     /**
  73.      * @return Collection<int, ClientOrder>
  74.      */
  75.     public function getAllClientOrders(): Collection
  76.     {
  77.         return $this->clientOrders;
  78.     }
  79.     public function addClientOrder(ClientOrder $clientOrder): static
  80.     {
  81.         if (!$this->clientOrders->contains($clientOrder)) {
  82.             $this->clientOrders->add($clientOrder);
  83.             $clientOrder->setProject($this);
  84.         }
  85.         return $this;
  86.     }
  87.     public function removeClientOrder(ClientOrder $clientOrder): static
  88.     {
  89.         if ($this->clientOrders->removeElement($clientOrder)) {
  90.             // set the owning side to null (unless already changed)
  91.             if ($clientOrder->getProject() === $this) {
  92.                 $clientOrder->setProject(null);
  93.             }
  94.         }
  95.         return $this;
  96.     }
  97.     /**
  98.      * @return Collection<int, NielsenOrder>
  99.      */
  100.     public function getNielsenOrders(): Collection
  101.     {
  102.         return $this->nielsenOrders;
  103.     }
  104.     public function addNielsenOrder(NielsenOrder $nielsenOrder): static
  105.     {
  106.         if (!$this->nielsenOrders->contains($nielsenOrder)) {
  107.             $this->nielsenOrders->add($nielsenOrder);
  108.             $nielsenOrder->setProject($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeNielsenOrder(NielsenOrder $nielsenOrder): static
  113.     {
  114.         if ($this->nielsenOrders->removeElement($nielsenOrder)) {
  115.             // set the owning side to null (unless already changed)
  116.             if ($nielsenOrder->getProject() === $this) {
  117.                 $nielsenOrder->setProject(null);
  118.             }
  119.         }
  120.         return $this;
  121.     }
  122.     public function getName(): ?string
  123.     {
  124.         return $this->name;
  125.     }
  126.     public function setName(string $name): static
  127.     {
  128.         $this->name $name;
  129.         return $this;
  130.     }
  131.     public function getMagasin(): ?Magasin
  132.     {
  133.         return $this->magasin;
  134.     }
  135.     public function setMagasin(?Magasin $magasin): static
  136.     {
  137.         $this->magasin $magasin;
  138.         return $this;
  139.     }
  140.     public function getProjectSettings(): ?ProjectSettings
  141.     {
  142.         return $this->projectSettings;
  143.     }
  144.     public function setProjectSettings(ProjectSettings $projectSettings): static
  145.     {
  146.         // set the owning side of the relation if necessary
  147.         if ($projectSettings->getProject() !== $this) {
  148.             $projectSettings->setProject($this);
  149.         }
  150.         $this->projectSettings $projectSettings;
  151.         return $this;
  152.     }
  153.     public function getToken(): ?string
  154.     {
  155.         return $this->token;
  156.     }
  157.     public function setToken(string $token): static
  158.     {
  159.         $this->token $token;
  160.         return $this;
  161.     }
  162. }