/**
	 * 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 save(Pap_Contexts_Tracking $context) {
		$context->debug('Saving commissions started');

		$tier = 1;
		$currentUser = $context->getUserObject();
		$currentCommission = $context->getCommission($tier);

		while($currentUser != null && $tier < 100) {
			if ($currentCommission != null) {
				if ($currentUser->getStatus() != null && $currentUser->getStatus() != 'D') {
					$this->saveCommission($context, $currentUser, $currentCommission);
				} else {
					$context->debug('Commission is not saved, because user is declined');
                }
			} else {
			    $context->debug('Commission is not saved, because it is not defined in campaign or user has no multi tier commission');
			}
		    Gpf_Plugins_Engine::extensionPoint('Tracker.saveAllCommissions', new Pap_Common_SaveCommissionCompoundContext($context, $tier, $currentUser, $this ));

			$tier++;
			$currentUser = $this->userTree->getParent($currentUser);
			$currentCommission = $context->getCommission($tier);
		}

		Gpf_Plugins_Engine::extensionPoint('Tracker.saveCommissions', $context);

		$context->debug('Saving commissions ended');
		$context->debug("");
    }
    public function recognize(Pap_Contexts_Tracking $context) {
        if(($context->getUserObject()) != null) {
            $context->debug('  User already recognized, finishing user recognizer');
            return;
        }

        parent::recognize($context);
    }
    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;
    }
 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);
 }
    protected function getCommissionsCollection(Pap_Contexts_Tracking $context) {
        $tier = 1;
        $currentUser = $context->getUserObject();
        $collection = new Gpf_DbEngine_Row_Collection();

        while($currentUser != null && $tier < 100) {
            $tierCommissions = $this->getTierCommissionCollection($context, $currentUser->getId(), $tier);
                foreach ($tierCommissions as $dbCommission) {
                    $context->debug('Adding commission commissiontypeid: '.$dbCommission->get(Pap_Db_Table_Commissions::TYPE_ID).
                                ', commissiongroupid: '.$dbCommission->get(Pap_Db_Table_Commissions::GROUP_ID).
                                ', tier: '.$dbCommission->get(Pap_Db_Table_Commissions::TIER).
                                ', subtype: '.$dbCommission->get(Pap_Db_Table_Commissions::SUBTYPE));
                    $collection->add($dbCommission);
                }

            $tier++;
            $currentUser = $this->userTree->getParent($currentUser);
        }
        return $collection;
    }
示例#7
0
 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();
 }
    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));
    }
 /**
  * @return Pap_Db_VisitorAffiliate
  */
 private function findAlreadyStoredVisitorAffiliate(Pap_Tracking_Common_VisitorAffiliateCollection $rows,
 Pap_Db_VisitorAffiliate $firstClickVisitorAffiliate = null,
 Pap_Contexts_Tracking $context) {
     foreach ($rows as $row) {
         if (!$row->isValid()) {
             continue;
         }
         if ($context->getUserObject()->getId() == $row->getUserId() &&
         $row !== $firstClickVisitorAffiliate) {
             $context->debug('VisitorAffiliate with affiliate already exist');
             return $row;
         }
     }
     return null;
 }
示例#10
0
 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);
         }
     }
 }