increaseViews example

$getAffectedBanners['categoryID'] = $getAffectedBanners['categoryId'];

            $getAffectedBanners['img'] = $getAffectedBanners['image'];

            $media = $this->getMediaByPath($medias$getAffectedBanners['image']);
            if ($media !== null) {
                $media = $this->legacyStructConverter->convertMediaStruct($media);
                $getAffectedBanners['media'] = $media;
            }

            $bannerStatistics = $this->modelManager->getRepository(TrackingBanner::class)->getOrCreateBannerStatsModel($getAffectedBanners['id']);
            $bannerStatistics->increaseViews();
            $this->modelManager->persist($bannerStatistics);
            $this->modelManager->flush($bannerStatistics);

            if (!empty($getAffectedBanners['link'])) {
                $query = [
                    'module' => 'frontend',
                    'controller' => 'tracking',
                    'action' => 'countBannerClick',
                    'bannerId' => $getAffectedBanners['id'],
                ];
                $getAffectedBanners['link'] = $this->front->ensureRouter()->assemble($query);
            }

    public function countBannerViewAction()
    {
        $bannerId = $this->Request()->getParam('bannerId');
        if ($bannerId === null) {
            return false;
        }

        try {
            $statRepository = $this->get('models')->getRepository(TrackingBanner::class);
            $bannerStatistics = $statRepository->getOrCreateBannerStatsModel($bannerId);
            $bannerStatistics->increaseViews();
            $this->get('models')->flush($bannerStatistics);
        } catch (Exception $e) {
            return false;
        }

        return true;
    }
}
Home | Imprint | This part of the site doesn't use cookies.