public function authorizations(LifecycleEventArgs $args) { $entity = $args->getEntity(); if (!$entity instanceof Authorization) { return; } $clientRepo = $args->getEntityManager()->getRepository('PROCERGSOAuthBundle:Client'); $counts = $clientRepo->getCountPerson($entity->getPerson(), $entity->getClient()->getId()); $count = $counts[0]['qty']; if (!is_int($count)) { $count = 0; } $statistics = new Statistics(); $statistics->setIndex('client.users')->setKey($entity->getClient()->getId())->setTimestamp(new \DateTime())->setValue($count); $args->getEntityManager()->persist($statistics); $args->getEntityManager()->flush($statistics); }
public function authorizationsAggregate(LifecycleEventArgs $args) { $entity = $args->getEntity(); if (!$entity instanceof Authorization) { return; } $em = $args->getEntityManager(); $key = $entity->getClient()->getId(); $date = \DateTime::createFromFormat('Y-m-d H:i:s', date('Y-m-d 00:00:00')); $clientRepo = $em->getRepository('LoginCidadaoOAuthBundle:Client'); $statsRepo = $em->getRepository('LoginCidadaoStatsBundle:Statistics'); $count = $this->getClientCount($clientRepo, $entity); $statistics = $statsRepo->findOneBy(array('timestamp' => $date, 'index' => 'agg.client.users', 'key' => $key)); if (!$statistics instanceof Statistics) { $statistics = new Statistics(); $statistics->setIndex('agg.client.users')->setKey($key)->setTimestamp($date); $em->persist($statistics); } $statistics->setValue($count); $em->flush($statistics); }