custom/plugins/AppflixCustomerMarket/src/Core/Service/CountVisitorService.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Appflix\CustomerMarket\Core\Service;
  3. use Appflix\CustomerMarket\Core\Defaults;
  4. use Shopware\Core\Framework\Uuid\Uuid;
  5. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  6. use Symfony\Component\HttpFoundation\Session\Session;
  7. use Doctrine\DBAL\Connection;
  8. class CountVisitorService
  9. {
  10.     private Connection $connection;
  11.     private Session $session;
  12.     public function __construct(
  13.         Connection $connection,
  14.         Session $session
  15.     )
  16.     {
  17.         $this->connection $connection;
  18.         $this->session $session;
  19.     }
  20.     public function update(string $appflixAdId): void
  21.     {
  22.         $visitedAdIds $this->session->get(Defaults::VISITED_AD_IDS, []);
  23.         if (in_array($appflixAdId$visitedAdIds)) {
  24.             return;
  25.         }
  26.         $visitedAdIds[] = $appflixAdId;
  27.         $this->session->set(Defaults::VISITED_AD_IDS$visitedAdIds);
  28.         $sql = <<<SQL
  29. UPDATE `appflix_ad` 
  30. SET `visitors` = `visitors` + 1
  31. WHERE `id` = :id;
  32. SQL;
  33.         $this->connection->executeUpdate($sql, ['id' => Uuid::fromHexToBytes($appflixAdId)]);
  34.     }
  35. }