cmtracker/src/Entity/Company/CompanyDocument.php
Ryan Prather bcc32bf445 mv: Refactor
* Move entities for organization
2025-01-28 20:47:26 -05:00

140 lines
3.4 KiB
PHP

<?php
namespace App\Entity\Company;
use App\Enums\Company\DocumentExtras;
use App\Repository\Company\CompanyDocumentRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: CompanyDocumentRepository::class)]
class CompanyDocument
{
#[ORM\Id]
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
private ?Uuid $id = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?Company $company = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $text = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $updated = null;
#[ORM\Column(type: Types::JSON, enumType: DocumentExtras::class, nullable: true)]
private array $extras = [];
private bool $selected = false;
public function getId(): ?Uuid
{
return $this->id;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): static
{
$this->company = $company;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(?string $text): static
{
$this->text = $text;
return $this;
}
public function getUpdated(): ?\DateTimeInterface
{
return $this->updated;
}
public function setUpdated(\DateTimeInterface $updated): static
{
$this->updated = $updated;
return $this;
}
public function isSelected(): bool
{
return $this->selected;
}
public function setSelected(): static
{
$this->selected = true;
return $this;
}
public function getExtras(): array
{
return $this->extras;
}
public function setExtras(array $extras): static
{
$this->extras = $extras;
return $this;
}
public function inExtras(DocumentExtras $field): bool
{
return in_array($field, $this->extras);
}
public function renderHtml(): string
{
$text = $this->text;
if ($this->inExtras(DocumentExtras::EMAIL)) {
$text = str_replace('{{ email }}', "<input type='email' name='email' id='email' value='{{ doc.client.email }}'/>", $text);
$text = str_replace('{{ checkbox|email }}', "<input type='checkbox' name='emailClient' id='emailClient' value='1'/>", $text);
}
if ($this->inExtras(DocumentExtras::PHONE)) {
$text = str_replace('{{ phone }}', "<input type='tel' name='phone' id='phone' value='{{ doc.client.phone }}'/>", $text);
$text = str_replace('{{ checkbox|phone }}', "<input type='checkbox' name='callClient' id='callClient' value='1'/>", $text);
$text = str_replace('{{ checkbox|text }}', "<input type='checkbox' name='textClient' id='textClient' value='1'/>", $text);
}
return <<<HTML
$text
HTML;
}
}