src/Entity/ProjectOrderTaskJobs.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProjectOrderTaskJobsRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Serializer\Annotation\Groups;
  6. /**
  7.  * @ORM\Entity(repositoryClass=ProjectOrderTaskJobsRepository::class)
  8.  */
  9. class ProjectOrderTaskJobs
  10. {
  11.     /**
  12.      * @ORM\Id
  13.      * @ORM\GeneratedValue
  14.      * @ORM\Column(type="integer")
  15.      * @Groups({
  16.      *     "project_order_task_job@base",
  17.      *     "project_order_task_job@core"
  18.      * })
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\ManyToOne(targetEntity=ProjectOrderTasks::class, inversedBy="project_order_task_jobs")
  23.      * @ORM\JoinColumn(onDelete="CASCADE")
  24.      */
  25.     // TODO Replace with task $order_task > $task !!!
  26.     private $order_task;
  27.     /**
  28.      * @ORM\Column(type="float", nullable=true)
  29.      * @Groups({
  30.      *     "project_order_task_job@core"
  31.      *  })
  32.      */
  33.     private $job_weight;
  34.     /**
  35.      * @ORM\Column(type="integer")
  36.      * @Groups({
  37.      *      "project_order_task_job@core"
  38.      *   })
  39.      */
  40.     private $job_index;
  41.     /**
  42.      * @ORM\Column(type="date_immutable", nullable=true)
  43.      * @Groups({
  44.      *      "project_order_task_job@core"
  45.      *   })
  46.      */
  47.     private $start_at;
  48.     /**
  49.      * @ORM\Column(type="date_immutable", nullable=true)
  50.      * @Groups({
  51.      *       "project_order_task_job@core"
  52.      *    })
  53.      */
  54.     private $end_at;
  55.     /**
  56.      * @ORM\Column(type="float", nullable=true)
  57.      * @Groups({
  58.      *      "project_order_task_job@core"
  59.      *   })
  60.      */
  61.     private $rating;
  62.     /**
  63.      * @ORM\Column(type="integer", nullable=true)
  64.      * @Groups({
  65.      *      "project_order_task_job@core"
  66.      *   })
  67.      */
  68.     private $real_days;
  69.     /**
  70.      * @ORM\Column(type="text", nullable=true)
  71.      * @Groups({
  72.      *      "project_order_task_job@core"
  73.      *   })
  74.      */
  75.     private $job_description;
  76.     /**
  77.      * @ORM\Column(type="float", nullable=true)
  78.      * @Groups({
  79.      *        "project_order_task_job@core"
  80.      *     })
  81.      */
  82.     private $duration_days;
  83.     public function getId(): ?int
  84.     {
  85.         return $this->id;
  86.     }
  87.     public function getOrderTask(): ?ProjectOrderTasks
  88.     {
  89.         return $this->order_task;
  90.     }
  91.     public function setOrderTask(?ProjectOrderTasks $order_task): self
  92.     {
  93.         $this->order_task $order_task;
  94.         return $this;
  95.     }
  96.     public function getJobWeight(): ?float
  97.     {
  98.         return $this->job_weight;
  99.     }
  100.     public function setJobWeight(?float $job_weight): self
  101.     {
  102.         $this->job_weight $job_weight;
  103.         return $this;
  104.     }
  105.     public function getJobIndex(): ?int
  106.     {
  107.         return $this->job_index;
  108.     }
  109.     public function setJobIndex(int $job_index): self
  110.     {
  111.         $this->job_index $job_index;
  112.         return $this;
  113.     }
  114.     public function getStartAt(): ?\DateTimeImmutable
  115.     {
  116.         return $this->start_at;
  117.     }
  118.     public function setStartAt(?\DateTimeImmutable $start_at): self
  119.     {
  120.         $this->start_at $start_at;
  121.         return $this;
  122.     }
  123.     public function getEndAt(): ?\DateTimeImmutable
  124.     {
  125.         return $this->end_at;
  126.     }
  127.     public function setEndAt(?\DateTimeImmutable $end_at): self
  128.     {
  129.         $this->end_at $end_at;
  130.         return $this;
  131.     }
  132.     /**
  133.      * Tamamlama kilidi — PLAN job'undan OKUNUR (read-through; order kendi tutmaz).
  134.      * Plan = lock otoritesi. Order bu değere göre editlenemez; unlock yetkisi plandadır.
  135.      * Plana bağlı olmayan order job'unda (source_plan_job null) her zaman false.
  136.      *
  137.      * @Groups({
  138.      *       "project_order_task_job@core"
  139.      *    })
  140.      */
  141.     public function getLocked(): bool
  142.     {
  143.         return $this->source_plan_job !== null && $this->source_plan_job->getLocked();
  144.     }
  145.     /**
  146.      * Tamamlama kilidi — SERVIS HELPER'ı (serialize EDİLMEZ). Job tamamlanmamış (end_at null)
  147.      * VE başlangıç günü gelmemişse (today < start_at) doldurulur; aksi halde null.
  148.      * Job tamamlama "live request" (job-completion-check endpoint → checkJobCompletion) bunu
  149.      * çağırır; eski serialize-edilen `completion_block` alanı kaldırıldı (FE artık endpoint kullanıyor).
  150.      *
  151.      * @return array|null
  152.      */
  153.     public function getCompletionBlock(): ?array
  154.     {
  155.         if ($this->end_at !== null) {
  156.             return null;
  157.         }
  158.         // Plan-bağlı job: start OTORİTESİ plan (order kopyası stale olabilir — plan ayrı yerde
  159.         // değişip order reload edilmemişse). Canlı check stale start yüzünden haksız blok vermesin.
  160.         $start $this->source_plan_job !== null $this->source_plan_job->getStartAt() : $this->start_at;
  161.         if ($start === null) {
  162.             return null;
  163.         }
  164.         // Tarih-string: bugün == başlangıç günü ise tamamlanabilir (saat bileşeni şişirmesin).
  165.         $todayStr = (new \DateTimeImmutable('today'))->format('Y-m-d');
  166.         if ($start->format('Y-m-d') > $todayStr) {
  167.             return ['reason' => 'not_started''start_at' => $start->format('Y-m-d')];
  168.         }
  169.         return null;
  170.     }
  171.     public function getRating(): ?float
  172.     {
  173.         return $this->rating;
  174.     }
  175.     public function setRating(?float $rating): self
  176.     {
  177.         $this->rating $rating;
  178.         return $this;
  179.     }
  180.     public function getRealDays(): ?int
  181.     {
  182.         return $this->real_days;
  183.     }
  184.     public function setRealDays(?int $real_days): self
  185.     {
  186.         $this->real_days $real_days;
  187.         return $this;
  188.     }
  189.     public function getJobDescription(): ?string
  190.     {
  191.         return $this->job_description;
  192.     }
  193.     public function setJobDescription(?string $job_description): self
  194.     {
  195.         $this->job_description $job_description;
  196.         return $this;
  197.     }
  198.     public function getDurationDays(): ?float
  199.     {
  200.         return $this->duration_days;
  201.     }
  202.     public function setDurationDays(?float $duration_days): self
  203.     {
  204.         $this->duration_days $duration_days;
  205.         return $this;
  206.     }
  207.     /**
  208.      * Materialization mapping — bu Order TaskJob hangi WorksPlanJob'dan üretildi.
  209.      * end_at değiştiğinde OrderEndAtBackSyncListener bu kolondan Plan job'una ulaşıp
  210.      * is_end_at'i set eder. Plan job silinirse NULL'a düşer (Order satırı kalır).
  211.      *
  212.      * @ORM\ManyToOne(targetEntity=WorksPlanJob::class)
  213.      * @ORM\JoinColumn(name="source_plan_job_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  214.      *
  215.      * NOT: Serialize EDİLMEZ (group YOK) — order FE'sine sızarsa save'de generic
  216.      * hydrator setSourcePlanJob(array) ile patlar. Yalnızca BE Materializer/back-sync kullanır.
  217.      */
  218.     private $source_plan_job;
  219.     public function getSourcePlanJob(): ?WorksPlanJob
  220.     {
  221.         return $this->source_plan_job;
  222.     }
  223.     public function setSourcePlanJob(?WorksPlanJob $source_plan_job): self
  224.     {
  225.         $this->source_plan_job $source_plan_job;
  226.         return $this;
  227.     }
  228. }