src/Entity/Supply.php line 15
<?phpnamespace App\Entity;use App\Repository\SupplyRepository;use App\Trait\DateTrait;use DateTimeImmutable;use DateTimeInterface;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: SupplyRepository::class)]class Supply{use DateTrait;#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(length: 255)]private ?string $code = null;#[ORM\OneToMany(mappedBy: 'supply', targetEntity: ArticleSupply::class, cascade: ['persist', 'remove'], orphanRemoval: true)]private Collection $articles;#[ORM\Column]private ?bool $isApproved;#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]private ?DateTimeInterface $approvedAt = null;#[ORM\ManyToOne]private ?User $approvedBy = null;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]private ?User $author = null;#[ORM\ManyToOne(inversedBy: 'supplies')]#[ORM\JoinColumn(nullable: false)]private ?Establishment $establishment = null;public function __construct(){if (is_null($this->code)) $this->code = strtoupper(uniqid('SP-', false));$this->isApproved = 0;if (is_null($this->createdAt)) $this->createdAt = new DateTimeImmutable();$this->updatedAt = new DateTimeImmutable();$this->articles = new ArrayCollection();}public function getId(): ?int{return $this->id;}public function getCode(): ?string{return $this->code;}public function setCode(string $code): self{$this->code = $code;return $this;}/*** @return Collection<int, ArticleSupply>*/public function getArticles(): Collection{return $this->articles;}public function addArticle(ArticleSupply $article): self{if (!$this->articles->contains($article)) {$this->articles->add($article);$article->setSupply($this);}return $this;}public function removeArticle(ArticleSupply $article): self{if ($this->articles->removeElement($article)) {// set the owning side to null (unless already changed)if ($article->getSupply() === $this) {$article->setSupply(null);}}return $this;}public function isIsApproved(): ?bool{return $this->isApproved;}public function getIsApprovedView(){$status = $this->isIsApproved() ? 'success' : 'danger';$text = $this->isIsApproved() ? 'Approuvé' : 'Non approuvé';return "<span class='badge badge-soft-{$status}'>$text</span>";}public function setIsApproved(bool $isApproved): self{$this->isApproved = $isApproved;return $this;}public function getApprovedAt(): ?DateTimeInterface{return $this->approvedAt;}public function setApprovedAt(?DateTimeInterface $approvedAt): self{$this->approvedAt = $approvedAt;return $this;}public function getApprovedBy(): ?User{return $this->approvedBy;}public function setApprovedBy(?User $approvedBy): self{$this->approvedBy = $approvedBy;return $this;}public function getAuthor(): ?User{return $this->author;}public function setAuthor(?User $author): self{$this->author = $author;return $this;}public function getEstablishment(): ?Establishment{return $this->establishment;}public function setEstablishment(?Establishment $establishment): self{$this->establishment = $establishment;return $this;}}