<?php
namespace Harmonizely\Service\SuperAdmin\EventListener;
use Harmonizely\Core\Security\Contract\ISuperAdminSecurityHelper ;
use Harmonizely\Entity\SuperAdmin\UserEntity;
use Harmonizely\Repository\SuperAdmin\Contract\IUserRepository;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class UserActivityListener
{
/**
* @var ISuperAdminSecurityHelper
*/
private ISuperAdminSecurityHelper $security;
/**
* @var IUserRepository
*/
private IUserRepository $repository;
/**
* UserActivityListener constructor.
*
* @param ISuperAdminSecurityHelper $security
* @param IUserRepository $repository
*/
public function __construct(ISuperAdminSecurityHelper $security, IUserRepository $repository)
{
$this->security = $security;
$this->repository = $repository;
}
/**
* @param RequestEvent $event
*/
public function onRequest(RequestEvent $event): void
{
$user = $this->security->getUser();
if ($user instanceof UserEntity) {
if ($user->updateLastAccessTime()) {
$this->repository->save($user);
}
}
}
}