Commit 1c3f244a1c7b8a1da128c610043568341df64296
Exists in
master
Merge branch 'master' into 3.1
Showing
4 changed files
with
204 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,119 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Cacic\CommonBundle\Entity; | |
| 4 | + | |
| 5 | +use Doctrine\ORM\Mapping as ORM; | |
| 6 | +use Symfony\Component\Validator\Constraints\DateTime; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * LogAcesso | |
| 10 | + */ | |
| 11 | +class LogUserLogado | |
| 12 | +{ | |
| 13 | + /** | |
| 14 | + * @var integer | |
| 15 | + */ | |
| 16 | + private $idLogUserLogado; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * @var \DateTime | |
| 20 | + */ | |
| 21 | + private $data; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * @var \Cacic\CommonBundle\Entity\Computador | |
| 25 | + */ | |
| 26 | + private $idComputador; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Get idLogUserLogado | |
| 30 | + * | |
| 31 | + * @return integer | |
| 32 | + */ | |
| 33 | + public function getIdLogUserLogado() | |
| 34 | + { | |
| 35 | + return $this->idLogUserLogado; | |
| 36 | + } | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Set data | |
| 40 | + * | |
| 41 | + * @param \DateTime $data | |
| 42 | + * @return LogUserLogado | |
| 43 | + */ | |
| 44 | + public function setData($data) | |
| 45 | + { | |
| 46 | + $this->data = $data; | |
| 47 | + | |
| 48 | + return $this; | |
| 49 | + } | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Get data | |
| 53 | + * | |
| 54 | + * @return \DateTime | |
| 55 | + */ | |
| 56 | + public function getData() | |
| 57 | + { | |
| 58 | + return $this->data; | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Set idComputador | |
| 63 | + * | |
| 64 | + * @param \Cacic\CommonBundle\Entity\Computador $idComputador | |
| 65 | + * @return LogUserLogado | |
| 66 | + */ | |
| 67 | + public function setIdComputador(\Cacic\CommonBundle\Entity\Computador $idComputador = null) | |
| 68 | + { | |
| 69 | + $this->idComputador = $idComputador; | |
| 70 | + | |
| 71 | + return $this; | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Get idComputador | |
| 76 | + * | |
| 77 | + * @return \Cacic\CommonBundle\Entity\Computador | |
| 78 | + */ | |
| 79 | + public function getIdComputador() | |
| 80 | + { | |
| 81 | + return $this->idComputador; | |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * @PrePersist | |
| 86 | + */ | |
| 87 | + public function onPrePersistSetRegistrationDate() | |
| 88 | + { | |
| 89 | + $this->data = new \DateTime(); | |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * @var string | |
| 94 | + */ | |
| 95 | + private $usuario; | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * Set usuario | |
| 99 | + * | |
| 100 | + * @param string $usuario | |
| 101 | + * @return LogUserLogado | |
| 102 | + */ | |
| 103 | + public function setUsuario($usuario) | |
| 104 | + { | |
| 105 | + $this->usuario = $usuario; | |
| 106 | + | |
| 107 | + return $this; | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * Get usuario | |
| 112 | + * | |
| 113 | + * @return string | |
| 114 | + */ | |
| 115 | + public function getUsuario() | |
| 116 | + { | |
| 117 | + return $this->usuario; | |
| 118 | + } | |
| 119 | +} | |
| 0 | 120 | \ No newline at end of file | ... | ... |
src/Cacic/CommonBundle/Entity/LogUserLogadoRepository.php
0 → 100644
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace Cacic\CommonBundle\Entity; | |
| 4 | + | |
| 5 | +use Doctrine\ORM\EntityRepository; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * LogAcessoRepository | |
| 9 | + * | |
| 10 | + * Métodos de repositório | |
| 11 | + */ | |
| 12 | +class LogUserLogadoRepository extends EntityRepository | |
| 13 | +{ | |
| 14 | + /** | |
| 15 | + * Função que retorna o último acesso para o computador solicitado | |
| 16 | + * | |
| 17 | + * @param $computador | |
| 18 | + */ | |
| 19 | + public function ultimoAcesso( $computador ) { | |
| 20 | + $qb = $this->createQueryBuilder('acesso') | |
| 21 | + ->select('acesso') | |
| 22 | + ->where('acesso.idComputador = :computador') | |
| 23 | + ->orderBy('acesso.data', 'desc') | |
| 24 | + ->setMaxResults(1) | |
| 25 | + ->setParameter('computador', $computador ); | |
| 26 | + | |
| 27 | + return $qb->getQuery()->getOneOrNullResult(); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | ... | ... |
src/Cacic/CommonBundle/Resources/config/doctrine/LogUserLogado.orm.yml
0 → 100644
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +Cacic\CommonBundle\Entity\LogUserLogado: | |
| 2 | + type: entity | |
| 3 | + table: log_user_logado | |
| 4 | + repositoryClass: Cacic\CommonBundle\Entity\LogUserLogadoRepository | |
| 5 | + fields: | |
| 6 | + idLogUserLogado: | |
| 7 | + id: true | |
| 8 | + type: integer | |
| 9 | + unsigned: false | |
| 10 | + nullable: false | |
| 11 | + column: id_log_user_logado | |
| 12 | + generator: | |
| 13 | + strategy: IDENTITY | |
| 14 | + data: | |
| 15 | + type: datetime | |
| 16 | + nullable: false | |
| 17 | + column: data | |
| 18 | + usuario: | |
| 19 | + type: text | |
| 20 | + nullable: true | |
| 21 | + manyToOne: | |
| 22 | + idComputador: | |
| 23 | + targetEntity: Computador | |
| 24 | + cascade: { } | |
| 25 | + mappedBy: null | |
| 26 | + inversedBy: null | |
| 27 | + joinColumns: | |
| 28 | + id_computador: | |
| 29 | + referencedColumnName: id_computador | |
| 30 | + orphanRemoval: false | |
| 0 | 31 | \ No newline at end of file | ... | ... |
src/Cacic/WSBundle/Controller/DefaultController.php
| ... | ... | @@ -7,6 +7,7 @@ use Cacic\CommonBundle\Entity\Computador; |
| 7 | 7 | use Cacic\CommonBundle\Entity\ComputadorColeta; |
| 8 | 8 | use Cacic\CommonBundle\Entity\ConfiguracaoLocal; |
| 9 | 9 | use Cacic\CommonBundle\Entity\ConfiguracaoPadrao; |
| 10 | +use Cacic\CommonBundle\Entity\LogUserLogado; | |
| 10 | 11 | use Cacic\CommonBundle\Entity\Rede; |
| 11 | 12 | use Cacic\CommonBundle\Entity\RedeGrupoFtp; |
| 12 | 13 | use Doctrine\Common\Util\Debug; |
| ... | ... | @@ -144,6 +145,8 @@ class DefaultController extends Controller |
| 144 | 145 | $hoje = $data_acesso->format('Y-m-d'); |
| 145 | 146 | |
| 146 | 147 | $ultimo_acesso = $this->getDoctrine()->getRepository('CacicCommonBundle:LogAcesso')->ultimoAcesso( $computador->getIdComputador() ); |
| 148 | + $ultimo_user_logado = $this->getDoctrine()->getRepository('CacicCommonBundle:LogUserLogado')->ultimoAcesso( $computador->getIdComputador() ); | |
| 149 | + | |
| 147 | 150 | if (empty($ultimo_acesso)) { |
| 148 | 151 | // Se for o primeiro registro grava o acesso do computador |
| 149 | 152 | $logger->debug("Último acesso não encontrado. Registrando acesso para o computador $computador em $hoje"); |
| ... | ... | @@ -153,10 +156,19 @@ class DefaultController extends Controller |
| 153 | 156 | $log_acesso->setData($data_acesso); |
| 154 | 157 | |
| 155 | 158 | /* |
| 159 | + * Grava os registros na Tabela Log_User_Logado | |
| 160 | + */ | |
| 161 | + $ultimo_user_logado = new LogUserLogado(); | |
| 162 | + $ultimo_user_logado->setIdComputador($computador); | |
| 163 | + $ultimo_user_logado->setData($data_acesso); | |
| 164 | + | |
| 165 | + /* | |
| 156 | 166 | * Grava o último usuário logado no banco apenas se não estiver vazio |
| 157 | 167 | */ |
| 158 | 168 | if (!empty($ultimo_login)) |
| 159 | 169 | $log_acesso->setUsuario($ultimo_login); |
| 170 | + $ultimo_user_logado->setUsuario($ultimo_login); | |
| 171 | + | |
| 160 | 172 | |
| 161 | 173 | // Grava o log |
| 162 | 174 | $this->getDoctrine()->getManager()->persist($log_acesso); |
| ... | ... | @@ -173,14 +185,27 @@ class DefaultController extends Controller |
| 173 | 185 | $log_acesso->setData($data_acesso); |
| 174 | 186 | |
| 175 | 187 | /* |
| 188 | + * Grava os registros na Tabela Log_User_Logado | |
| 189 | + */ | |
| 190 | + $ultimo_user_logado = new LogUserLogado(); | |
| 191 | + $ultimo_user_logado->setIdComputador($computador); | |
| 192 | + $ultimo_user_logado->setData($data_acesso); | |
| 193 | + | |
| 194 | + /* | |
| 176 | 195 | * Grava o último usuário logado no banco apenas se não estiver vazio |
| 177 | 196 | */ |
| 178 | 197 | if (!empty($ultimo_login)) |
| 179 | 198 | $log_acesso->setUsuario($ultimo_login); |
| 199 | + $ultimo_user_logado->setUsuario($ultimo_login); | |
| 200 | + | |
| 180 | 201 | |
| 181 | 202 | // Grava o log |
| 182 | 203 | $this->getDoctrine()->getManager()->persist($log_acesso); |
| 183 | 204 | $this->getDoctrine()->getManager()->flush(); |
| 205 | + | |
| 206 | + // Grava em log_user_logado | |
| 207 | + $this->getDoctrine()->getManager()->persist($ultimo_user_logado); | |
| 208 | + $this->getDoctrine()->getManager()->flush(); | |
| 184 | 209 | } |
| 185 | 210 | } |
| 186 | 211 | ... | ... |