/** * returns commission group for user (if not set already) * Commission group can be set previously in the checkCampaignType() function * */ protected function getCommissionGroup(Pap_Contexts_Tracking $context) { $context->debug('Recognizing commission group started'); if (($user = $context->getUserObject()) == null) { $context->debug('STOPPING, user is not set - cannot find commission group'); return; } $commGroupId = $this->getUserCommissionGroupFromCache($context->getCampaignObject(), $user->getId()); if($commGroupId == false) { $context->debug("STOPPING, Cannot find commission group for this affiliate and campaign! ".$context->getCampaignObject()->getId().' - '.$user->getId()); $context->setDoCommissionsSave(false); $context->setDoTrackerSave(false); return; } Gpf_Plugins_Engine::extensionPoint('PostAffiliate.RecognizeCommGroup.getCommissionGroup', $context); $commissionGroup = $this->getCommissionGroupFromCache($commGroupId); if ($commissionGroup == null) { $context->debug(' Commission group with ID '.$commGroupId . ' does not exist'); return; } $context->setCommissionGroup($commissionGroup); $context->debug('Received commission group ID = '.$commGroupId); }
public function recognize(Pap_Contexts_Tracking $context) { if(($context->getUserObject()) != null) { $context->debug(' User already recognized, finishing user recognizer'); return; } parent::recognize($context); }
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(''); }
private function sumOfCommissions(Pap_Contexts_Tracking $context, $tier) { $sumCommissions = 0; for ($count=$tier - 1; $count>=1; $count--) { $commission = $context->getTransaction($count); if ($commission != null) { $sumCommissions += $commission->getCommission(); } } return $sumCommissions; }
public function recognize(Pap_Contexts_Tracking $context) { $fpStatus = $context->getFraudProtectionStatus(); if($fpStatus != null && $fpStatus != '') { $context->debug(" Using status '".$fpStatus."' set by fraud protection"); $context->setStatusForAllCommissions($fpStatus); return; } if($this->getCustomStatus($context)) { return; } }
private function recognizeAccountId(Pap_Contexts_Tracking $context) { if (!$this->accountValid($context->getVisit()->getAccountId())) { $context->debug('Account from visit with accountId='.$context->getVisit()->getAccountId() . ' is not valid! For now, set default account: '.$context->getAccountId()); return; } $context->debug('Set AccountId: '.$context->getVisit()->getAccountId()); $context->setAccountId($context->getVisit()->getAccountId(), Pap_Contexts_Tracking::ACCOUNT_RECOGNIZED_FROM_FORCED_PARAMETER); }
public function recognize(Pap_Contexts_Tracking $context) { $context->debug('Recognizing affiliate started'); $user = $this->getUser($context); if($user == null) { $context->debug(' Error, no affiliate recognized! setDoSaveCommissions(false)'); $context->setDoTrackerSave(false); $context->setDoCommissionsSave(false); return; } $context->setUserObject($user); $context->debug('Recognizing affiliate ended. Recognized affiliate id: '.$user->getId()); $context->debug(""); }
public function process(Pap_Contexts_Tracking $context) { $context->debug(' Preparing commissions for the click started'); $context->setDoCommissionsSave($this->isValidCommission($context)); if (!$context->getDoCommissionsSave()) { return; } $this->recognizeCommissions($context); if($context->getDoCommissionsSave() && $context->getDoTrackerSave() && $context->getClickStatus() != Pap_Db_ClickImpression::STATUS_DECLINED) { $this->saveCommissions($context); } $context->debug(' Preparing commissions for the click ended'); $context->debug(''); }
protected function getUser(Pap_Contexts_Tracking $context) { if ($context->getUserObject() != null) { return $context->getUserObject(); } if (($user = $this->getUserFromParameter($context)) != null) { return $user; } if (($user = $this->getUserFromVisitorAffiliate($context)) != null) { return $user; } if (($user = $this->getDefaultAffiliate($context)) != null) { return $user; } return null; }
public function recognize(Pap_Contexts_Tracking $context) { if ($context->isVisitorAffiliateRecognized()) { return; } Pap_Tracking_Common_VisitorAffiliateCheckCompatibility::getHandlerInstance()->checkCompatibility($context->getVisitorId(), $this->visitorAffiliateCache); $context->debug('Getting VisitorAffiliate for visitorId = ' . $context->getVisitorId()); if (($visitorAffiliate = $this->visitorAffiliateCache->getActualVisitorAffiliate($context->getVisitorId())) == null) { $context->debug('Recognize VisitorAffiliate not recognized from actual'); return; } $context->debug('Recognize VisitorAffiliate recognized from actual, id: '.$visitorAffiliate->getId(). ', accountId: '. $visitorAffiliate->getAccountId()); $context->setVisitorAffiliate($visitorAffiliate); }
private function findBestMatchingCampaignId(Gpf_Data_RecordSet $matchingCampaigns, $productId, Pap_Contexts_Tracking $context) { foreach ($matchingCampaigns as $campaign) { $campaignProductIds = explode(',', $campaign->get(Pap_Db_Table_Campaigns::PRODUCT_ID)); if (in_array($productId, array_values($campaignProductIds))) { $campaignObject = $this->getCampaign($campaign->get(Pap_Db_Table_Campaigns::ID)); $status = $campaignObject->getCampaignStatus(); if($status == Pap_Db_Campaign::CAMPAIGN_STATUS_STOPPED || $status == Pap_Db_Campaign::CAMPAIGN_STATUS_STOPPED_INVISIBLE) { continue; } if ($campaignObject->getCampaignType() == Pap_Db_Campaign::CAMPAIGN_TYPE_PUBLIC) { return $campaign->get(Pap_Db_Table_Campaigns::ID); } if ($context->getUserObject() != null && $campaignObject->checkUserIsInCampaign($context->getUserObject()->getId())) { return $campaign->get(Pap_Db_Table_Campaigns::ID); } } } throw new Gpf_Exception('No campaign matching product ID: '.$productId); }
/** * @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; } }
/** * @return Pap_Common_Banner */ protected function recognizeCampaigns(Pap_Contexts_Tracking $context) { if ($context->getCampaignObject() != null) { return $context->getCampaignObject(); } try { return $this->getCampaignFromForcedBanner($context); } catch (Gpf_Exception $e) { } try { return $this->getCampaignFromParameter($context); } catch (Gpf_Exception $e) { } try { return $this->getCampaignFromProductID($context); } catch (Gpf_Exception $e) { if (Gpf_Settings::get(Pap_Settings::FORCE_CHOOSING_PRODUCTID_SETTING_NAME) == Gpf::YES) { $context->setDoCommissionsSave(false); return; } } try { $visitorAffiliate = $context->getVisitorAffiliate(); if ($visitorAffiliate != null) { $context->debug('Getting campaign from visitor affiliate, visitorId: '.$visitorAffiliate->getVisitorId()); $context->debug('Checking campaign with Id: '.$visitorAffiliate->getCampaignId()); return $this->getCampaignById($context, $visitorAffiliate->getCampaignId()); } } catch (Gpf_Exception $e) { } try { return $this->getDefaultCampaign($context); } catch (Gpf_Exception $e) { } }
private function getTransaction(Pap_Contexts_Tracking $context) { $userTree = new Pap_Common_UserTree(); $tier = 1; $currentUser = $context->getUserObject(); $currentTransaction = $context->getTransaction($tier); while ($currentUser != null && $tier < 100) { if ($currentTransaction != null) { $transactionId = $currentTransaction->getTransactionId(); if ($transactionId != null && $transactionId != '') { return $currentTransaction; } } $tier++; $currentUser = $userTree->getParent($currentUser); $currentTransaction = $context->getTransaction($tier); } return $context->getTransaction(); }
/** * @return Gpf_DbEngine_Row_Collection */ private function getTierCommissionCollection(Pap_Contexts_Tracking $context, $userId, $tier) { $context->debug('Loading tier commission collection for userid: ' . $userId . ' and tier: ' . $tier); $commissionTypeId = $context->getCommissionTypeObject()->getId(); $groupId = $this->getCommissionGroupForUser($context->getCampaignObject(), $userId); $hash = $commissionTypeId.$groupId.$tier; if (isset($this->commissions[$hash])) { $context->debug('Record found in cache.'); return $this->commissions[$hash]; } $context->debug('Trying to load commission for typeid:' . $commissionTypeId . ', groupId:' . $groupId . ',tier:' . $tier); $commission = new Pap_Db_Commission(); $commission->setCommissionTypeId($commissionTypeId); $commission->setGroupId($groupId); $commission->setTier($tier); try { $commissions = $this->loadCommissionCollectionFromData($commission); } catch (Gpf_DbEngine_NoRowException $e) { $context->debug('Error loading collection from data. returning empty collection.'); return new Gpf_DbEngine_Row_Collection(); } $context->debug('Commissions succ. loaded, saving to cache.'); $this->commissions[$hash] = $commissions; return $this->commissions[$hash]; }
/** * @param $message * @throws Pap_Tracking_Exception */ protected function logAndThrow(Pap_Contexts_Tracking $context, $message) { $context->debug($message); throw new Pap_Tracking_Exception($message); }
/** * 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()); }
protected function setParentBannerNotExistsDebug(Pap_Contexts_Tracking $context) { $context->debug(' FEATURE BannerRotator: Parent banner is not exists, skipping'); }
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; }
private function getVisitorAffiliate(Pap_Db_VisitorAffiliate $firstClickVisitorAffiliate, Pap_Db_VisitorAffiliate $oldVisitorAffiliate = null, Pap_Tracking_Visit_VisitorAffiliateCache $cache, Pap_Contexts_Tracking $context) { if ($firstClickVisitorAffiliate->getDateVisit() > $context->getDateCreated()) { return $firstClickVisitorAffiliate; } if ($oldVisitorAffiliate == null) { $visitorAffiliate = $cache->createVisitorAffiliate($context->getVisitorId()); $visitorAffiliate->setDateVisit($context->getDateCreated()); return $visitorAffiliate; } if ($oldVisitorAffiliate->getDateVisit() < $context->getDateCreated()) { return $oldVisitorAffiliate; } return null; }
/** * recognizes commission type for campaign * * @param Pap_Plugins_Tracking_Action_Context $context */ public function getCommissionType(Pap_Contexts_Tracking $context) { $campaign = $context->getCampaignObject(); $context->debug('Recognizing commission type started'); $type = $context->getActionType(); try { $context->debug(' Checking commission type : '.$type.' is in campaign'); $hash = $campaign->getId().$type.Pap_Db_CommissionType::STATUS_ENABLED; if (isset($this->commissionTypesCache[$hash])) { return $this->commissionTypesCache[$hash]; } $commissionType = $campaign->getCommissionTypeObject($type, '', $context->getCountryCode()); $this->commissionTypesCache[$hash] = $commissionType; } catch (Pap_Tracking_Exception $e) { $context->debug(" STOPPING, This commission type is not supported by current campaign or is NOT enabled! "); return; } $context->setCommissionTypeObject($commissionType); $context->getTransaction(1)->setType($type); $context->debug(' Commission type set to: '.$type.', ID: '.$commissionType->getId()); $context->debug('Recognizing commission type ended'); $context->debug(""); }
public static function getCookieLifetime(Pap_Contexts_Tracking $context) { if ($context->getCommissionGroup() !== null && ($cookieLifetime = $context->getCommissionGroup()->getCookieLifetime()) > Pap_Db_CommissionGroup::COOKIE_LIFETIME_VALUE_SAME_AS_CAMPAIGN) { return $cookieLifetime; } $lifetime = 0; if ($context->getCampaignObject() != null) { $lifetime = $context->getCampaignObject()->getCookieLifetime(); } if($lifetime == 0) { $lifetime = self::COOKIE_LIFETIME_FOREVER; } return $lifetime; }
/** * recomputes total cost to default currency * * @return unknown */ public function computeRealTotalCost(Pap_Contexts_Tracking $context) { if($context->getActionType() != Pap_Common_Constants::TYPE_ACTION) { $context->debug('Setting commission to 0 as the transaction type is not sale/action but '.$context->getActionType()); return 0; } $this->recognizeCurrency->processTotalCost($context); $newTotalCost = $this->computeRealCost($context,$context->getRealTotalCost() ,'realTotalCost'); $context->debug('Setting realTotalCost to '.$newTotalCost); $context->setRealTotalCost($newTotalCost); }
public function __construct(Pap_Db_RawImpression $rawImpression) { parent::__construct(); $this->rawImpression = $rawImpression; }
/** * @return string datetime in standard format */ public function getVisitDateTime() { if (strlen($timeStamp = $this->getCustomTimeStampFromRequest())) { return Gpf_Common_DateUtils::getDateTime($timeStamp); } return parent::getVisitDateTime(); }
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)); }
public function getCommissionGroup(Pap_Contexts_Tracking $context) { if ($context->getCampaignObject()->getCampaignType() != Pap_Db_Campaign::CAMPAIGN_TYPE_PUBLIC) { try { $status = Pap_Db_Table_UserInCommissionGroup::getStatus($context->getCampaignObject()->getId(), $context->getUserObject()->getId()); if ($status != Pap_Features_PerformanceRewards_Condition::STATUS_APPROVED && $status != Pap_Features_PerformanceRewards_Condition::STATUS_FIXED) { throw new Gpf_Exception(''); } } catch (Gpf_Exception $e) { $context->debug(' STOPPING, User is not approved in this campaign!'); $context->setDoCommissionsSave(false); $context->setDoTrackerSave(false); } } }
public function __construct() { parent::__construct(); }
private function isAccountRecognizedNotFromDefault(Pap_Contexts_Tracking $context) { if ($context->getAccountId() != null && $context->getAccountRecognizeMethod() != Pap_Contexts_Tracking::ACCOUNT_RECOGNIZED_DEFAULT) { return true; } return false; }
protected function getCommissionTypeId(Pap_Contexts_Tracking $context) { $commissionType = $context->getCommissionTypeObject(); if ($commissionType == null) { return null; } return $commissionType->getId(); }