src/Entity/Pao.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\PaoRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use App\Validator as CustomAssert;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClass: PaoRepository::class)]
  12. #[CustomAssert\UniqueStructureAndYear]
  13. #[ORM\HasLifecycleCallbacks]
  14. class Pao
  15. {
  16.     use TimeStampable;
  17.     
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     #[Groups(["entity:write", "entity:read"])]
  22.     private ?int $id = null;
  23.     #[ORM\Column(length: 255)]
  24.     #[Groups(["entity:write", "entity:read"])]
  25.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  26.     private ?string $titre = null;
  27.     #[ORM\ManyToOne(inversedBy: 'paos')]
  28.     #[Groups(["entity:write"])]
  29.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  30.     private ?Structure $structure = null;
  31.     #[ORM\Column(nullable: true)]
  32.     #[Groups(["entity:write"])]
  33.     private ?int $status = null;
  34.     #[ORM\Column(length: 255)]
  35.     #[Groups(["entity:write", "entity:read"])]
  36.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  37.     private ?string $year = null;
  38.     
  39.     #[Groups(["entity:read"])]
  40.     #[ORM\OneToMany(mappedBy: 'pao', targetEntity: Objectif::class, cascade:['persist', 'remove'])]
  41.     private Collection $objectifs;
  42.     #[ORM\ManyToOne(inversedBy: 'paos')]
  43.     private ?User $createdBy = null;
  44.     public function __construct()
  45.     {
  46.         $this->createdAt = new \DateTimeImmutable();
  47.         $this->updatedAt = new \DateTimeImmutable();
  48.         $this->status = 1;
  49.         $this->objectifs = new ArrayCollection();
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getTitre(): ?string
  56.     {
  57.         return $this->titre;
  58.     }
  59.     public function setTitre(?string $titre): static
  60.     {
  61.         $this->titre = $titre;
  62.         return $this;
  63.     }
  64.     public function getStructure(): ?Structure
  65.     {
  66.         return $this->structure;
  67.     }
  68.     public function setStructure(?Structure $structure): static
  69.     {
  70.         $this->structure = $structure;
  71.         return $this;
  72.     }
  73.     public function getStatus(): ?int
  74.     {
  75.         return $this->status;
  76.     }
  77.     public function setStatus(int $status): static
  78.     {
  79.         $this->status = $status;
  80.         return $this;
  81.     }
  82.     public function status(): string
  83.     {
  84.         if($this->status ==  1)
  85.         {
  86.             return 'En cours';
  87.         }elseif($this->status == 2) {
  88.             return 'Terminer';
  89.         }
  90.         else {
  91.             return  '';
  92.         }
  93.     }
  94.     public function getYear(): ?string
  95.     {
  96.         return $this->year;
  97.     }
  98.     public function setYear(string $year): static
  99.     {
  100.         $this->year = $year;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @return Collection<int, Objectif>
  105.      */
  106.     public function getObjectifs(): Collection
  107.     {
  108.         return $this->objectifs;
  109.     }
  110.     public function addObjectif(Objectif $objectif): static
  111.     {
  112.         if (!$this->objectifs->contains($objectif)) {
  113.             $this->objectifs->add($objectif);
  114.             $objectif->setPao($this);
  115.         }
  116.         return $this;
  117.     }
  118.     public function removeObjectif(Objectif $objectif): static
  119.     {
  120.         if ($this->objectifs->removeElement($objectif)) {
  121.             // set the owning side to null (unless already changed)
  122.             if ($objectif->getPao() === $this) {
  123.                 $objectif->setPao(null);
  124.             }
  125.         }
  126.         return $this;
  127.     }
  128.     public function getCountObjetifsByType(TypeObjectif $typeObjectif): int
  129.     {
  130.         $countObjectifs = 0;
  131.         foreach ($this->objectifs as $objectif) {
  132.             if($objectif->getTypeObjectif() == $typeObjectif) {
  133.                 $countObjectifs = $countObjectifs + 1;
  134.             }
  135.         }
  136.         return $countObjectifs;
  137.     }
  138.     public function __tostring()
  139.     {
  140.         return $this->titre;
  141.     }
  142.     public function getCreatedBy(): ?User
  143.     {
  144.         return $this->createdBy;
  145.     }
  146.     public function setCreatedBy(?User $createdBy): static
  147.     {
  148.         $this->createdBy = $createdBy;
  149.         return $this;
  150.     }
  151. }