<?php
namespace App\Entity;
use App\Entity\Traits\TimeStampableTrait;
use App\Repository\RateOfProgressRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: RateOfProgressRepository::class)]
#[Vich\Uploadable]
class RateOfProgress
{
const WAITTING = 'En attente de validation';
const VALIDED = 'Approver';
const REJECTED = 'Retourner';
use TimeStampableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
private ?int $id = null;
#[ORM\Column]
#[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
private ?int $valeur = null;
#[ORM\Column(type: Types::TEXT)]
#[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
private ?string $commentaire = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
#[Groups(['task:read', 'activity:read'])]
private ?\DateTimeInterface $dateValidation = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
private ?string $piece = null;
#[Vich\UploadableField(mapping: 'documents_tache', fileNameProperty: 'piece')]
private ?File $imageFile = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAtFile = null;
#[ORM\ManyToOne(inversedBy: 'rateOfProgress')]
private ?Task $tache = null;
#[ORM\Column(nullable: true)]
#[Groups(['task:read', 'activity:read'])]
private ?int $status = null;
#[ORM\OneToMany(mappedBy: 'RateOfProgress', targetEntity: RejectEvaluation::class, cascade:['remove'])]
private Collection $rejectEvaluations;
#[ORM\ManyToOne(inversedBy: 'rateOfProgress')]
private ?User $author = null;
#[ORM\Column]
#[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
private ?bool $isValided = null;
#[Groups(['task:read'])]
#[ORM\OneToMany(mappedBy: 'rateOfProgress', targetEntity: Comment::class)]
private Collection $comment;
#[ORM\OneToMany(mappedBy: 'rateOfProgress', targetEntity: Document::class, cascade:['persist', 'remove'])]
private Collection $documents;
#[ORM\ManyToOne(inversedBy: 'rateOfProgress')]
private ?Activity $activity = null;
#[ORM\Column]
#[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
private ?int $reference = null;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->rejectEvaluations = new ArrayCollection();
$this->isValided = false;
$this->comment = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->reference = 0;
}
public function getId(): ?int
{
return $this->id;
}
public function getValeur(): ?int
{
return $this->valeur;
}
public function setValeur(int $valeur): static
{
$this->valeur = $valeur;
return $this;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setCommentaire(string $commentaire): static
{
$this->commentaire = $commentaire;
return $this;
}
public function getDateValidation(): ?\DateTimeInterface
{
return $this->dateValidation;
}
public function setDateValidation(\DateTimeInterface $dateValidation): static
{
$this->dateValidation = $dateValidation;
return $this;
}
public function getPiece(): ?string
{
return $this->piece;
}
public function setPiece(?string $piece): static
{
$this->piece = $piece;
return $this;
}
public function getTache(): ?Task
{
return $this->tache;
}
public function setTache(?Task $tache): static
{
$this->tache = $tache;
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAtFile = new \DateTimeImmutable();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
// public function setImageName(?string $imageName): void
// {
// $this->imageName = $imageName;
// }
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(?int $status): static
{
$this->status = $status;
return $this;
}
#[Groups(['task:read', 'activity:read'])]
public function getStatusRate(): string
{
if ($this->getStatus() == 1) {
return self::WAITTING;
}
if ($this->getStatus() == 2) {
return self::REJECTED;
}
if ($this->getStatus() == 3) {
return self::VALIDED;
}
return '';
}
/**
* @return Collection<int, RejectEvaluation>
*/
public function getRejectEvaluations(): Collection
{
return $this->rejectEvaluations;
}
public function addRejectEvaluation(RejectEvaluation $rejectEvaluation): static
{
if (!$this->rejectEvaluations->contains($rejectEvaluation)) {
$this->rejectEvaluations->add($rejectEvaluation);
$rejectEvaluation->setRateOfProgress($this);
}
return $this;
}
public function removeRejectEvaluation(RejectEvaluation $rejectEvaluation): static
{
if ($this->rejectEvaluations->removeElement($rejectEvaluation)) {
// set the owning side to null (unless already changed)
if ($rejectEvaluation->getRateOfProgress() === $this) {
$rejectEvaluation->setRateOfProgress(null);
}
}
return $this;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): static
{
$this->author = $author;
return $this;
}
public function isIsValided(): ?bool
{
return $this->isValided;
}
public function setIsValided(bool $isValided): static
{
$this->isValided = $isValided;
return $this;
}
/**
* @return Collection<int, Comment>
*/
public function getComment(): Collection
{
return $this->comment;
}
public function addComment(Comment $comment): static
{
if (!$this->comment->contains($comment)) {
$this->comment->add($comment);
$comment->setRateOfProgress($this);
}
return $this;
}
public function removeComment(Comment $comment): static
{
if ($this->comment->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getRateOfProgress() === $this) {
$comment->setRateOfProgress(null);
}
}
return $this;
}
/**
* @return Collection<int, Document>
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): static
{
if (!$this->documents->contains($document)) {
$this->documents->add($document);
$document->setRateOfProgress($this);
}
return $this;
}
public function removeDocument(Document $document): static
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getRateOfProgress() === $this) {
$document->setRateOfProgress(null);
}
}
return $this;
}
public function getActivity(): ?Activity
{
return $this->activity;
}
public function setActivity(?Activity $activity): static
{
$this->activity = $activity;
return $this;
}
public function getReference(): ?int
{
return $this->reference;
}
public function setReference(int $reference): static
{
$this->reference = $reference;
return $this;
}
#[Groups(['task:read'])]
public function getUnite() {
return $this->activity->getUnite()?->getName();
}
#[Groups(['task:read'])]
public function getCountComment(): int {
return $this->getComment()->count();
}
}