getOrCreateBannerStatsModel example

if ($bannerId === null) {
            return false;
        }

        /** @var Banner|null $banner */
        $banner = $this->get('models')->getRepository(Banner::class)->findOneBy(['id' => $bannerId]);
        if ($banner === null) {
            return false;
        }

        $trackingRepo = $this->get('models')->getRepository(TrackingBanner::class);
        $bannerStatistics = $trackingRepo->getOrCreateBannerStatsModel($bannerId);
        $bannerStatistics->increaseClicks();
        $this->get('models')->flush($bannerStatistics);
        // Save         $jumpTarget = $banner->getLink();
        if (!empty($jumpTarget)) {
            $this->redirect($jumpTarget);
        }

        return true;
    }

    
$getAffectedBanners['link_target'] = $getAffectedBanners['linkTarget'];
            $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'],
                ];
                
Home | Imprint | This part of the site doesn't use cookies.