add users online
This commit is contained in:
parent
20c20b3eaf
commit
aa07c84fb0
|
@ -14,6 +14,7 @@ use App\Entity\Registry;
|
||||||
use App\Entity\Settings;
|
use App\Entity\Settings;
|
||||||
use App\Entity\StoreroomTicket;
|
use App\Entity\StoreroomTicket;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
|
use App\Entity\UserToken;
|
||||||
use App\Entity\WalletTransaction;
|
use App\Entity\WalletTransaction;
|
||||||
use App\Service\Extractor;
|
use App\Service\Extractor;
|
||||||
use App\Service\Jdate;
|
use App\Service\Jdate;
|
||||||
|
@ -581,6 +582,23 @@ class AdminController extends AbstractController
|
||||||
return $this->json($extractor->operationSuccess(array_reverse($temps)));
|
return $this->json($extractor->operationSuccess(array_reverse($temps)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/api/admin/onlineusers/list', name: 'api_admin_online_users_list')]
|
||||||
|
public function api_admin_online_users_list(Extractor $extractor,Jdate $jdate, EntityManagerInterface $entityManager): JsonResponse
|
||||||
|
{
|
||||||
|
$tokens = $entityManager->getRepository(UserToken::class)->getOnlines(120);
|
||||||
|
$res = [];
|
||||||
|
foreach($tokens as $token){
|
||||||
|
$res[] = [
|
||||||
|
'name' => $token->getUser()->getFullName(),
|
||||||
|
'email'=>$token->getUser()->getEmail(),
|
||||||
|
'mobile'=>$token->getUser()->getMobile(),
|
||||||
|
'lastActive'=>$token->getLastActive() - time(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $this->json($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -218,7 +218,7 @@ class BusinessController extends AbstractController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (array_key_exists('profitCalcType', $params)) {
|
if (array_key_exists('profitCalcType', $params)) {
|
||||||
if ($params['profitCalcType'] == 'lis' || $params['profitCalcType'] == 'avgis') {
|
if ($params['profitCalcType'] == 'lis' || $params['profitCalcType'] == 'avgis' || $params['profitCalcType'] == 'simple') {
|
||||||
$business->setProfitCalcType($params['profitCalcType']);
|
$business->setProfitCalcType($params['profitCalcType']);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Controller;
|
||||||
|
|
||||||
use App\Entity\Business;
|
use App\Entity\Business;
|
||||||
use App\Entity\Notification;
|
use App\Entity\Notification;
|
||||||
|
use App\Entity\UserToken;
|
||||||
use App\Service\Access;
|
use App\Service\Access;
|
||||||
use App\Service\Jdate;
|
use App\Service\Jdate;
|
||||||
use App\Service\Log;
|
use App\Service\Log;
|
||||||
|
@ -11,13 +12,14 @@ use App\Service\twigFunctions;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
class NotificationsController extends AbstractController
|
class NotificationsController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/api/notifications/list/{type}', name: 'api_notification_list')]
|
#[Route('/api/notifications/list/{type}', name: 'api_notification_list')]
|
||||||
public function api_notification_list(twigFunctions $twigFunctions,Access $access, Jdate $jdate, EntityManagerInterface $entityManager,String $type = 'all'): JsonResponse
|
public function api_notification_list(twigFunctions $twigFunctions,Access $access,Request $request, Jdate $jdate, EntityManagerInterface $entityManager,String $type = 'all'): JsonResponse
|
||||||
{
|
{
|
||||||
if(!$this->getUser())
|
if(!$this->getUser())
|
||||||
throw $this->createAccessDeniedException('lot loged in');
|
throw $this->createAccessDeniedException('lot loged in');
|
||||||
|
@ -62,6 +64,15 @@ class NotificationsController extends AbstractController
|
||||||
$temp['id'] = $item->getId();
|
$temp['id'] = $item->getId();
|
||||||
$temps[] = $temp;
|
$temps[] = $temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$userToken = $entityManager->getRepository(UserToken::class)->findOneBy([
|
||||||
|
'token'=> $request->headers->get('X-AUTH-TOKEN')
|
||||||
|
]);
|
||||||
|
if($userToken){
|
||||||
|
$userToken->setLastActive(time());
|
||||||
|
$entityManager->persist($userToken);
|
||||||
|
$entityManager->flush();
|
||||||
|
}
|
||||||
return $this->json($temps);
|
return $this->json($temps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ class UserToken
|
||||||
#[ORM\Column(length: 255, nullable: true)]
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
private ?string $tokenID = null;
|
private ?string $tokenID = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 40, nullable: true)]
|
||||||
|
private ?string $lastActive = null;
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
@ -63,4 +66,16 @@ class UserToken
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLastActive(): ?string
|
||||||
|
{
|
||||||
|
return $this->lastActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLastActive(?string $lastActive): static
|
||||||
|
{
|
||||||
|
$this->lastActive = $lastActive;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ class UserTokenRepository extends ServiceEntityRepository
|
||||||
/**
|
/**
|
||||||
* @throws NonUniqueResultException
|
* @throws NonUniqueResultException
|
||||||
*/
|
*/
|
||||||
public function findByApiToken($value): UserToken | null
|
public function findByApiToken($value): UserToken|null
|
||||||
{
|
{
|
||||||
return $this->createQueryBuilder('u')
|
return $this->createQueryBuilder('u')
|
||||||
->andWhere('u.token = :val')
|
->andWhere('u.token = :val')
|
||||||
|
@ -52,13 +52,13 @@ class UserTokenRepository extends ServiceEntityRepository
|
||||||
->setMaxResults(10)
|
->setMaxResults(10)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getOneOrNullResult()
|
->getOneOrNullResult()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws NonUniqueResultException
|
* @throws NonUniqueResultException
|
||||||
*/
|
*/
|
||||||
public function findByApiTokenID($value): UserToken | null
|
public function findByApiTokenID($value): UserToken|null
|
||||||
{
|
{
|
||||||
return $this->createQueryBuilder('u')
|
return $this->createQueryBuilder('u')
|
||||||
->andWhere('u.tokenID = :val')
|
->andWhere('u.tokenID = :val')
|
||||||
|
@ -67,13 +67,14 @@ class UserTokenRepository extends ServiceEntityRepository
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getOneOrNullResult();
|
->getOneOrNullResult();
|
||||||
}
|
}
|
||||||
// public function findOneBySomeField($value): ?UserToken
|
|
||||||
// {
|
public function getOnlines($maxTime = 120): ?array
|
||||||
// return $this->createQueryBuilder('u')
|
{
|
||||||
// ->andWhere('u.exampleField = :val')
|
return $this->createQueryBuilder('u')
|
||||||
// ->setParameter('val', $value)
|
->andWhere('u.lastActive > :maxTime')
|
||||||
// ->getQuery()
|
->setParameter('maxTime', time() - $maxTime)
|
||||||
// ->getOneOrNullResult()
|
->getQuery()
|
||||||
// ;
|
->getResult()
|
||||||
// }
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue