src/Entity/UserProjets.php line 15
<?phpnamespace App\Entity;use App\Repository\UserProjetsRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;#[ORM\Entity(repositoryClass: UserProjetsRepository::class)]#[UniqueEntity(fields: ['projet', 'user'], message: 'This user is already linked to this project.')]class UserProjets{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\ManyToOne(inversedBy: 'userProjets')]#[ORM\JoinColumn(nullable: false)]private ?User $user = null;#[ORM\ManyToOne(inversedBy: 'userProjets')]#[ORM\JoinColumn(nullable: false)]private ?Projets $projet = null;#[ORM\Column]private ?\DateTimeImmutable $createdAt = null;#[ORM\Column]private ?bool $Completed = null;#[ORM\OneToMany(mappedBy: 'projet', targetEntity: Commentaires::class, cascade: ['persist', 'remove'])]private Collection $commentaires;#[ORM\Column(nullable: true)]private ?\DateTimeImmutable $finishedAt = null;#[ORM\Column(length: 255, nullable: true)]private ?string $github = null;private $notesRepository;public function __construct(){$this->Completed = false;$this->createdAt = new \DateTimeImmutable();$this->commentaires = new ArrayCollection();}public function getId(): ?int{return $this->id;}public function getUser(): ?User{return $this->user;}public function setUser(?User $user): self{$this->user = $user;return $this;}public function getProjet(): ?Projets{return $this->projet;}public function setProjet(?Projets $projet): self{$this->projet = $projet;return $this;}public function getCreatedAt(): ?\DateTimeImmutable{return $this->createdAt;}public function setCreatedAt(\DateTimeImmutable $createdAt): self{$this->createdAt = $createdAt;return $this;}public function isCompleted(): ?bool{return $this->Completed;}public function setCompleted(bool $Completed): self{$this->Completed = $Completed;return $this;}/*** @return Collection<int, Commentaires>*/public function getCommentaires(): Collection{return $this->commentaires;}public function getCommentairesJS(): string{$commentaires = $this->commentaires->getValues();$commentairesJS = [];foreach ($commentaires as $commentaire) {$commentairesJS[] = ['id' => $commentaire->getId(),'text' => $commentaire->getText(),'user' => $commentaire->getUser()->getUserInfos()->getName(),'image' => $commentaire->getUser()->getUserInfos()->getImage(),'rating' => $commentaire->getNotes()->isEmpty() ? null : $commentaire->getNotes()[0]->getRating(),'createdAt' => $commentaire->getCreatedAt()->format('d/m/Y - H:i'),];}return json_encode($commentairesJS);}public function getAverageRatings(): array{$commentaires = $this->commentaires->getValues();$ratings = [];foreach ($commentaires as $commentaire) {if (!$commentaire->getNotes()->isEmpty()) {$ratings[] = $commentaire->getNotes()[0]->getRating();}}if (count($ratings) === 0) {return [0, 0];}return [array_sum($ratings) / count($ratings), count($ratings)];}public function addCommentaire(Commentaires $commentaire): self{if (!$this->commentaires->contains($commentaire)) {$this->commentaires->add($commentaire);$commentaire->setProjet($this);}return $this;}public function removeCommentaire(Commentaires $commentaire): self{if ($this->commentaires->removeElement($commentaire)) {// set the owning side to null (unless already changed)if ($commentaire->getProjet() === $this) {$commentaire->setProjet(null);}}return $this;}public function getFinishedAt(): ?\DateTimeImmutable{return $this->finishedAt;}public function setFinishedAt(?\DateTimeImmutable $finishedAt): self{$this->finishedAt = $finishedAt;return $this;}public function getGithub(): ?string{return $this->github;}public function setGithub(?string $github): self{$this->github = $github;return $this;}}