src/Entity/Denuncias.php line 502

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DenunciasRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JsonSerializable;
  9. #[ORM\Entity(repositoryClass: DenunciasRepository::class)]
  10. class Denuncias implements JsonSerializable
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id = null;
  16.     #[ORM\ManyToOne(inversedBy: 'denuncias')]
  17.     private ?Tipologias $tipologia = null;
  18.     #[ORM\ManyToOne(inversedBy: 'denuncias')]
  19.     private ?Estados $estado = null;
  20.     #[ORM\Column(length: 255, nullable: true)]
  21.     private ?string $email_denunciante = null;
  22.     #[ORM\Column]
  23.     private ?bool $anonimato = null;
  24.     #[ORM\Column(length: 255, nullable: true)]
  25.     private ?string $nome_denunciante = null;
  26.     #[ORM\Column(length: 255, nullable: true)]
  27.     private ?string $telefone_denunciante = null;
  28.     #[ORM\Column(length: 255)]
  29.     private ?string $nome_denunciado = null;
  30.     #[ORM\Column(length: 255, nullable: true)]
  31.     private ?string $telefone_denunciado = null;
  32.     #[ORM\Column(length: 255, nullable: true)]
  33.     private ?string $email_denunciado = null;
  34.     #[ORM\Column(length: 255)]
  35.     private ?string $empresa_denunciado = null;
  36.     #[ORM\Column(type: Types::TEXT)]
  37.     private ?string $motivacao = null;
  38.     #[ORM\Column(type: Types::DATETIME_MUTABLE)]
  39.     private ?\DateTimeInterface $data_inicio_ocorrencia = null;
  40.     // 1. Tenho a certeza absoluta
  41.     // 2. Não tenho certeza absoluta sobre esta data
  42.     // 3. Ocorrência(s) a decorrer
  43.     #[ORM\Column(type:Types::INTEGER)]
  44.     private ?int $inicio_ocorrencia_comment = null;
  45.     // 1. Pelo menos uma vez
  46.     // 2. Esporádico
  47.     // 3. Frequente
  48.     // 4. Constante
  49.     #[ORM\Column(type:Types::INTEGER)]
  50.     private ?int $regularidade_ocorrencia = null;
  51.     #[ORM\Column(length: 255)]
  52.     private ?string $local_ocorrencia = null;
  53.     #[ORM\Column(type: Types::TEXT)]
  54.     private ?string $corpo = null;
  55.     #[ORM\Column(type: Types::DATETIME_MUTABLE)]
  56.     private ?\DateTimeInterface $data_criacao = null;
  57.     #[ORM\Column(type: Types::DATETIME_MUTABLE)]
  58.     private ?\DateTimeInterface $data_editado = null;
  59.     #[ORM\Column(length: 255)]
  60.     private ?string $codigo = null;
  61.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  62.     private ?\DateTimeInterface $data_fim_ocorrencia = null;
  63.     #[ORM\ManyToMany(targetEntity: Acessos::class, mappedBy: 'denuncia')]
  64.     private Collection $acessos;
  65.     #[ORM\OneToMany(mappedBy: 'denuncia', targetEntity: Mensagens::class)]
  66.     private Collection $mensagens;
  67.     #[ORM\OneToMany(mappedBy: 'denuncia', targetEntity: Observacoes::class)]
  68.     private Collection $observacoes;
  69.     #[ORM\OneToMany(mappedBy: 'denuncia', targetEntity: Anexos::class)]
  70.     private Collection $anexos;
  71.     public function __construct($codigo=null)
  72.     {
  73.         $this->acessos = new ArrayCollection();
  74.         $this->mensagens = new ArrayCollection();
  75.         $this->observacoes = new ArrayCollection();
  76.         $this->anexos = new ArrayCollection();
  77.         $this->inicio_ocorrencia_comment = 1;
  78.         $this->regularidade_ocorrencia = 1;
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getTipologia(): ?Tipologias
  85.     {
  86.         return $this->tipologia;
  87.     }
  88.     public function setTipologia(?Tipologias $tipologia): self
  89.     {
  90.         $this->tipologia = $tipologia;
  91.         return $this;
  92.     }
  93.     public function getEstado(): ?Estados
  94.     {
  95.         return $this->estado;
  96.     }
  97.     public function setEstado(?Estados $estado): self
  98.     {
  99.         $this->estado = $estado;
  100.         return $this;
  101.     }
  102.     public function getEmailDenunciante(): ?string
  103.     {
  104.         return $this->email_denunciante;
  105.     }
  106.     public function setEmailDenunciante(?string $email_denunciante): self
  107.     {
  108.         $this->email_denunciante = $email_denunciante;
  109.         return $this;
  110.     }
  111.     public function getInicioOcorrenciaComment(): ?int
  112.     {
  113.         return $this->inicio_ocorrencia_comment;
  114.     }
  115.     public function setInicioOcorrenciaComment(?int $inicio_ocorrencia_comment): self
  116.     {
  117.         $this->inicio_ocorrencia_comment = $inicio_ocorrencia_comment;
  118.         return $this;
  119.     }
  120.     public function getRegularidadeOcorrencia(): ?int
  121.     {
  122.         return $this->regularidade_ocorrencia;
  123.     }
  124.     public function setRegularidadeOcorrencia(?int $regularidade_ocorrencia): self
  125.     {
  126.         $this->regularidade_ocorrencia = $regularidade_ocorrencia;
  127.         return $this;
  128.     }
  129.     public function isAnonimato(): ?bool
  130.     {
  131.         return $this->anonimato;
  132.     }
  133.     public function setAnonimato(bool $anonimato): self
  134.     {
  135.         $this->anonimato = $anonimato;
  136.         return $this;
  137.     }
  138.     public function getNomeDenunciante(): ?string
  139.     {
  140.         return $this->nome_denunciante;
  141.     }
  142.     public function setNomeDenunciante(?string $nome_denunciante): self
  143.     {
  144.         $this->nome_denunciante = $nome_denunciante;
  145.         return $this;
  146.     }
  147.     public function getTelefoneDenunciante(): ?string
  148.     {
  149.         return $this->telefone_denunciante;
  150.     }
  151.     public function setTelefoneDenunciante(?string $telefone_denunciante): self
  152.     {
  153.         $this->telefone_denunciante = $telefone_denunciante;
  154.         return $this;
  155.     }
  156.     public function getNomeDenunciado(): ?string
  157.     {
  158.         return $this->nome_denunciado;
  159.     }
  160.     public function setNomeDenunciado(string $nome_denunciado): self
  161.     {
  162.         $this->nome_denunciado = $nome_denunciado;
  163.         return $this;
  164.     }
  165.     public function getTelefoneDenunciado(): ?string
  166.     {
  167.         return $this->telefone_denunciado;
  168.     }
  169.     public function setTelefoneDenunciado(?string $telefone_denunciado): self
  170.     {
  171.         $this->telefone_denunciado = $telefone_denunciado;
  172.         return $this;
  173.     }
  174.     public function getEmailDenunciado(): ?string
  175.     {
  176.         return $this->email_denunciado;
  177.     }
  178.     public function setEmailDenunciado(?string $email_denunciado): self
  179.     {
  180.         $this->email_denunciado = $email_denunciado;
  181.         return $this;
  182.     }
  183.     public function getEmpresaDenunciado(): ?string
  184.     {
  185.         return $this->empresa_denunciado;
  186.     }
  187.     public function setEmpresaDenunciado(string $empresa_denunciado): self
  188.     {
  189.         $this->empresa_denunciado = $empresa_denunciado;
  190.         return $this;
  191.     }
  192.     public function getMotivacao(): ?string
  193.     {
  194.         return $this->motivacao;
  195.     }
  196.     public function setMotivacao(string $motivacao): self
  197.     {
  198.         $this->motivacao = $motivacao;
  199.         return $this;
  200.     }
  201.     public function getDataInicioOcorrencia(): ?\DateTimeInterface
  202.     {
  203.         return $this->data_inicio_ocorrencia;
  204.     }
  205.     public function setDataInicioOcorrencia(\DateTimeInterface $data_inicio_ocorrencia): self
  206.     {
  207.         $this->data_inicio_ocorrencia = $data_inicio_ocorrencia;
  208.         return $this;
  209.     }
  210.     public function getLocalOcorrencia(): ?string
  211.     {
  212.         return $this->local_ocorrencia;
  213.     }
  214.     public function setLocalOcorrencia(string $local_ocorrencia): self
  215.     {
  216.         $this->local_ocorrencia = $local_ocorrencia;
  217.         return $this;
  218.     }
  219.     public function getCorpo(): ?string
  220.     {
  221.         return $this->corpo;
  222.     }
  223.     public function setCorpo(string $corpo): self
  224.     {
  225.         $this->corpo = $corpo;
  226.         return $this;
  227.     }
  228.     public function getDataCriacao(): ?\DateTimeInterface
  229.     {
  230.         return $this->data_criacao;
  231.     }
  232.     public function setDataCriacao(\DateTimeInterface $data_criacao): self
  233.     {
  234.         $this->data_criacao = $data_criacao;
  235.         return $this;
  236.     }
  237.     public function getDataEditado(): ?\DateTimeInterface
  238.     {
  239.         return $this->data_editado;
  240.     }
  241.     public function setDataEditado(\DateTimeInterface $data_editado): self
  242.     {
  243.         $this->data_editado = $data_editado;
  244.         return $this;
  245.     }
  246.     public function getCodigo(): ?string
  247.     {
  248.         return $this->codigo;
  249.     }
  250.     public function setCodigo(string $codigo): self
  251.     {
  252.         $this->codigo = $codigo;
  253.         return $this;
  254.     }
  255.     public function getDataFimOcorrencia(): ?\DateTimeInterface
  256.     {
  257.         return $this->data_fim_ocorrencia;
  258.     }
  259.     public function setDataFimOcorrencia(\DateTimeInterface $data_fim_ocorrencia): self
  260.     {
  261.         $this->data_fim_ocorrencia = $data_fim_ocorrencia;
  262.         return $this;
  263.     }
  264.     /**
  265.      * @return Collection<int, Acessos>
  266.      */
  267.     public function getAcessos(): Collection
  268.     {
  269.         return $this->acessos;
  270.     }
  271.     public function addAcesso(Acessos $acesso): self
  272.     {
  273.         if (!$this->acessos->contains($acesso)) {
  274.             $this->acessos->add($acesso);
  275.             $acesso->addDenuncium($this);
  276.         }
  277.         return $this;
  278.     }
  279.     public function removeAcesso(Acessos $acesso): self
  280.     {
  281.         if ($this->acessos->removeElement($acesso)) {
  282.             $acesso->removeDenuncium($this);
  283.         }
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return Collection<int, Mensagens>
  288.      */
  289.     public function getMensagens(): Collection
  290.     {
  291.         return $this->mensagens;
  292.     }
  293.     public function addMensagen(Mensagens $mensagen): self
  294.     {
  295.         if (!$this->mensagens->contains($mensagen)) {
  296.             $this->mensagens->add($mensagen);
  297.             $mensagen->setDenuncia($this);
  298.         }
  299.         return $this;
  300.     }
  301.     public function removeMensagen(Mensagens $mensagen): self
  302.     {
  303.         if ($this->mensagens->removeElement($mensagen)) {
  304.             // set the owning side to null (unless already changed)
  305.             if ($mensagen->getDenuncia() === $this) {
  306.                 $mensagen->setDenuncia(null);
  307.             }
  308.         }
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return Collection<int, Observacoes>
  313.      */
  314.     public function getObservacoes(): Collection
  315.     {
  316.         return $this->observacoes;
  317.     }
  318.     public function addObservaco(Observacoes $observaco): self
  319.     {
  320.         if (!$this->observacoes->contains($observaco)) {
  321.             $this->observacoes->add($observaco);
  322.             $observaco->setDenuncia($this);
  323.         }
  324.         return $this;
  325.     }
  326.     public function removeObservaco(Observacoes $observaco): self
  327.     {
  328.         if ($this->observacoes->removeElement($observaco)) {
  329.             // set the owning side to null (unless already changed)
  330.             if ($observaco->getDenuncia() === $this) {
  331.                 $observaco->setDenuncia(null);
  332.             }
  333.         }
  334.         return $this;
  335.     }
  336.     /**
  337.      * @return Collection<int, Anexos>
  338.      */
  339.     public function getAnexos(): Collection
  340.     {
  341.         return $this->anexos;
  342.     }
  343.     public function addAnexo(Anexos $anexo): self
  344.     {
  345.         if (!$this->anexos->contains($anexo)) {
  346.             $this->anexos->add($anexo);
  347.             $anexo->setDenuncia($this);
  348.         }
  349.         return $this;
  350.     }
  351.     public function removeAnexo(Anexos $anexo): self
  352.     {
  353.         if ($this->anexos->removeElement($anexo)) {
  354.             // set the owning side to null (unless already changed)
  355.             if ($anexo->getDenuncia() === $this) {
  356.                 $anexo->setDenuncia(null);
  357.             }
  358.         }
  359.         return $this;
  360.     }
  361.     function generateUniqueCode() {
  362.         $timestamp = time(); // Obtener el timestamp actual
  363.         $caracteres = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // caracteres permitidos
  364.         $codigo = '';
  365.         $codigo2 = '';
  366.         for ($i = 0; $i < 5; $i++) {
  367.             for ($j = 0; $j < 5; $j++) {
  368.                 $indice = mt_rand(0, strlen($caracteres) - 1);
  369.                 $codigo .= $caracteres[$indice];
  370.             }
  371.             if ($i != 4) {
  372.                 $codigo .= '-';
  373.             }
  374.         }
  375.         for ($i = 0; $i < 5; $i++) {
  376.             $indice = $timestamp % strlen($caracteres);
  377.             $codigo2 .= $caracteres[$indice];
  378.             $timestamp = floor($timestamp / strlen($caracteres));
  379.         }
  380.         // Agregar timestamp al final del código
  381.         $codigo .= '-' . $codigo2;
  382.         return $codigo;
  383.     }
  384.     public function jsonSerialize()
  385.     {
  386.         return [
  387.             'id' => $this->id,
  388.             'tipologia' => $this->tipologia->getId(),
  389.             'estado' => $this->estado->getDescricao(),
  390.             'email_denunciante' => $this->email_denunciante,
  391.             'anonimato' => $this->anonimato,
  392.             'nome_denunciante' => $this->nome_denunciante,
  393.             'telefone_denunciante' => $this->telefone_denunciante,
  394.             'nome_denunciado' => $this->nome_denunciado,
  395.             'telefone_denunciado' => $this->telefone_denunciado,
  396.             'email_denunciado' => $this->email_denunciado,
  397.             'empresa_denunciado' => $this->empresa_denunciado,
  398.             'motivacao' => $this->motivacao,
  399.             'data_inicio_ocorrencia' => $this->data_inicio_ocorrencia,
  400.             'inicio_ocorrencia_comment' => $this->inicio_ocorrencia_comment,
  401.             'regularidade_ocorrencia' => $this->regularidade_ocorrencia,
  402.             'local_ocorrencia' => $this->local_ocorrencia,
  403.             'corpo' => $this->corpo,
  404.             'data_criacao' => $this->data_criacao,
  405.             'data_editado' => $this->data_editado,
  406.             'codigo' => $this->codigo,
  407.             'data_fim_ocorrencia' => $this->data_fim_ocorrencia,
  408.             'acessos' => $this->acessos,
  409.             'mensagens' => $this->mensagens,
  410.             'observacoes' => $this->observacoes,
  411.             'anexos' => $this->anexos,
  412.         ];
  413.     }
  414. }