src/Entity/RateOfProgress.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampableTrait;
  4. use App\Repository\RateOfProgressRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. #[ORM\Entity(repositoryClass: RateOfProgressRepository::class)]
  13. #[Vich\Uploadable]
  14. class RateOfProgress
  15. {
  16.     const WAITTING = 'En attente de validation';
  17.     const VALIDED = 'Approver';
  18.     const REJECTED = 'Retourner';
  19.     use TimeStampableTrait;
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column]
  23.     #[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
  24.     private ?int $id = null;
  25.     #[ORM\Column]
  26.     #[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
  27.     private ?int $valeur = null;
  28.     #[ORM\Column(type: Types::TEXT)]
  29.     #[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
  30.     private ?string $commentaire = null;
  31.     #[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
  32.     #[Groups(['task:read', 'activity:read'])]
  33.     private ?\DateTimeInterface $dateValidation = null;
  34.     #[ORM\Column(length: 255, nullable: true)]
  35.     #[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
  36.     private ?string $piece = null;
  37.     #[Vich\UploadableField(mapping: 'documents_tache', fileNameProperty: 'piece')]
  38.     private ?File $imageFile = null;
  39.     #[ORM\Column(nullable: true)]
  40.     private ?\DateTimeImmutable $updatedAtFile = null;
  41.     #[ORM\ManyToOne(inversedBy: 'rateOfProgress')]
  42.     private ?Task $tache = null;
  43.     #[ORM\Column(nullable: true)]
  44.     #[Groups(['task:read', 'activity:read'])]
  45.     private ?int $status = null;
  46.     #[ORM\OneToMany(mappedBy: 'RateOfProgress', targetEntity: RejectEvaluation::class, cascade:['remove'])]
  47.     private Collection $rejectEvaluations;
  48.     #[ORM\ManyToOne(inversedBy: 'rateOfProgress')]
  49.     private ?User $author = null;
  50.     #[ORM\Column]
  51.     #[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
  52.     private ?bool $isValided = null;
  53.     #[Groups(['task:read'])]
  54.     #[ORM\OneToMany(mappedBy: 'rateOfProgress', targetEntity: Comment::class)]
  55.     private Collection $comment;
  56.     #[ORM\OneToMany(mappedBy: 'rateOfProgress', targetEntity: Document::class, cascade:['persist', 'remove'])]
  57.     private Collection $documents;
  58.     #[ORM\ManyToOne(inversedBy: 'rateOfProgress')]
  59.     private ?Activity $activity = null;
  60.     #[ORM\Column]
  61.     #[Groups(['task:read', 'rejetEvaluation:read', 'activity:read'])]
  62.     private ?int $reference = null;
  63.     public function __construct()
  64.     {
  65.         $this->createdAt = new \DateTimeImmutable();
  66.         $this->rejectEvaluations = new ArrayCollection();
  67.         $this->isValided = false;
  68.         $this->comment = new ArrayCollection();
  69.         $this->documents = new ArrayCollection();
  70.         $this->reference = 0;
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getValeur(): ?int
  77.     {
  78.         return $this->valeur;
  79.     }
  80.     public function setValeur(int $valeur): static
  81.     {
  82.         $this->valeur = $valeur;
  83.         return $this;
  84.     }
  85.     public function getCommentaire(): ?string
  86.     {
  87.         return $this->commentaire;
  88.     }
  89.     public function setCommentaire(string $commentaire): static
  90.     {
  91.         $this->commentaire = $commentaire;
  92.         return $this;
  93.     }
  94.     public function getDateValidation(): ?\DateTimeInterface
  95.     {
  96.         return $this->dateValidation;
  97.     }
  98.     public function setDateValidation(\DateTimeInterface $dateValidation): static
  99.     {
  100.         $this->dateValidation = $dateValidation;
  101.         return $this;
  102.     }
  103.     public function getPiece(): ?string
  104.     {
  105.         return $this->piece;
  106.     }
  107.     public function setPiece(?string $piece): static
  108.     {
  109.         $this->piece = $piece;
  110.         return $this;
  111.     }
  112.     public function getTache(): ?Task
  113.     {
  114.         return $this->tache;
  115.     }
  116.     public function setTache(?Task $tache): static
  117.     {
  118.         $this->tache = $tache;
  119.         return $this;
  120.     }
  121.     /**
  122.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  123.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  124.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  125.      * must be able to accept an instance of 'File' as the bundle will inject one here
  126.      * during Doctrine hydration.
  127.      *
  128.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  129.      */
  130.     public function setImageFile(?File $imageFile = null): void
  131.     {
  132.         $this->imageFile = $imageFile;
  133.         if (null !== $imageFile) {
  134.             // It is required that at least one field changes if you are using doctrine
  135.             // otherwise the event listeners won't be called and the file is lost
  136.             $this->updatedAtFile = new \DateTimeImmutable();
  137.         }
  138.     }
  139.     public function getImageFile(): ?File
  140.     {
  141.         return $this->imageFile;
  142.     }
  143.     // public function setImageName(?string $imageName): void
  144.     // {
  145.     //     $this->imageName = $imageName;
  146.     // }
  147.     public function getStatus(): ?int
  148.     {
  149.         return $this->status;
  150.     }
  151.     public function setStatus(?int $status): static
  152.     {
  153.         $this->status = $status;
  154.         return $this;
  155.     }
  156.     #[Groups(['task:read', 'activity:read'])]
  157.     public function getStatusRate(): string
  158.     {
  159.         if ($this->getStatus() == 1) {
  160.             return self::WAITTING;
  161.         }
  162.         if ($this->getStatus() == 2) {
  163.             return self::REJECTED;
  164.         }
  165.         if ($this->getStatus() == 3) {
  166.             return self::VALIDED;
  167.         }
  168.         return '';
  169.     }
  170.     /**
  171.      * @return Collection<int, RejectEvaluation>
  172.      */
  173.     public function getRejectEvaluations(): Collection
  174.     {
  175.         return $this->rejectEvaluations;
  176.     }
  177.     public function addRejectEvaluation(RejectEvaluation $rejectEvaluation): static
  178.     {
  179.         if (!$this->rejectEvaluations->contains($rejectEvaluation)) {
  180.             $this->rejectEvaluations->add($rejectEvaluation);
  181.             $rejectEvaluation->setRateOfProgress($this);
  182.         }
  183.         return $this;
  184.     }
  185.     public function removeRejectEvaluation(RejectEvaluation $rejectEvaluation): static
  186.     {
  187.         if ($this->rejectEvaluations->removeElement($rejectEvaluation)) {
  188.             // set the owning side to null (unless already changed)
  189.             if ($rejectEvaluation->getRateOfProgress() === $this) {
  190.                 $rejectEvaluation->setRateOfProgress(null);
  191.             }
  192.         }
  193.         return $this;
  194.     }
  195.     public function getAuthor(): ?User
  196.     {
  197.         return $this->author;
  198.     }
  199.     public function setAuthor(?User $author): static
  200.     {
  201.         $this->author = $author;
  202.         return $this;
  203.     }
  204.     public function isIsValided(): ?bool
  205.     {
  206.         return $this->isValided;
  207.     }
  208.     public function setIsValided(bool $isValided): static
  209.     {
  210.         $this->isValided = $isValided;
  211.         return $this;
  212.     }
  213.     /**
  214.      * @return Collection<int, Comment>
  215.      */
  216.     public function getComment(): Collection
  217.     {
  218.         return $this->comment;
  219.     }
  220.     public function addComment(Comment $comment): static
  221.     {
  222.         if (!$this->comment->contains($comment)) {
  223.             $this->comment->add($comment);
  224.             $comment->setRateOfProgress($this);
  225.         }
  226.         return $this;
  227.     }
  228.     public function removeComment(Comment $comment): static
  229.     {
  230.         if ($this->comment->removeElement($comment)) {
  231.             // set the owning side to null (unless already changed)
  232.             if ($comment->getRateOfProgress() === $this) {
  233.                 $comment->setRateOfProgress(null);
  234.             }
  235.         }
  236.         return $this;
  237.     }
  238.     /**
  239.      * @return Collection<int, Document>
  240.      */
  241.     public function getDocuments(): Collection
  242.     {
  243.         return $this->documents;
  244.     }
  245.     public function addDocument(Document $document): static
  246.     {
  247.         if (!$this->documents->contains($document)) {
  248.             $this->documents->add($document);
  249.             $document->setRateOfProgress($this);
  250.         }
  251.         return $this;
  252.     }
  253.     public function removeDocument(Document $document): static
  254.     {
  255.         if ($this->documents->removeElement($document)) {
  256.             // set the owning side to null (unless already changed)
  257.             if ($document->getRateOfProgress() === $this) {
  258.                 $document->setRateOfProgress(null);
  259.             }
  260.         }
  261.         return $this;
  262.     }
  263.     public function getActivity(): ?Activity
  264.     {
  265.         return $this->activity;
  266.     }
  267.     public function setActivity(?Activity $activity): static
  268.     {
  269.         $this->activity = $activity;
  270.         return $this;
  271.     }
  272.     public function getReference(): ?int
  273.     {
  274.         return $this->reference;
  275.     }
  276.     public function setReference(int $reference): static
  277.     {
  278.         $this->reference = $reference;
  279.         return $this;
  280.     }
  281.     #[Groups(['task:read'])]
  282.     public function getUnite() {
  283.         return $this->activity->getUnite()?->getName();
  284.     }
  285.     #[Groups(['task:read'])]
  286.     public function getCountComment(): int {
  287.         return $this->getComment()->count();
  288.     }
  289. }