src/Entity/CRM/PromptTemplate.php line 15

  1. <?php
  2. namespace App\Entity\CRM;
  3. use App\Enum\PromptCode;
  4. use App\Repository\CRM\PromptTemplateRepository;
  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. #[ORM\Entity(repositoryClassPromptTemplateRepository::class)]
  10. #[ORM\Table(name'prompt_template')]
  11. #[ORM\UniqueConstraint(name'uniq_prompt_template_code_tenant'columns: ['code''tenant_id'])]
  12. class PromptTemplate
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length32enumTypePromptCode::class)]
  19.     private PromptCode $code;
  20.     /**
  21.      * NULL = prompt globalny (domyślny dla wszystkich oddziałów).
  22.      * Konkretny Branch = override per oddział.
  23.      */
  24.     #[ORM\ManyToOne]
  25.     #[ORM\JoinColumn(name'tenant_id'nullabletrueonDelete'CASCADE')]
  26.     private ?Branch $tenant null;
  27.     #[ORM\Column(length255)]
  28.     private string $name;
  29.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  30.     private ?string $description null;
  31.     #[ORM\ManyToOne(targetEntityPromptTemplateVersion::class)]
  32.     #[ORM\JoinColumn(name'current_version_id'nullabletrueonDelete'SET NULL')]
  33.     private ?PromptTemplateVersion $currentVersion null;
  34.     #[ORM\OneToMany(mappedBy'template'targetEntityPromptTemplateVersion::class, cascade: ['persist'], orphanRemovalfalse)]
  35.     #[ORM\OrderBy(['version' => 'DESC'])]
  36.     private Collection $versions;
  37.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  38.     private \DateTimeInterface $createdAt;
  39.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  40.     private ?\DateTimeInterface $updatedAt null;
  41.     public function __construct(PromptCode $codestring $name)
  42.     {
  43.         $this->code $code;
  44.         $this->name $name;
  45.         $this->versions = new ArrayCollection();
  46.         $this->createdAt = new \DateTimeImmutable();
  47.     }
  48.     public function __toString(): string
  49.     {
  50.         return sprintf(
  51.             '%s%s',
  52.             $this->name,
  53.             $this->tenant !== null sprintf(' [%s]', (string) $this->tenant) : ' [globalny]'
  54.         );
  55.     }
  56.     public function getId(): ?int
  57.     {
  58.         return $this->id;
  59.     }
  60.     public function getCode(): PromptCode
  61.     {
  62.         return $this->code;
  63.     }
  64.     public function setCode(PromptCode $code): static
  65.     {
  66.         $this->code $code;
  67.         return $this;
  68.     }
  69.     public function getTenant(): ?Branch
  70.     {
  71.         return $this->tenant;
  72.     }
  73.     public function setTenant(?Branch $tenant): static
  74.     {
  75.         $this->tenant $tenant;
  76.         return $this;
  77.     }
  78.     public function getName(): string
  79.     {
  80.         return $this->name;
  81.     }
  82.     public function setName(string $name): static
  83.     {
  84.         $this->name $name;
  85.         return $this;
  86.     }
  87.     public function getDescription(): ?string
  88.     {
  89.         return $this->description;
  90.     }
  91.     public function setDescription(?string $description): static
  92.     {
  93.         $this->description $description;
  94.         return $this;
  95.     }
  96.     public function getCurrentVersion(): ?PromptTemplateVersion
  97.     {
  98.         return $this->currentVersion;
  99.     }
  100.     public function setCurrentVersion(?PromptTemplateVersion $currentVersion): static
  101.     {
  102.         $this->currentVersion $currentVersion;
  103.         $this->updatedAt = new \DateTimeImmutable();
  104.         return $this;
  105.     }
  106.     /**
  107.      * @return Collection<int, PromptTemplateVersion>
  108.      */
  109.     public function getVersions(): Collection
  110.     {
  111.         return $this->versions;
  112.     }
  113.     public function addVersion(PromptTemplateVersion $version): static
  114.     {
  115.         if (!$this->versions->contains($version)) {
  116.             $this->versions->add($version);
  117.             $version->setTemplate($this);
  118.         }
  119.         return $this;
  120.     }
  121.     public function getCreatedAt(): \DateTimeInterface
  122.     {
  123.         return $this->createdAt;
  124.     }
  125.     public function setCreatedAt(\DateTimeInterface $createdAt): static
  126.     {
  127.         $this->createdAt $createdAt;
  128.         return $this;
  129.     }
  130.     public function getUpdatedAt(): ?\DateTimeInterface
  131.     {
  132.         return $this->updatedAt;
  133.     }
  134.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): static
  135.     {
  136.         $this->updatedAt $updatedAt;
  137.         return $this;
  138.     }
  139.     public function requiresSuperAdmin(): bool
  140.     {
  141.         return $this->code->requiresSuperAdmin();
  142.     }
  143. }