src/Entity/Dispositivo.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\Common\Collections\Criteria;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use JMS\Serializer\Annotation\ExclusionPolicy;
  9. use JMS\Serializer\Annotation\Expose;
  10. use JMS\Serializer\Annotation\Groups;
  11. use App\Entity\Interfaces\UsuarioDependenteInterface;
  12. use App\Entity\Interfaces\ContratoDependenteInterface;
  13. /**
  14.  * @ORM\Entity(repositoryClass="App\Repository\DispositivoRepository")
  15.  * @ExclusionPolicy("all")
  16.  */
  17. class Dispositivo extends AbstractEntity implements UsuarioDependenteInterfaceContratoDependenteInterface
  18. {
  19.     const PENDENTE 0;
  20.     const ATIVO 1;
  21.     const DESATIVO 2;
  22.     const RECUSADO 9;
  23.     const BLOQUEADO 1;
  24.     const DESBLOQUADO 0;
  25.     /**
  26.      * @ORM\Id()
  27.      * @ORM\GeneratedValue()
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @Assert\NotBlank
  33.      * @ORM\Column(type="string", length=50)
  34.      * @Expose
  35.      */
  36.     private $identificador;
  37.     /**
  38.      * @ORM\Column(type="string", length=100, nullable=true)
  39.      * @Expose
  40.      */
  41.     private $marca;
  42.     /**
  43.      * @ORM\Column(type="string", length=100, nullable=true)
  44.      * @Expose
  45.      */
  46.     private $modelo;
  47.     /**
  48.      * @Assert\NotBlank
  49.      * @ORM\ManyToOne(targetEntity="App\Entity\Contrato", inversedBy="dispositivos")
  50.      * @ORM\JoinColumn(nullable=false)
  51.      * @Expose
  52.      */
  53.     private $contrato;
  54.     /**
  55.      * @ORM\Column(type="string", length=12)
  56.      * @Expose
  57.      * @Groups({"new"})
  58.      */
  59.     private $selector;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity="App\Entity\Solicitacao", mappedBy="dispositivo", orphanRemoval=true)
  62.      */
  63.     private $solicitacoes;
  64.     /**
  65.      * @ORM\Column(type="smallint")
  66.      * @Expose
  67.      */
  68.     private $status;
  69.     
  70.     /**
  71.      * @ORM\Column(type="smallint", nullable=true)
  72.      * @Expose
  73.      */
  74.     private $bloqueio;
  75.     
  76.     /**
  77.      * @ORM\ManyToOne(targetEntity="App\Entity\Usuario", inversedBy="dispositivos")
  78.      * @ORM\JoinColumn(nullable=false)
  79.      * @Expose
  80.      */
  81.     private $usuario;
  82.     /**
  83.      * @Assert\NotBlank
  84.      * @ORM\Column(type="string", length=50, nullable=true)
  85.      * @Expose
  86.      */
  87.     private $informacaoComplementar;
  88.     /**
  89.      * @Assert\NotBlank
  90.      * @ORM\Column(type="string", length=50, nullable=true)
  91.      */
  92.     private $firebaseIdentificador;
  93.     /**
  94.      * @ORM\Column(type="string", length=6, nullable=true)
  95.      * @Expose
  96.      * @Groups({"senha"})
  97.      */
  98.     private $senha;
  99.     /**
  100.      * @ORM\OneToMany(targetEntity="App\Entity\PackageDispositivo", mappedBy="dispositivo", orphanRemoval=true, cascade={"persist"} )
  101.      */
  102.     private $packages;
  103.     
  104.     /**
  105.      * @ORM\OneToMany(targetEntity="App\Entity\DispositivoHistoricoAcao", mappedBy="dispositivo", orphanRemoval=true, cascade={"persist"} )     
  106.      */
  107.     private $historicoAcao;
  108.         
  109.     /**
  110.      * @ORM\Column(type="string", length=50, nullable=true)
  111.      */
  112.     private $identificador_propaganda;
  113.     
  114.     /**     
  115.      * @ORM\Column(type="string", length=500, nullable=true)
  116.      */
  117.     private $firebaseToken;
  118.     public function __construct()
  119.     {
  120.         $this->selector $this->generateSelector();
  121.         $this->status Dispositivo::PENDENTE;
  122.         $this->bloqueio Dispositivo::DESBLOQUADO;
  123.         $this->solicitacoes = new ArrayCollection();
  124.         $this->senha rand(100000999999);
  125.         $this->packages = new ArrayCollection();
  126.         $this->historicoAcao = new ArrayCollection();
  127.     }
  128.     public function getId(): ?int
  129.     {
  130.         return $this->id;
  131.     }
  132.     public function getIdentificador(): ?string
  133.     {
  134.         return $this->identificador;
  135.     }
  136.     public function setIdentificador(string $identificador): self
  137.     {
  138.         $this->identificador $identificador;
  139.         return $this;
  140.     }
  141.     public function getMarca(): ?string
  142.     {
  143.         return $this->marca;
  144.     }
  145.     public function setMarca(?string $marca): self
  146.     {
  147.         $this->marca $marca;
  148.         return $this;
  149.     }
  150.     public function getModelo(): ?string
  151.     {
  152.         return $this->modelo;
  153.     }
  154.     public function setModelo(?string $modelo): self
  155.     {
  156.         $this->modelo $modelo;
  157.         return $this;
  158.     }
  159.     public function getContrato(): ?Contrato
  160.     {
  161.         return $this->contrato;
  162.     }
  163.     public function setContrato(?Contrato $contrato): ContratoDependenteInterface
  164.     {
  165.         $this->contrato $contrato;
  166.         return $this;
  167.     }
  168.     public function getSelector(): ?string
  169.     {
  170.         return $this->selector;
  171.     }
  172.     public function setSelector(string $selector): self
  173.     {
  174.         $this->selector $selector;
  175.         return $this;
  176.     }
  177.     /**
  178.      * @return Collection|Solicitacao[]
  179.      */
  180.     public function getSolicitacoes(): Collection
  181.     {
  182.         return $this->solicitacoes;
  183.     }
  184.     public function addSolicitacao(Solicitacao $solicitacao): self
  185.     {
  186.         if (!$this->solicitacoes->contains($solicitacao)) {
  187.             $this->solicitacoes[] = $solicitacao;
  188.             $solicitacao->setDispositivo($this);
  189.         }
  190.         return $this;
  191.     }
  192.     public function removeSolicitacao(Solicitacao $solicitacao): self
  193.     {
  194.         if ($this->solicitacoes->contains($solicitacao)) {
  195.             $this->solicitacoes->removeElement($solicitacao);
  196.             // set the owning side to null (unless already changed)
  197.             if ($solicitacao->getDispositivo() === $this) {
  198.                 $solicitacao->setDispositivo(null);
  199.             }
  200.         }
  201.         return $this;
  202.     }
  203.     public function getStatus(): ?int
  204.     {
  205.         return $this->status;
  206.     }
  207.     public function setStatus(int $status): self
  208.     {
  209.         $this->status $status;
  210.         return $this;
  211.     }
  212.     
  213.     public function getBloqueio(): ?int
  214.     {
  215.         return $this->bloqueio;
  216.     }
  217.     public function setBloqueio(int $bloqueado): self
  218.     {
  219.         $this->bloqueio $bloqueado;
  220.         return $this;
  221.     }
  222.     
  223.     public function getUsuario(): ?Usuario
  224.     {
  225.         return $this->usuario;
  226.     }
  227.     public function setUsuario(?Usuario $usuario): UsuarioDependenteInterface
  228.     {
  229.         $this->usuario $usuario;
  230.         return $this;
  231.     }
  232.     public function getInformacaoComplementar(): ?string
  233.     {
  234.         return $this->informacaoComplementar;
  235.     }
  236.     public function setInformacaoComplementar(?string $informacaoComplementar): self
  237.     {
  238.         $this->informacaoComplementar $informacaoComplementar;
  239.         return $this;
  240.     }
  241.     public function getFirebaseIdentificador(): ?string
  242.     {
  243.         return $this->firebaseIdentificador;
  244.     }
  245.     public function setFirebaseIdentificador(?string $firebaseIdentificador): self
  246.     {
  247.         $this->firebaseIdentificador $firebaseIdentificador;
  248.         return $this;
  249.     }
  250.     public function getFirebaseToken(): ?string
  251.     {
  252.         return $this->firebaseToken;
  253.     }
  254.     public function setFirebaseToken(?string $firebaseToken): self
  255.     {
  256.         $this->firebaseToken $firebaseToken;
  257.         return $this;
  258.     }
  259.     
  260.     public function getSenha(): ?string
  261.     {
  262.         return $this->senha;
  263.     }
  264.     public function setSenha(?string $senha): self
  265.     {
  266.         $this->senha $senha;
  267.         return $this;
  268.     }
  269.     /**
  270.      * @return Collection|PackageDispositivo[]
  271.      */
  272.     public function getPackages(): Collection
  273.     {
  274.         return $this->packages;
  275.     }
  276.     public function addPackage(PackageDispositivo $package): self
  277.     {
  278.         if (!$this->packages->contains($package)) {
  279.             $this->packages[] = $package;
  280.             $package->setDispositivo($this);
  281.         }
  282.         return $this;
  283.     }
  284.     public function removePackage(PackageDispositivo $package): self
  285.     {
  286.         if ($this->packages->contains($package)) {
  287.             $this->packages->removeElement($package);
  288.             // set the owning side to null (unless already changed)
  289.             if ($package->getDispositivo() === $this) {
  290.                 $package->setDispositivo(null);
  291.             }
  292.         }
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return Collection|DispositivoHistoricoAcao[]
  297.      */
  298.     public function getDispositivoHistoricoAcoes(): Collection
  299.     {
  300.         return $this->historicoAcao;
  301.     }
  302.     public function addDispositivoHistoricoAcao(DispositivoHistoricoAcao $acao): self
  303.     {        
  304.         $this->historicoAcao[] = $acao;
  305.         $acao->setDispositivo($this);
  306.         return $this;
  307.     }
  308.     public function getUltimaMensagemBloqueio(): ?String
  309.     {
  310.         $criteria Criteria::create();
  311.         $criteria->where(Criteria::expr()->eq('bloqueio'Dispositivo::BLOQUEADO));
  312.         $criteria->orderBy(array('created_at' => Criteria::DESC));
  313.         $criteria->setMaxResults(1);
  314.         $result $this->historicoAcao->matching($criteria);
  315.              
  316.         if (!$result->isEmpty()) {
  317.             return $result[0]->getDescricao();
  318.         }
  319.         
  320.         return null;        
  321.     }
  322.     
  323.     public function getIdentificadorPropaganda(): ?string
  324.     {
  325.         return $this->identificador_propaganda;
  326.     }
  327.     public function setIdentificadorPropaganda(?string $identificador_propaganda): self
  328.     {
  329.         $this->identificador_propaganda $identificador_propaganda;
  330.         return $this;
  331.     }
  332. }