<?php
namespace App\Entity\File;
use App\Entity\AbstractEntity;
use App\Entity\Order;
use App\Entity\Product;
use App\Repository\FileRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\MappedSuperclass()
* @ORM\Entity(repositoryClass=FileRepository::class)
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"template" = "Template", "contract" = "Contract", "signi" = "Signi", "file" = "File", "simple" = "SimpleFile", "digi_sign" = "DigiSign", "photo" = "Photo", "valuable" = "ValuableFile", "valuable_protocol" = "ValuableProtocolFile"})
* @ORM\HasLifecycleCallbacks
*/
class File extends AbstractEntity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* Počítá se jako počet vygenerovaných smluv v rámci objednávky nehledě na smazané tzn. deleted = 1 soubory
*
* @ORM\Column(type="string", length=255)
*/
private $version;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $deleted = false;
/**
* Order název souboru bych viděl jako Smlouva č.{order_id} v.{version} a u
* Product bych tam nahrával to jak to má pojmenovaný uživatel
*
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=128)
*/
private $mime;
/**
* Technický název bych viděl v případě Order takto /public/files/contracts/{order_id}/{RAND_HASH}.pdf a
* V případě Product takto /public/files/templates/{product_id}/{RAND_HASH}.pdf
*
* @ORM\Column(type="string", length=512)
*/
private $url;
/**
* @ORM\Column(type="string", length=512, nullable=true)
*/
private $url_del;
/**
* @ORM\Column(type="integer")
*/
private $size;
/**
* @ORM\Column(type="boolean")
*/
private $signed = false;
/**
* @ORM\ManyToOne(targetEntity=Order::class, inversedBy="files")
*/
private $orderEnt;
/**
* Společně s vytvářením produktu se nahrává Word šablona, ze které se bude generovat potom to PDF
*
* @ORM\OneToOne(targetEntity=Product::class)
*/
private $product;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $signiContractId;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $signiState;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $envelopeId;
/**
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="photos")
*/
protected $metal;
public function getId(): ?int
{
return $this->id;
}
public function getVersion(): ?string
{
return $this->version;
}
public function setVersion(string $version): self
{
$this->version = $version;
return $this;
}
public function isDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(?bool $deleted): self
{
$this->deleted = $deleted;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getMime(): ?string
{
return $this->mime;
}
public function setMime(string $mime): self
{
$this->mime = $mime;
return $this;
}
public function getUrl($trim = '/public'): ?string
{
return str_replace($trim, '', $this->url);
}
public function setUrl(string $url): self
{
$this->url = $url;
return $this;
}
public function getUrlDel(): ?string
{
return $this->url_del;
}
public function setUrlDel(?string $url_del): self
{
$this->url_del = $url_del;
return $this;
}
public function getSize(): ?int
{
return $this->size;
}
public function setSize(int $size): self
{
$this->size = $size;
return $this;
}
public function isSigned(): ?bool
{
return $this->signed;
}
public function setSigned(bool $signed): self
{
$this->signed = $signed;
return $this;
}
public function getOrderEnt(): ?Order
{
return $this->orderEnt;
}
public function setOrderEnt(?Order $orderEnt): self
{
$this->orderEnt = $orderEnt;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getSigniContractId(): ?string
{
return $this->signiContractId;
}
public function setSigniContractId(?string $signiContractId): self
{
$this->signiContractId = $signiContractId;
return $this;
}
public function getSigniState(): ?string
{
return $this->signiState;
}
/**
* TODO: Refactoring, used in signi and digisign
* @param string|null $signiState
* @return $this
*/
public function setSigniState(?string $signiState): self
{
$this->signiState = $signiState;
return $this;
}
public function getEnvelopeId(): ?string
{
return $this->envelopeId;
}
public function setEnvelopeId(?string $envelopeId): self
{
$this->envelopeId = $envelopeId;
return $this;
}
/**
* @return bool
*/
public function exists(){
return file_exists($this->getUrlDel());
}
/**
* @ORM\PrePersist
*/
public function onPrePersist() {
parent::onPrePersist();
$re = '';
if(
$this->getOrderEnt() instanceof Order &&
$this->getOrderEnt()->isReinvest() === true
){
$re = 'RE ';
}
$this->name = $re . $this->name;
}
public function getMetal(): ?Product
{
return $this->metal;
}
public function setMetal(?Product $metal): self
{
$this->metal = $metal;
return $this;
}
public function getDigisignState(): ?string
{
return $this->digisignState;
}
public function setDigisignState(string $digisignState): self
{
$this->digisignState = $digisignState;
return $this;
}
}