|
|
|
|
|
|
|
|
protected EntityManagerInterface $entityManager; |
|
|
protected EntityManagerInterface $entityManager; |
|
|
|
|
|
|
|
|
public function __construct( |
|
|
public function __construct( |
|
|
EntityManagerInterface $entityManager, |
|
|
|
|
|
CookieComponent $cookieComponent, |
|
|
|
|
|
ParameterBagInterface $parameterBag |
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
EntityManagerInterface $entityManager, |
|
|
|
|
|
CookieComponent $cookieComponent, |
|
|
|
|
|
ParameterBagInterface $parameterBag |
|
|
|
|
|
) |
|
|
|
|
|
{ |
|
|
$this->entityManager = $entityManager; |
|
|
$this->entityManager = $entityManager; |
|
|
$this->cookieComponent = $cookieComponent; |
|
|
$this->cookieComponent = $cookieComponent; |
|
|
$this->parameterBag = $parameterBag; |
|
|
$this->parameterBag = $parameterBag; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// addVisitor |
|
|
// addVisitor |
|
|
public function create(string $cookie, string $ip) |
|
|
|
|
|
|
|
|
public function create(string $cookieValue, string $ip) |
|
|
{ |
|
|
{ |
|
|
$visitorFactory = new VisitorFactory(); |
|
|
$visitorFactory = new VisitorFactory(); |
|
|
$visitor = $visitorFactory->create($cookie, $ip); |
|
|
|
|
|
|
|
|
$visitor = $visitorFactory->create($cookieValue, $ip); |
|
|
|
|
|
|
|
|
$this->entityManager->create($visitor); |
|
|
$this->entityManager->create($visitor); |
|
|
$this->entityManager->flush(); |
|
|
$this->entityManager->flush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function update(VisitorInterface $visitor) |
|
|
public function update(VisitorInterface $visitor) |
|
|
{ |
|
|
{ |
|
|
$totalVisit = $visitor->getTotalVisit() + 1; |
|
|
|
|
|
|
|
|
if($visitor->getLastAccess() < new \DateTime('-1 hour')) { |
|
|
|
|
|
$totalVisit = $visitor->getTotalVisit() + 1; |
|
|
|
|
|
$visitor->setTotalVisit($totalVisit); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$visitor->setTotalVisit($totalVisit); |
|
|
|
|
|
$visitor->setLastAccess(new \DateTime()); |
|
|
$visitor->setLastAccess(new \DateTime()); |
|
|
|
|
|
|
|
|
$this->entityManager->update($visitor); |
|
|
$this->entityManager->update($visitor); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// setCookieVisitor |
|
|
// setCookieVisitor |
|
|
public function setCookie($response, $cookie): void |
|
|
|
|
|
|
|
|
public function setCookie($response, $cookieValue): Cookie |
|
|
{ |
|
|
{ |
|
|
$response->headers->setCookie( |
|
|
|
|
|
Cookie::create( |
|
|
|
|
|
$this->parameterBag->get('app.cookie_name_visitor'), |
|
|
|
|
|
$this->cookieComponent->cryptCookie($cookie), |
|
|
|
|
|
new \DateTime('+2 months'), |
|
|
|
|
|
'/', |
|
|
|
|
|
$this->cookieComponent->getCookieDomain() |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
$cookie = Cookie::create( |
|
|
|
|
|
$this->parameterBag->get('app.cookie_name_visitor'), |
|
|
|
|
|
$this->cookieComponent->cryptCookie($cookieValue), |
|
|
|
|
|
new \DateTime('+2 months'), |
|
|
|
|
|
'/', |
|
|
|
|
|
$this->cookieComponent->getCookieDomain() |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
$response->headers->setCookie($cookie); |
|
|
|
|
|
|
|
|
|
|
|
return $cookie; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// updateVisitorCookie |
|
|
// updateVisitorCookie |
|
|
public function updateCookie($response): void |
|
|
public function updateCookie($response): void |
|
|
{ |
|
|
{ |
|
|
$response->headers->setCookie( |
|
|
$response->headers->setCookie( |
|
|
Cookie::create( |
|
|
|
|
|
$this->parameterBag->get('app.cookie_name_visitor'), |
|
|
|
|
|
$this->cookieComponent->cryptCookie($this->getVisitorCurrent()->getCookie()), |
|
|
|
|
|
new \DateTime('+2 months'), |
|
|
|
|
|
'/', |
|
|
|
|
|
$this->cookieComponent->getCookieDomain() |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
Cookie::create( |
|
|
|
|
|
$this->parameterBag->get('app.cookie_name_visitor'), |
|
|
|
|
|
$this->cookieComponent->cryptCookie($this->getVisitorCurrent()->getCookie()), |
|
|
|
|
|
new \DateTime('+2 months'), |
|
|
|
|
|
'/', |
|
|
|
|
|
$this->cookieComponent->getCookieDomain() |
|
|
|
|
|
) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|