src/Entity/Priority.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\PriorityRepository;
  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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClass: PriorityRepository::class)]
  13. #[UniqueEntity(
  14.     fields: ['name',],
  15.     errorPath: 'name',
  16.     message: 'Le nom que vous avez saisi est déjà utilisé',
  17. )]
  18. #[ORM\HasLifecycleCallbacks]
  19. class Priority
  20. {
  21.     use TimeStampable;
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue]
  24.     #[ORM\Column]
  25.     #[Groups(['priority:read','taskProjet:read', 'entity:write', 'objectif:read', 'entity:write'])]
  26.     private ?int $id = null;
  27.     #[ORM\Column(length: 255)]
  28.     #[Groups(['priority:read', 'taskProjet:read', 'entity:write', 'objectif:read',  'activity:read','entity:write'])]
  29.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  30.     private ?string $name = null;
  31.     #[ORM\Column(type: Types::TEXT, nullable: true)]
  32.     #[Groups(['entity:write', 'activity:read'])]
  33.     private ?string $description = null;
  34.     #[ORM\OneToMany(mappedBy: 'priority', targetEntity: Task::class)]
  35.     private Collection $tasks;
  36.     #[ORM\ManyToOne(inversedBy: 'priorities')]
  37.     private ?User $createdBy = null;
  38.     // #[ORM\OneToMany(mappedBy: 'priority', targetEntity: Activity::class)]
  39.     // private Collection $activities;
  40.     public function __construct()
  41.     {
  42.         $this->tasks = new ArrayCollection();
  43.         $this->createdAt = new \DateTimeImmutable();
  44.         $this->isEnabled = false;
  45.         // $this->activities = new ArrayCollection();
  46.         $this->updatedAt = new \DateTimeImmutable();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getName(): ?string
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function setName(string $name): self
  57.     {
  58.         $this->name = $name;
  59.         return $this;
  60.     }
  61.     public function getDescription(): ?string
  62.     {
  63.         return $this->description;
  64.     }
  65.     public function setDescription(?string $description): self
  66.     {
  67.         $this->description = $description;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @return Collection<int, Task>
  72.      */
  73.     public function getTasks(): Collection
  74.     {
  75.         return $this->tasks;
  76.     }
  77.     public function addTask(Task $task): self
  78.     {
  79.         if (!$this->tasks->contains($task)) {
  80.             $this->tasks->add($task);
  81.             $task->setPriority($this);
  82.         }
  83.         return $this;
  84.     }
  85.     public function removeTask(Task $task): self
  86.     {
  87.         if ($this->tasks->removeElement($task)) {
  88.             // set the owning side to null (unless already changed)
  89.             if ($task->getPriority() === $this) {
  90.                 $task->setPriority(null);
  91.             }
  92.         }
  93.         return $this;
  94.     }
  95.     public function __toString(): string 
  96.     {
  97.         return $this->name;
  98.     }
  99.     public function getCreatedBy(): ?User
  100.     {
  101.         return $this->createdBy;
  102.     }
  103.     public function setCreatedBy(?User $createdBy): static
  104.     {
  105.         $this->createdBy = $createdBy;
  106.         return $this;
  107.     }
  108.     // /**
  109.     //  * @return Collection<int, Activity>
  110.     //  */
  111.     // public function getActivities(): Collection
  112.     // {
  113.     //     return $this->activities;
  114.     // }
  115.     // public function addActivity(Activity $activity): static
  116.     // {
  117.     //     if (!$this->activities->contains($activity)) {
  118.     //         $this->activities->add($activity);
  119.     //         $activity->setPriority($this);
  120.     //     }
  121.     //     return $this;
  122.     // }
  123.     // public function removeActivity(Activity $activity): static
  124.     // {
  125.     //     if ($this->activities->removeElement($activity)) {
  126.     //         // set the owning side to null (unless already changed)
  127.     //         if ($activity->getPriority() === $this) {
  128.     //             $activity->setPriority(null);
  129.     //         }
  130.     //     }
  131.     //     return $this;
  132.     // }
  133. }