src/Entity/WorksPlan.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\WorksPlanRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. /**
  9.  * WorksPlan — bir order'a bind edilebilen ya da bağımsız çalışan iş planı.
  10.  *
  11.  * Plan otorite olduğunda task/job strüktürünü taşır, dependency DAG'ı yönetir,
  12.  * cascade hesabını yapar. Order'a bind edilince ProjectOrderTasks/ProjectOrderTaskJobs
  13.  * satırları Plan'ın aynası haline gelir (MaterializationListener). Order'daki end_at
  14.  * Plan'a is_end_at olarak geri akar (OrderEndAtBackSyncListener).
  15.  *
  16.  * @ORM\Entity(repositoryClass=WorksPlanRepository::class)
  17.  * @ORM\Table(name="works_plan")
  18.  * @ORM\HasLifecycleCallbacks
  19.  */
  20. class WorksPlan
  21. {
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue
  25.      * @ORM\Column(type="integer")
  26.      * @Groups({
  27.      *     "works_plan@ref",
  28.      *     "works_plan@base",
  29.      *     "works_plan@core",
  30.      *     "works_plan@list"
  31.      * })
  32.      */
  33.     private $id;
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      * @Groups({
  37.      *     "works_plan@base",
  38.      *     "works_plan@core",
  39.      *     "works_plan@list"
  40.      * })
  41.      */
  42.     private $title;
  43.     /**
  44.      * @ORM\Column(type="text", nullable=true)
  45.      * @Groups({
  46.      *     "works_plan@core",
  47.      *     "works_plan@list"
  48.      * })
  49.      */
  50.     private $description;
  51.     /**
  52.      * Bağlı order — UNIQUE OneToOne (tek yönlü). ProjectOrders.works_plan ile çift bağ
  53.      * BindService tarafından synchronize edilir.
  54.      *
  55.      * @ORM\OneToOne(targetEntity=ProjectOrders::class)
  56.      * @ORM\JoinColumn(name="project_order_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  57.      * @Groups({
  58.      *     "works_plan@core",
  59.      *     "works_plan@list"
  60.      * })
  61.      */
  62.     private $project_order;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=WorkerActivities::class)
  65.      * @ORM\JoinColumn(name="owner_id", referencedColumnName="id", nullable=false)
  66.      * @Groups({
  67.      *     "works_plan@core",
  68.      *     "works_plan@list"
  69.      * })
  70.      */
  71.     private $owner;
  72.     /**
  73.      * @ORM\Column(type="datetime_immutable")
  74.      * @Groups({
  75.      *     "works_plan@core",
  76.      *     "works_plan@list"
  77.      * })
  78.      */
  79.     private $created_at;
  80.     /**
  81.      * @ORM\Column(type="datetime_immutable", nullable=true)
  82.      * @Groups({
  83.      *     "works_plan@core",
  84.      *     "works_plan@list"
  85.      * })
  86.      */
  87.     private $updated_at;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity=WorksPlanTask::class, mappedBy="works_plan", cascade={"persist"}, orphanRemoval=true)
  90.      * @ORM\OrderBy({"task_index" = "ASC"})
  91.      * @Groups({
  92.      *     "works_plan@tasks"
  93.      * })
  94.      */
  95.     private $tasks;
  96.     public function __construct()
  97.     {
  98.         $this->tasks = new ArrayCollection();
  99.     }
  100.     /**
  101.      * @ORM\PrePersist
  102.      */
  103.     public function onPrePersist(): void
  104.     {
  105.         if ($this->created_at === null) {
  106.             $this->created_at = new \DateTimeImmutable();
  107.         }
  108.     }
  109.     /**
  110.      * @ORM\PreUpdate
  111.      */
  112.     public function onPreUpdate(): void
  113.     {
  114.         $this->updated_at = new \DateTimeImmutable();
  115.     }
  116.     public function getId(): ?int
  117.     {
  118.         return $this->id;
  119.     }
  120.     public function getTitle(): ?string
  121.     {
  122.         return $this->title;
  123.     }
  124.     public function setTitle(string $title): self
  125.     {
  126.         $this->title $title;
  127.         return $this;
  128.     }
  129.     public function getDescription(): ?string
  130.     {
  131.         return $this->description;
  132.     }
  133.     public function setDescription(?string $description): self
  134.     {
  135.         $this->description $description;
  136.         return $this;
  137.     }
  138.     public function getProjectOrder(): ?ProjectOrders
  139.     {
  140.         return $this->project_order;
  141.     }
  142.     public function setProjectOrder(?ProjectOrders $project_order): self
  143.     {
  144.         $this->project_order $project_order;
  145.         return $this;
  146.     }
  147.     public function getOwner(): ?WorkerActivities
  148.     {
  149.         return $this->owner;
  150.     }
  151.     public function setOwner(?WorkerActivities $owner): self
  152.     {
  153.         $this->owner $owner;
  154.         return $this;
  155.     }
  156.     public function getCreatedAt(): ?\DateTimeImmutable
  157.     {
  158.         return $this->created_at;
  159.     }
  160.     public function setCreatedAt(\DateTimeImmutable $created_at): self
  161.     {
  162.         $this->created_at $created_at;
  163.         return $this;
  164.     }
  165.     public function getUpdatedAt(): ?\DateTimeImmutable
  166.     {
  167.         return $this->updated_at;
  168.     }
  169.     public function setUpdatedAt(?\DateTimeImmutable $updated_at): self
  170.     {
  171.         $this->updated_at $updated_at;
  172.         return $this;
  173.     }
  174.     /**
  175.      * Reindex edilmiş tasks collection — Serializer'ın associative object çıkarmasını
  176.      * engeller (bkz. ProjectOrderTasks::getTaskJobs() yorumu).
  177.      *
  178.      * @return Collection<int, WorksPlanTask>
  179.      */
  180.     public function getTasks(): Collection
  181.     {
  182.         return new ArrayCollection(array_values($this->tasks->toArray()));
  183.     }
  184.     public function addTask(WorksPlanTask $task): self
  185.     {
  186.         if (!$this->tasks->contains($task)) {
  187.             $this->tasks[] = $task;
  188.             $task->setWorksPlan($this);
  189.         }
  190.         return $this;
  191.     }
  192.     public function removeTask(WorksPlanTask $task): self
  193.     {
  194.         if ($this->tasks->removeElement($task)) {
  195.             if ($task->getWorksPlan() === $this) {
  196.                 $task->setWorksPlan(null);
  197.             }
  198.         }
  199.         return $this;
  200.     }
  201. }