src/Entity/Supply.php line 15

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SupplyRepository;
  4. use App\Trait\DateTrait;
  5. use DateTimeImmutable;
  6. use DateTimeInterface;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. #[ORM\Entity(repositoryClass: SupplyRepository::class)]
  12. class Supply
  13. {
  14.     use DateTrait;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id = null;
  19.     #[ORM\Column(length: 255)]
  20.     private ?string $code = null;
  21.     #[ORM\OneToMany(mappedBy: 'supply', targetEntity: ArticleSupply::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  22.     private Collection $articles;
  23.     #[ORM\Column]
  24.     private ?bool $isApproved;
  25.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  26.     private ?DateTimeInterface $approvedAt = null;
  27.     #[ORM\ManyToOne]
  28.     private ?User $approvedBy = null;
  29.     #[ORM\ManyToOne]
  30.     #[ORM\JoinColumn(nullable: false)]
  31.     private ?User $author = null;
  32.     #[ORM\ManyToOne(inversedBy: 'supplies')]
  33.     #[ORM\JoinColumn(nullable: false)]
  34.     private ?Establishment $establishment = null;
  35.     public function __construct()
  36.     {
  37.         if (is_null($this->code)) $this->code = strtoupper(uniqid('SP-', false));
  38.         $this->isApproved = 0;
  39.         if (is_null($this->createdAt)) $this->createdAt = new DateTimeImmutable();
  40.         $this->updatedAt = new DateTimeImmutable();
  41.         $this->articles = new ArrayCollection();
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getCode(): ?string
  48.     {
  49.         return $this->code;
  50.     }
  51.     public function setCode(string $code): self
  52.     {
  53.         $this->code = $code;
  54.         return $this;
  55.     }
  56.     /**
  57.      * @return Collection<int, ArticleSupply>
  58.      */
  59.     public function getArticles(): Collection
  60.     {
  61.         return $this->articles;
  62.     }
  63.     public function addArticle(ArticleSupply $article): self
  64.     {
  65.         if (!$this->articles->contains($article)) {
  66.             $this->articles->add($article);
  67.             $article->setSupply($this);
  68.         }
  69.         return $this;
  70.     }
  71.     public function removeArticle(ArticleSupply $article): self
  72.     {
  73.         if ($this->articles->removeElement($article)) {
  74.             // set the owning side to null (unless already changed)
  75.             if ($article->getSupply() === $this) {
  76.                 $article->setSupply(null);
  77.             }
  78.         }
  79.         return $this;
  80.     }
  81.     public function isIsApproved(): ?bool
  82.     {
  83.         return $this->isApproved;
  84.     }
  85.     public function getIsApprovedView()
  86.     {
  87.         $status = $this->isIsApproved() ? 'success' : 'danger';
  88.         $text = $this->isIsApproved() ? 'ApprouvĂ©' : 'Non approuvĂ©';
  89.         return "<span class='badge badge-soft-{$status}'>$text</span>";
  90.     }
  91.     public function setIsApproved(bool $isApproved): self
  92.     {
  93.         $this->isApproved = $isApproved;
  94.         return $this;
  95.     }
  96.     public function getApprovedAt(): ?DateTimeInterface
  97.     {
  98.         return $this->approvedAt;
  99.     }
  100.     public function setApprovedAt(?DateTimeInterface $approvedAt): self
  101.     {
  102.         $this->approvedAt = $approvedAt;
  103.         return $this;
  104.     }
  105.     public function getApprovedBy(): ?User
  106.     {
  107.         return $this->approvedBy;
  108.     }
  109.     public function setApprovedBy(?User $approvedBy): self
  110.     {
  111.         $this->approvedBy = $approvedBy;
  112.         return $this;
  113.     }
  114.     public function getAuthor(): ?User
  115.     {
  116.         return $this->author;
  117.     }
  118.     public function setAuthor(?User $author): self
  119.     {
  120.         $this->author = $author;
  121.         return $this;
  122.     }
  123.     public function getEstablishment(): ?Establishment
  124.     {
  125.         return $this->establishment;
  126.     }
  127.     public function setEstablishment(?Establishment $establishment): self
  128.     {
  129.         $this->establishment = $establishment;
  130.         return $this;
  131.     }
  132. }