public function process(Pap_Contexts_Tracking $context) { $banner = $context->getBannerObject(); $rawClick = $this->createRawClick($context, $banner); if($context->getDoTrackerSave() && $rawClick != null) { $this->saveRawClick($rawClick); $this->saveClick($context, new Pap_Db_Click(), $banner, $rawClick); } $context->debug(''); }
/** * @return Pap_Common_Banner */ public function recognizeBanners(Pap_Contexts_Tracking $context) { if ($context->getBannerObject() != null) { $context->debug('Banner oject was set before banner recognizing.'); return $context->getBannerObject(); } try { $banner = $this->getBannerById($context, $context->getBannerIdFromRequest()); $context->debug('Banner is recognized from request parameter.'); return $banner; } catch (Exception $e) { } try { $banner = $this->getBannerById($context, $context->getVisitorAffiliate()->getBannerId()); $context->debug('Banner is recognized from VisitorAffiliate.'); return $banner; } catch (Exception $e) { $context->debug('Banner not recognized'); return; } }
public function saveCommission(Pap_Contexts_Tracking $context, Pap_Common_User $user, Pap_Tracking_Common_Commission $commission) { $context->debug('Saving '.$context->getActionType().' commission started'); $transaction = $context->getTransaction($commission->getTier()); if ($transaction == null) { $transaction = clone $context->getTransaction(1); $transaction->setPersistent(false); $transaction->generateNewTransactionId(); } if (($parentTransaction = $context->getTransaction($commission->getTier() - 1)) != null) { $transaction->setParentTransactionId($parentTransaction->getId()); } if (($channel = $context->getChannelObject()) != null) { $transaction->setChannel($channel->getId()); } $transaction->setTier($commission->getTier()); $transaction->setUserId($user->getId()); $transaction->setCampaignId($context->getCampaignObject()->getId()); $transaction->setAccountId($context->getAccountId()); $banner = $context->getBannerObject(); if (!is_null($banner)) { $transaction->setBannerId($banner->getId()); } if ($user->getStatus() == 'P') { $transaction->setStatus('P'); $context->debug('Commission is saved as pending because user state is in pending'); } else { $transaction->setStatus($commission->getStatus()); } $transaction->setPayoutStatus(Pap_Common_Transaction::PAYOUT_UNPAID); $transaction->setCommissionTypeId($context->getCommissionTypeObject()->getId()); $transaction->setCountryCode(($context->getVisit()!=null)?$context->getVisit()->getCountryCode():''); $transaction->setType($context->getCommissionTypeObject()->getType()); $transaction->setCommission($commission->getCommission($context->getRealTotalCost()-$context->getFixedCost())); $context->debug(' Computed commission is: '.$transaction->getCommission()); $transaction->setClickCount(1); $transaction->setLogGroupId($context->getLoggerGroupId()); if ($transaction->getTier() == 1) { $transaction->setSaleId($transaction->getId()); } else { $transaction->setSaleId($context->getTransaction(1)->getSaleId()); } //check if we can save zero commission if ($transaction->getCommission() == 0 && $context->getCommissionTypeObject()->getSaveZeroCommissions() != Gpf::YES) { $context->debug(' Saving of commission transaction was STOPPED. Saving of zero commissions is disabled. Trans id: '.$transaction->getId()); return Gpf_Plugins_Engine::PROCESS_CONTINUE; } $transactionCompoundContext = new Pap_Common_TransactionCompoundContext($transaction, $context); Gpf_Plugins_Engine::extensionPoint('Tracker.saveCommissions.beforeSaveTransaction', $transactionCompoundContext); if (!$transactionCompoundContext->getSaveTransaction()) { $context->debug(' Saving of commission transaction was STOPPED by plugin. Trans id: '.$transaction->getId()); return Gpf_Plugins_Engine::PROCESS_CONTINUE; } $this->saveTransaction($transaction, $context->getVisitDateTime()); $context->setTransactionObject($transaction, $commission->getTier()); $context->debug(' Commission transaction was successfully saved with ID: '.$transaction->getId()); $context->debug('Saving '.$context->getActionType().' commission ended'); $context->debug(''); return Gpf_Plugins_Engine::PROCESS_CONTINUE; }
/** * if banner was recognized, get campaign from this banner * * @param Pap_Plugins_Tracking_Click_Context $context * @return unknown */ protected function recognizeCampaignFromBanner(Pap_Contexts_Tracking $context) { $banner = $context->getBannerObject(); if($banner == null) { $this->logAndThrow($context, 'Banner is null, cannot recognize campaign'); } $context->debug('Banner recognized, Banner Id: '.$banner->getId().', getting campaign for this banner, campaignId: '. $banner->getCampaignId()); return $this->getCampaignById($context, $banner->getCampaignId()); }
public static function prepareVisitorAffiliate(Pap_Db_VisitorAffiliate $visitorAffiliate, Pap_Contexts_Tracking $context) { $visitorAffiliate->setUserId($context->getUserObject()->getId()); if ($context->getBannerObject() != null) { $visitorAffiliate->setBannerId($context->getBannerObject()->getId()); } else { $visitorAffiliate->setBannerId(null); } if ($context->getChannelObject() != null) { $visitorAffiliate->setChannelId($context->getChannelObject()->getId()); } $visitorAffiliate->setCampaignId($context->getCampaignObject()->getId()); $visitorAffiliate->setIp($context->getIp()); $visitorAffiliate->setDateVisit($context->getDateCreated()); $visitorAffiliate->setReferrerUrl($context->getReferrerUrl()); $visitorAffiliate->setData1($context->getExtraDataFromRequest(1)); $visitorAffiliate->setData2($context->getExtraDataFromRequest(2)); $visitorAffiliate->setValidTo(self::getVisitorAffiliateValidity($context, $visitorAffiliate)); }