src/Entity/Cliente/Modelagem/Modelagem.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Cliente\Modelagem;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. /**
  6.  * @ORM\Table(name="modelagem.modelagem")
  7.  * @ORM\Entity(repositoryClass="App\Repository\Cliente\Modelagem\ModelagemRepository")
  8.  */
  9. class Modelagem
  10. {
  11.     /**
  12.      * @var int
  13.      *
  14.      * @ORM\Column(name="id_modelagem", type="integer", nullable=false)
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue(strategy="AUTO")
  17.      */
  18.     private $idModelagem;
  19.     /**
  20.      * @ORM\ManyToOne(targetEntity="App\Entity\Cliente\Modelagem\Programa", inversedBy="modelagens", fetch="EAGER")
  21.      * @ORM\JoinColumn(name="id_programa", referencedColumnName="id_programa")
  22.      */
  23.     private $programa;
  24.     /**
  25.      * @ORM\Column(name="titulo", type="string", length=255)
  26.      *
  27.      * @Assert\NotBlank(message="Campo título não pode ser vazio")
  28.      * @Assert\Length(
  29.      *     min=2,
  30.      *     max=200,
  31.      *     minMessage="Campo título deve ter no minimo {{ limit }} caracteres.",
  32.      *     maxMessage="Campo título deve ter no maximo {{ limit }} caracteres."
  33.      * )
  34.      */
  35.     private $titulo;
  36.     /**
  37.      * @var json
  38.      *
  39.      * @ORM\Column(name="config", type="json")
  40.      */
  41.     private $config;
  42.     /**
  43.      * @ORM\Column(name="inicio", type="integer")
  44.      * @Assert\NotBlank(message="Campo início não pode ser vazio")
  45.      * @Assert\Regex("/([12]\d{3}(0[1-9]|1[0-2]))/", message="Campo início está incorreto")
  46.      */
  47.     private $inicio;
  48.     /**
  49.      * @ORM\Column(name="fim", type="integer", nullable=true)
  50.      * @Assert\NotBlank(message="Campo fim não pode ser vazio")
  51.      * @Assert\Regex("/([12]\d{3}(0[1-9]|1[0-2]))/", message="Campo fim está incorreto")
  52.      */
  53.     private $fim;
  54.     /**
  55.      * @ORM\Column(name="id_usuario", type="integer")
  56.      */
  57.     private $id_usuario;
  58.     /**
  59.      * @ORM\Column(name="ativo", type="boolean")
  60.      */
  61.     private $ativo;
  62.     /**
  63.      * @ORM\Column(name="observacao")
  64.      */
  65.     private $observacao;
  66.     /**
  67.      * @ORM\Column(name="data_upd", type="datetimetz")
  68.      */
  69.     private $data_upd;
  70.     /**
  71.      * @ORM\Column(name="id_visao")
  72.      */
  73.     private $idVisao;
  74.     /**
  75.      * @ORM\Column(type="boolean", name="envia_mensagem", nullable=FALSE)
  76.      */
  77.     private $envia_mensagem;
  78.     
  79.     /**
  80.      * @ORM\Column(type="boolean", name="aceite_mensagem", nullable=FALSE)
  81.      */
  82.     private $aceite_mensagem;
  83.     /**
  84.      * @ORM\Column(type="integer", name="id_usuario_mensagem", nullable=FALSE)
  85.      */
  86.     private $id_usuario_mensagem;
  87.     private $where;
  88.     public function getIdModelagem()
  89.     {
  90.         return $this->idModelagem;
  91.     }
  92.     public function getTitulo()
  93.     {
  94.         return $this->titulo;
  95.     }
  96.     public function getConfig(): ?array
  97.     {
  98.         return $this->config;
  99.     }
  100.     public function getInicio()
  101.     {
  102.         return $this->inicio;
  103.     }
  104.     public function getFim()
  105.     {
  106.         return $this->fim;
  107.     }
  108.     public function setIdModelagem($idModelagem)
  109.     {
  110.         $this->idModelagem $idModelagem;
  111.         return $this;
  112.     }
  113.     public function setTitulo($titulo)
  114.     {
  115.         $this->titulo $titulo;
  116.         return $this;
  117.     }
  118.     public function setConfig($config)
  119.     {
  120.         $this->config $config;
  121.         return $this;
  122.     }
  123.     public function setInicio($inicio)
  124.     {
  125.         $this->inicio $inicio;
  126.         return $this;
  127.     }
  128.     public function setFim($fim)
  129.     {
  130.         $this->fim $fim;
  131.         return $this;
  132.     }
  133.     /**
  134.      * Get the value of id_usuario.
  135.      */
  136.     public function getIdUsuario()
  137.     {
  138.         return $this->id_usuario;
  139.     }
  140.     /**
  141.      * Set the value of id_usuario.
  142.      *
  143.      * @param mixed $id_usuario
  144.      *
  145.      * @return self
  146.      */
  147.     public function setIdUsuario($id_usuario)
  148.     {
  149.         $this->id_usuario $id_usuario;
  150.         return $this;
  151.     }
  152.     public function getAtivo()
  153.     {
  154.         return $this->ativo;
  155.     }
  156.     public function setAtivo($ativo)
  157.     {
  158.         $this->ativo $ativo;
  159.         return $this;
  160.     }
  161.     /**
  162.      * Get the value of observacao.
  163.      */
  164.     public function getObservacao()
  165.     {
  166.         return $this->observacao;
  167.     }
  168.     /**
  169.      * Set the value of observacao.
  170.      *
  171.      * @param mixed $observacao
  172.      *
  173.      * @return self
  174.      */
  175.     public function setObservacao($observacao)
  176.     {
  177.         $this->observacao $observacao;
  178.         return $this;
  179.     }
  180.     /**
  181.      * Get the value of data_upd.
  182.      */
  183.     public function getDataUpd()
  184.     {
  185.         return $this->data_upd;
  186.     }
  187.     /**
  188.      * Set the value of data_upd.
  189.      *
  190.      * @param mixed $data_upd
  191.      *
  192.      * @return self
  193.      */
  194.     public function setDataUpd($data_upd)
  195.     {
  196.         $this->data_upd $data_upd;
  197.         return $this;
  198.     }
  199.     /**
  200.      * Get the value of id_visao.
  201.      */
  202.     public function getIdVisao()
  203.     {
  204.         return $this->parsePostgresToArray($this->idVisao);
  205.     }
  206.     /**
  207.      * Set the value of id_visao.
  208.      *
  209.      * @param mixed $idVisao
  210.      *
  211.      * @return self
  212.      */
  213.     public function setIdVisao($idVisao)
  214.     {
  215.         $idVisao $this->parseArrayToPostgres($idVisao);
  216.         $this->idVisao $idVisao;
  217.         return $this;
  218.     }
  219.     public function getPrograma(): ?Programa
  220.     {
  221.         return $this->programa;
  222.     }
  223.     public function setPrograma(?Programa $programa): self
  224.     {
  225.         $this->programa $programa;
  226.         return $this;
  227.     }
  228.     public function getEnviaMensagem(): bool
  229.     {
  230.         return $this->envia_mensagem;
  231.     }
  232.     
  233.     public function setEnviaMensagem(bool $envia_mensagem): self
  234.     {
  235.         $this->envia_mensagem $envia_mensagem;
  236.     
  237.         return $this;
  238.     }
  239.     
  240.     public function getAceiteMensagem(): bool
  241.     {
  242.         return $this->aceite_mensagem;
  243.     }
  244.     
  245.     public function setAceiteMensagem(bool $aceite_mensagem): self
  246.     {
  247.         $this->aceite_mensagem $aceite_mensagem;
  248.     
  249.         return $this;
  250.     }
  251.     
  252.     public function getIdUsuarioMensagem(): int
  253.     {
  254.         return $this->id_usuario_mensagem;
  255.     }
  256.     
  257.     public function setIdUsuarioMensagem(int $id_usuario_mensagem): self
  258.     {
  259.         $this->id_usuario_mensagem $id_usuario_mensagem;
  260.     
  261.         return $this;
  262.     }
  263.     /**
  264.      * Método utilizado para buscar quais módulos
  265.      * estão disponíveis para o usuário perante a
  266.      * configuração da Modelagem.
  267.      *
  268.      * @author Matheus Vieira <matheus.aguilar@2im.com.br>
  269.      */
  270.     public function getModulos(): array
  271.     {
  272.         return $this->config['avaliado']['modulos'] ?? [];
  273.     }
  274.     /**
  275.      * Get the value of where.
  276.      */
  277.     public function getWhere()
  278.     {
  279.         return " id_modelagem = {$this->getIdModelagem()} AND id_programa = {$this->getPrograma()->getIdPrograma()}";
  280.     }
  281.     /**
  282.      * Set the value of where.
  283.      *
  284.      * @param mixed $where
  285.      *
  286.      * @return self
  287.      */
  288.     public function setWhere($where): string
  289.     {
  290.         $this->where $where;
  291.         return $this;
  292.     }
  293.     public function parseArrayToPostgres(array $array)
  294.     {
  295.         return '{'.implode(','$array).'}';
  296.     }
  297.     public function parsePostgresToArray(?string $string): array
  298.     {
  299.         return is_null($string) ? [] : explode(','str_replace(['{''}'], ''$string));
  300.     }
  301.     /**
  302.      * Popula Modelagem.
  303.      *
  304.      * @author Juliano Silva <juliano.silva@2im.com.br>
  305.      *
  306.      * @param string $titulo
  307.      * @param string $mesInicio
  308.      * @param string $mesFim
  309.      * @param int    $programa
  310.      * @param string $observacao
  311.      *
  312.      * @return Modelagem $modelagem
  313.      */
  314.     public function fillObject(?string $titulo, ?string $mesInicio, ?string $anoIncio, ?string $mesFim, ?string $anoFim$programaint $idUsuario, array $idVisao, ?string $observacao, ?array $config nullbool $ativo truebool $deletado false, ?string $where)
  315.     {
  316.         $dataAtual date('d/m/Y H:i:s');
  317.         $this
  318.             ->setTitulo($titulo)
  319.             ->setInicio($this->trataPeriodo($mesInicio$anoIncio))
  320.             ->setFim($this->trataPeriodo($mesFim$anoFim))
  321.             ->setPrograma($programa)
  322.             ->setId_usuario($idUsuario)
  323.             ->setIdVisao($idVisao)
  324.             ->setObservacao($observacao)
  325.             ->setConfig($config)
  326.             ->setAtivo($ativo)
  327.             ->setWhere($where)
  328.         ;
  329.     }
  330.     /**
  331.      * trata mes e ano em um inteiro
  332.      * Se necessário adiciona zero a esquerda no mês.
  333.      *
  334.      * @param string $mes 1
  335.      * @param string $ano 2015
  336.      *
  337.      * @return int exemplo: 201501
  338.      */
  339.     public function trataPeriodo(string $messtring $ano): int
  340.     {
  341.         return (int) sprintf('%s%s'$anostr_pad($mes2'0'STR_PAD_LEFT));
  342.     }
  343.     /**
  344.      * Converte periodo AAAAMM em um array de ano e mês.
  345.      *
  346.      * @param string $periodo
  347.      *
  348.      * @return array exemplo ['ano' => '2015', 'mes' => '01']
  349.      */
  350.     public function separaPeriodo($periodo): array
  351.     {
  352.         list($ano$mes) = str_split($periodo4);
  353.         return ['ano' => (string) $ano'mes' => (string) $mes];
  354.     }
  355.     /**
  356.      * Converte periodo inicio e fim e salva no mesmo objeto.
  357.      *
  358.      * @author Juliano Silva <juliano.silva@2im.com.br>
  359.      */
  360.     public function parsePeriodos()
  361.     {
  362.         $inicio $this->separaPeriodo($this->getInicio());
  363.         $fim $this->separaPeriodo($this->getFim());
  364.         $this->inicioArray $inicio;
  365.         $this->fimArray $fim;
  366.     }
  367.     /**
  368.      * Esse retorna se a visualização dos datalhes de um indicador de custeio
  369.      * está disponível para visualização do usuário.
  370.      */
  371.     public function permitirDetalhes(?string $perfil NULL): bool
  372.     {
  373.         return isset($this->config[$perfil]) ? $this->config[$perfil]['custeio']['detalhes'] : (isset($this->config['custeio']) ? $this->config['custeio']['detalhes'] : true);
  374.     }
  375. }