/** * @inheritdoc * * @return Impressions */ public function findImpressionsByCampaign(TrackableCampaignInterface $campaign) { $data = $this->getData($campaign->getTrackingId()); if (empty($data)) { return null; } return new Impressions($campaign, $this->getImpressionsForToday($data), $this->getTotalImpressions($data)); }
/** * @param TrackableCampaignInterface $campaign * @param Impressions $impressions * * @return string */ private function getVisibilityText(TrackableCampaignInterface $campaign, Impressions $impressions) { if ($this->impressionsOperator->areImpressionsEnabled()) { if ($impressions->canBeIncreasedToday()) { $text = 'Popup is showed in normal mode. This is impression ' . ($impressions->getForToday() + 1) . ' out of ' . $campaign->getMaxImpressionPerDay() . ' for today'; } else { $text = 'Popup is not showed in normal mode. The ' . $campaign->getMaxImpressionPerDay() . ' impressions for today were exhausted.'; } } else { $text = 'Popup is not showed in normal mode. All impressions were disabled.'; } ob_start(); require_once __DIR__ . '/../templates/debug.php'; $content = ob_get_clean(); return $content; }
/** * Returns the Javascript code which deals with the showing of the popup. * * We show a fancybox, which gets its content from the specified URL via AJAX, after a specified timeout. * * @param TrackableCampaignInterface $campaign * @param $timeout The timeout after which the popup should appear in seconds. * * @return string */ public function getScript(TrackableCampaignInterface $campaign, $timeout) { $js = sprintf(' (function () { var %s = "%s"; var url = "%s"; var tout = %s; $(document).ready(function () { setTimeout(function() { if (!$.fancybox.isOpen) { $.fancybox.open({ type: "ajax", ajax: { data: "%1$s=" + %1$s }, href: url, }); } }, tout); }) }());', DataResolver::CAMPAIGN_ID_KEY, $campaign->getTrackingId(), $this->url, $timeout * 1000); return sprintf("<script>%s</script>", $js); }
/** * Returns how many overall impressions the user still has for the campaign. * * @return int */ private function getRemainingTotal() { return $this->campaign->getMaxImpressions() - $this->getTotal(); }