<?php
namespace App\Entity;
use App\Repository\DenunciasRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
#[ORM\Entity(repositoryClass: DenunciasRepository::class)]
class Denuncias implements JsonSerializable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'denuncias')]
private ?Tipologias $tipologia = null;
#[ORM\ManyToOne(inversedBy: 'denuncias')]
private ?Estados $estado = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $email_denunciante = null;
#[ORM\Column]
private ?bool $anonimato = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $nome_denunciante = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $telefone_denunciante = null;
#[ORM\Column(length: 255)]
private ?string $nome_denunciado = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $telefone_denunciado = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $email_denunciado = null;
#[ORM\Column(length: 255)]
private ?string $empresa_denunciado = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $motivacao = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $data_inicio_ocorrencia = null;
// 1. Tenho a certeza absoluta
// 2. Não tenho certeza absoluta sobre esta data
// 3. Ocorrência(s) a decorrer
#[ORM\Column(type:Types::INTEGER)]
private ?int $inicio_ocorrencia_comment = null;
// 1. Pelo menos uma vez
// 2. Esporádico
// 3. Frequente
// 4. Constante
#[ORM\Column(type:Types::INTEGER)]
private ?int $regularidade_ocorrencia = null;
#[ORM\Column(length: 255)]
private ?string $local_ocorrencia = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $corpo = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $data_criacao = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $data_editado = null;
#[ORM\Column(length: 255)]
private ?string $codigo = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $data_fim_ocorrencia = null;
#[ORM\ManyToMany(targetEntity: Acessos::class, mappedBy: 'denuncia')]
private Collection $acessos;
#[ORM\OneToMany(mappedBy: 'denuncia', targetEntity: Mensagens::class)]
private Collection $mensagens;
#[ORM\OneToMany(mappedBy: 'denuncia', targetEntity: Observacoes::class)]
private Collection $observacoes;
#[ORM\OneToMany(mappedBy: 'denuncia', targetEntity: Anexos::class)]
private Collection $anexos;
public function __construct($codigo=null)
{
$this->acessos = new ArrayCollection();
$this->mensagens = new ArrayCollection();
$this->observacoes = new ArrayCollection();
$this->anexos = new ArrayCollection();
$this->inicio_ocorrencia_comment = 1;
$this->regularidade_ocorrencia = 1;
}
public function getId(): ?int
{
return $this->id;
}
public function getTipologia(): ?Tipologias
{
return $this->tipologia;
}
public function setTipologia(?Tipologias $tipologia): self
{
$this->tipologia = $tipologia;
return $this;
}
public function getEstado(): ?Estados
{
return $this->estado;
}
public function setEstado(?Estados $estado): self
{
$this->estado = $estado;
return $this;
}
public function getEmailDenunciante(): ?string
{
return $this->email_denunciante;
}
public function setEmailDenunciante(?string $email_denunciante): self
{
$this->email_denunciante = $email_denunciante;
return $this;
}
public function getInicioOcorrenciaComment(): ?int
{
return $this->inicio_ocorrencia_comment;
}
public function setInicioOcorrenciaComment(?int $inicio_ocorrencia_comment): self
{
$this->inicio_ocorrencia_comment = $inicio_ocorrencia_comment;
return $this;
}
public function getRegularidadeOcorrencia(): ?int
{
return $this->regularidade_ocorrencia;
}
public function setRegularidadeOcorrencia(?int $regularidade_ocorrencia): self
{
$this->regularidade_ocorrencia = $regularidade_ocorrencia;
return $this;
}
public function isAnonimato(): ?bool
{
return $this->anonimato;
}
public function setAnonimato(bool $anonimato): self
{
$this->anonimato = $anonimato;
return $this;
}
public function getNomeDenunciante(): ?string
{
return $this->nome_denunciante;
}
public function setNomeDenunciante(?string $nome_denunciante): self
{
$this->nome_denunciante = $nome_denunciante;
return $this;
}
public function getTelefoneDenunciante(): ?string
{
return $this->telefone_denunciante;
}
public function setTelefoneDenunciante(?string $telefone_denunciante): self
{
$this->telefone_denunciante = $telefone_denunciante;
return $this;
}
public function getNomeDenunciado(): ?string
{
return $this->nome_denunciado;
}
public function setNomeDenunciado(string $nome_denunciado): self
{
$this->nome_denunciado = $nome_denunciado;
return $this;
}
public function getTelefoneDenunciado(): ?string
{
return $this->telefone_denunciado;
}
public function setTelefoneDenunciado(?string $telefone_denunciado): self
{
$this->telefone_denunciado = $telefone_denunciado;
return $this;
}
public function getEmailDenunciado(): ?string
{
return $this->email_denunciado;
}
public function setEmailDenunciado(?string $email_denunciado): self
{
$this->email_denunciado = $email_denunciado;
return $this;
}
public function getEmpresaDenunciado(): ?string
{
return $this->empresa_denunciado;
}
public function setEmpresaDenunciado(string $empresa_denunciado): self
{
$this->empresa_denunciado = $empresa_denunciado;
return $this;
}
public function getMotivacao(): ?string
{
return $this->motivacao;
}
public function setMotivacao(string $motivacao): self
{
$this->motivacao = $motivacao;
return $this;
}
public function getDataInicioOcorrencia(): ?\DateTimeInterface
{
return $this->data_inicio_ocorrencia;
}
public function setDataInicioOcorrencia(\DateTimeInterface $data_inicio_ocorrencia): self
{
$this->data_inicio_ocorrencia = $data_inicio_ocorrencia;
return $this;
}
public function getLocalOcorrencia(): ?string
{
return $this->local_ocorrencia;
}
public function setLocalOcorrencia(string $local_ocorrencia): self
{
$this->local_ocorrencia = $local_ocorrencia;
return $this;
}
public function getCorpo(): ?string
{
return $this->corpo;
}
public function setCorpo(string $corpo): self
{
$this->corpo = $corpo;
return $this;
}
public function getDataCriacao(): ?\DateTimeInterface
{
return $this->data_criacao;
}
public function setDataCriacao(\DateTimeInterface $data_criacao): self
{
$this->data_criacao = $data_criacao;
return $this;
}
public function getDataEditado(): ?\DateTimeInterface
{
return $this->data_editado;
}
public function setDataEditado(\DateTimeInterface $data_editado): self
{
$this->data_editado = $data_editado;
return $this;
}
public function getCodigo(): ?string
{
return $this->codigo;
}
public function setCodigo(string $codigo): self
{
$this->codigo = $codigo;
return $this;
}
public function getDataFimOcorrencia(): ?\DateTimeInterface
{
return $this->data_fim_ocorrencia;
}
public function setDataFimOcorrencia(\DateTimeInterface $data_fim_ocorrencia): self
{
$this->data_fim_ocorrencia = $data_fim_ocorrencia;
return $this;
}
/**
* @return Collection<int, Acessos>
*/
public function getAcessos(): Collection
{
return $this->acessos;
}
public function addAcesso(Acessos $acesso): self
{
if (!$this->acessos->contains($acesso)) {
$this->acessos->add($acesso);
$acesso->addDenuncium($this);
}
return $this;
}
public function removeAcesso(Acessos $acesso): self
{
if ($this->acessos->removeElement($acesso)) {
$acesso->removeDenuncium($this);
}
return $this;
}
/**
* @return Collection<int, Mensagens>
*/
public function getMensagens(): Collection
{
return $this->mensagens;
}
public function addMensagen(Mensagens $mensagen): self
{
if (!$this->mensagens->contains($mensagen)) {
$this->mensagens->add($mensagen);
$mensagen->setDenuncia($this);
}
return $this;
}
public function removeMensagen(Mensagens $mensagen): self
{
if ($this->mensagens->removeElement($mensagen)) {
// set the owning side to null (unless already changed)
if ($mensagen->getDenuncia() === $this) {
$mensagen->setDenuncia(null);
}
}
return $this;
}
/**
* @return Collection<int, Observacoes>
*/
public function getObservacoes(): Collection
{
return $this->observacoes;
}
public function addObservaco(Observacoes $observaco): self
{
if (!$this->observacoes->contains($observaco)) {
$this->observacoes->add($observaco);
$observaco->setDenuncia($this);
}
return $this;
}
public function removeObservaco(Observacoes $observaco): self
{
if ($this->observacoes->removeElement($observaco)) {
// set the owning side to null (unless already changed)
if ($observaco->getDenuncia() === $this) {
$observaco->setDenuncia(null);
}
}
return $this;
}
/**
* @return Collection<int, Anexos>
*/
public function getAnexos(): Collection
{
return $this->anexos;
}
public function addAnexo(Anexos $anexo): self
{
if (!$this->anexos->contains($anexo)) {
$this->anexos->add($anexo);
$anexo->setDenuncia($this);
}
return $this;
}
public function removeAnexo(Anexos $anexo): self
{
if ($this->anexos->removeElement($anexo)) {
// set the owning side to null (unless already changed)
if ($anexo->getDenuncia() === $this) {
$anexo->setDenuncia(null);
}
}
return $this;
}
function generateUniqueCode() {
$timestamp = time(); // Obtener el timestamp actual
$caracteres = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // caracteres permitidos
$codigo = '';
$codigo2 = '';
for ($i = 0; $i < 5; $i++) {
for ($j = 0; $j < 5; $j++) {
$indice = mt_rand(0, strlen($caracteres) - 1);
$codigo .= $caracteres[$indice];
}
if ($i != 4) {
$codigo .= '-';
}
}
for ($i = 0; $i < 5; $i++) {
$indice = $timestamp % strlen($caracteres);
$codigo2 .= $caracteres[$indice];
$timestamp = floor($timestamp / strlen($caracteres));
}
// Agregar timestamp al final del código
$codigo .= '-' . $codigo2;
return $codigo;
}
public function jsonSerialize()
{
return [
'id' => $this->id,
'tipologia' => $this->tipologia->getId(),
'estado' => $this->estado->getDescricao(),
'email_denunciante' => $this->email_denunciante,
'anonimato' => $this->anonimato,
'nome_denunciante' => $this->nome_denunciante,
'telefone_denunciante' => $this->telefone_denunciante,
'nome_denunciado' => $this->nome_denunciado,
'telefone_denunciado' => $this->telefone_denunciado,
'email_denunciado' => $this->email_denunciado,
'empresa_denunciado' => $this->empresa_denunciado,
'motivacao' => $this->motivacao,
'data_inicio_ocorrencia' => $this->data_inicio_ocorrencia,
'inicio_ocorrencia_comment' => $this->inicio_ocorrencia_comment,
'regularidade_ocorrencia' => $this->regularidade_ocorrencia,
'local_ocorrencia' => $this->local_ocorrencia,
'corpo' => $this->corpo,
'data_criacao' => $this->data_criacao,
'data_editado' => $this->data_editado,
'codigo' => $this->codigo,
'data_fim_ocorrencia' => $this->data_fim_ocorrencia,
'acessos' => $this->acessos,
'mensagens' => $this->mensagens,
'observacoes' => $this->observacoes,
'anexos' => $this->anexos,
];
}
}