Beispiel #1
0
 private function getUserCommissionTypes($campaignId = null) {
     $userId = null;
     if (Gpf_Session::getAuthUser()->isAffiliate()) {
         $userId = Gpf_Session::getAuthUser()->getPapUserId();
     }
     return Pap_Db_Table_CommissionTypes::getInstance()->getAllUserCommissionTypes($campaignId, Pap_Common_Constants::TYPE_ACTION, $userId);
 }
    public function run() {
    	$time1 = microtime();
    	Pap3Compatibility_Migration_OutputWriter::logOnce("Deleting migrated data from existing PAP4 tables<br/>");

    	try {
    		$this->deleteTable(Pap_Db_Table_Campaigns::getName());
    		$this->deleteTable(Pap_Db_Table_CommissionGroups::getName());
    		$this->deleteTable(Pap_Db_Table_CommissionTypes::getName());
    		$this->deleteTable(Pap_Db_Table_Commissions::getName());
    		$this->deleteTable(Pap_Db_Table_UserInCommissionGroup::getName());
    		
    		$this->deleteTable(Gpf_Db_Table_FormFields::getName());
    		$this->deleteTable(Gpf_Db_Table_FieldGroups::getName());
    		
    		$this->deleteTable(Pap_Db_Table_Transactions::getName());
    		$this->deleteTable(Pap_Db_Table_Clicks::getName());
    		$this->deleteTable(Pap_Db_Table_RawClicks::getName());
    		$this->deleteTable(Pap_Db_Table_Impressions::getName());

    		$this->deleteTable(Pap_Db_Table_Banners::getName());
    		
    		$this->deleteTable(Gpf_Db_Table_FieldGroups::getName());
    		$this->deleteTable(Pap_Db_Table_PayoutsHistory::getName());
    		$this->deleteTable(Pap_Db_Table_Payouts::getName());
    		
    		$this->deleteTable(Gpf_Db_Table_Currencies::getName());
    		$this->deleteTable(Gpf_Db_Table_MailAccounts::getName());
    		
    	} catch(Exception $e) {
    		Pap3Compatibility_Migration_OutputWriter::log("&nbsp;&nbsp;Errror: ".$e->getMessage()."<br/>");
    	}

    	$time2 = microtime();
		Pap3Compatibility_Migration_OutputWriter::logDone($time1, $time2);
    }
 protected function buildFrom() {
     $this->_selectBuilder->from->add(Pap_Db_Table_AffiliateTrackingCodes::getName(), 'atc');
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_CommissionTypes::getName(), 'com', 'com.commtypeid=atc.commtypeid');
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Campaigns::getName(), 'cam', 'cam.campaignid=com.campaignid');
     
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), 'u', 'u.userid=atc.userid');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'gu', 'u.accountuserid=gu.accountuserid');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au', 'au.authid=gu.authid');
 }
Beispiel #4
0
 private function getUserCommissionTypes($campaignId = null) {
     $userId = null;
     if (Gpf_Session::getAuthUser()->isAffiliate()) {
         $userId = Gpf_Session::getAuthUser()->getPapUserId();
     }
     if (!array_key_exists($campaignId.'_'.$userId, self::$userCommissionTypes)) {
         self::$userCommissionTypes[$campaignId.'_'.$userId] = Pap_Db_Table_CommissionTypes::getInstance()->getAllUserCommissionTypes($campaignId, Pap_Common_Constants::TYPE_ACTION, $userId);
     }
     return self::$userCommissionTypes[$campaignId.'_'.$userId];
 }
 /**
  * @return Gpf_SqlBuilder_SelectBuilder
  */
 protected function createSelectBuilder() {
 	$select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add("DISTINCT(".Pap_Db_Table_CommissionTypes::CODE.")", self::ID);
     $select->select->add(Pap_Db_Table_CommissionTypes::NAME, self::VALUE);
     $select->from->add(Pap_Db_Table_CommissionTypes::getName());
     $select->where->add(Pap_Db_Table_CommissionTypes::TYPE,
         '=', Pap_Common_Constants::TYPE_ACTION);
     $select->orderBy->add(Pap_Db_Table_CommissionTypes::NAME);
     
     return $select;
 }
	/**
	 * @return Gpf_SqlBuilder_SelectBuilder
	 */
	protected function createCommissionTypeSelect($campaignId) {
		$selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
		foreach ($this->createHeaderArray() as $column) {
			$selectBuilder->select->add($column);	
		}		
		$selectBuilder->from->add(Pap_Db_Table_CommissionTypes::getName());
		if ($campaignId !== '') {
			$selectBuilder->where->add(Pap_Db_Table_CommissionTypes::CAMPAIGNID, '=', $campaignId);
		}
		return $selectBuilder;
	}
 public function save(Pap_Merchants_Campaign_CommissionTypeRpcForm $form) {
     if($form->getFieldValue('rtype') != Pap_Common_Constants::TYPE_ACTION) {
         return;
     }
     $update =  new Gpf_SqlBuilder_UpdateBuilder();
     $update->set->add(Pap_Db_Table_CommissionTypes::NAME, $form->getFieldValue(Pap_Db_Table_CommissionTypes::NAME));
     $update->from->add(Pap_Db_Table_CommissionTypes::getName());
     $update->where->add(Pap_Db_Table_CommissionTypes::CODE, '=', $form->getFieldValue(Pap_Db_Table_CommissionTypes::CODE));
     $update->where->add(Pap_Db_Table_CommissionTypes::CAMPAIGNID, '=', Pap_Db_CommissionGroup::getCommissionGroupById($form->getFieldValue('CommissionGroupId'))->getCampaignId());
     $update->execute();
 }
 protected function buildFrom() {
     $affiliateWhere = new Gpf_SqlBuilder_CompoundWhereCondition();
     $affiliateWhere->add(Pap_Db_Table_AffiliateTrackingCodes::AFFILIATEID, '=', Gpf_Session::getAuthUser()->getPapUserId(), 'OR');
     $affiliateWhere->add(Pap_Db_Table_AffiliateTrackingCodes::AFFILIATEID, 'IS', 'NULL', 'OR', false);
     
     $this->_selectBuilder->from->add(Pap_Db_Table_CommissionTypes::getName(), 'ct');
     $onCondition = new Gpf_SqlBuilder_CompoundWhereCondition();
     $onCondition->add('ct.'.Pap_Db_Table_CommissionTypes::ID, '=', 'c.'.Pap_Db_Table_AffiliateTrackingCodes::COMMTYPEID, 'AND', false);
     $onCondition->addCondition($affiliateWhere); 
     
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_AffiliateTrackingCodes::getName(), 'c', 
         $onCondition->toString());
 }
    private function initActionCampaignNames() {
        $select = new Gpf_SqlBuilder_SelectBuilder();
        $select->select->add('c.'.Pap_Db_Table_Campaigns::NAME);
        $select->select->add('ct.'.Pap_Db_Table_CommissionTypes::ID);
        $select->from->add(Pap_Db_Table_Campaigns::getName(), 'c');
        $select->from->addInnerJoin(Pap_Db_Table_CommissionTypes::getName(), 'ct', 'ct.'.Pap_Db_Table_CommissionTypes::CAMPAIGNID.'='.'c.'.Pap_Db_Table_Campaigns::ID);
        $select->where->add('ct.'.Pap_Db_Table_CommissionTypes::NAME, '!=', '');
        $select->where->add('ct.'.Pap_Db_Table_CommissionTypes::NAME, '!=', null);

        $this->campaignNamesCache = array();

        foreach ($select->getAllRows() as $row) {
            $this->campaignNamesCache[$row->get(Pap_Db_Table_CommissionTypes::ID)] = $row->get(Pap_Db_Table_Campaigns::NAME);
        }
    }
 private function getCommissionTypeSelect($commissionType, $code = '',$countryCode = '') {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->addAll(Pap_Db_Table_CommissionTypes::getInstance());
     $select->from->add(Pap_Db_Table_CommissionTypes::getName());
     $select->where->add(Pap_Db_Table_CommissionTypes::CAMPAIGNID, '=', $this->getId());
     $select->where->add(Pap_Db_Table_CommissionTypes::TYPE, '=', $commissionType);
     $select->where->add(Pap_Db_Table_CommissionTypes::STATUS, '=', Pap_Db_CommissionType::STATUS_ENABLED);
     if ($code != null && $code != '') {
         $select->where->add(Pap_Db_Table_CommissionTypes::CODE, '=', $code);
     }
     if (!strlen($countryCode)) {
         $compoundCondition = new Gpf_SqlBuilder_CompoundWhereCondition();
         $compoundCondition->add(Pap_Db_Table_CommissionTypes::PARENT_COMMISSIONTYPE_ID, '=', null, 'OR');
         $compoundCondition->add(Pap_Db_Table_CommissionTypes::PARENT_COMMISSIONTYPE_ID, '=', '', 'OR');
         $select->where->addCondition($compoundCondition);
     } else {
         $select->where->add(Pap_Db_Table_CommissionTypes::PARENT_COMMISSIONTYPE_ID, '!=', null);
         $select->where->add(Pap_Db_Table_CommissionTypes::COUNTRYCODES, 'like', '%' . $countryCode . '%');
     }
     return $select;
 }
Beispiel #11
0
    public function execute() {
        $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::ID);
        $selectBuilder->from->add(Pap_Db_Table_CommissionTypes::getName());
        $selectBuilder->where->add(Pap_Db_Table_CommissionTypes::TYPE, '=', Pap_Common_Constants::TYPE_REFERRAL);
        try {
            $selectBuilder->getOneRow();
            return;
        } catch (Gpf_Exception $e) {
        }

        $insert = new Gpf_SqlBuilder_InsertBuilder();
        $insert->setTable(Pap_Db_Table_CommissionTypes::getInstance());
        $insert->add(Pap_Db_Table_CommissionTypes::ID, 'refercom');
        $insert->add(Pap_Db_Table_CommissionTypes::TYPE, Pap_Common_Constants::TYPE_REFERRAL);
        $insert->add(Pap_Db_Table_CommissionTypes::STATUS, Pap_Db_CommissionType::STATUS_ENABLED);
        $insert->add(Pap_Db_Table_CommissionTypes::APPROVAL, Pap_Db_CommissionType::APPROVAL_AUTOMATIC);
        $insert->add(Pap_Db_Table_CommissionTypes::ZEROORDERSCOMMISSION, Gpf::NO);
        try {
            $insert->execute();
        } catch (Exception $e) {
        }
    }
Beispiel #12
0
 public function getCommissionType(Pap_Contexts_Action $context) {
     $context->debug("Begin recognizing country specific commission type");
     if(!strlen($context->getTransactionObject()->getCountryCode())) {
         $context->debug("STOPPING recognizing country specific commission type eneded: country code not recognized or empty");
         return;
     }
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->addAll(Pap_Db_Table_CommissionTypes::getInstance());
     $select->from->add(Pap_Db_Table_CommissionTypes::getName());
     $select->where->add(Pap_Db_Table_CommissionTypes::PARENT_COMMISSIONTYPE_ID, '=', $context->getCommissionTypeObject()->getId());
         
     $compoundContext = new Gpf_Data_Record(array(Pap_Db_Table_RawImpressions::IP, Pap_Db_Table_Impressions::COUNTRYCODE), array($context->getVisit()->getIp(), ''));
     $this->getCountryCode($compoundContext);
     $countryCode = $compoundContext->get(Pap_Db_Table_Impressions::COUNTRYCODE);
     if (!strlen($countryCode)) {
         $context->debug("STOPPING recognizing country specific commission type eneded: country code not recognized or empty");
         return;
     }
         
     $select->where->add(Pap_Db_Table_CommissionTypes::COUNTRYCODES, 'LIKE', '%'.$countryCode.'%');
     try {
         $commType = new Pap_Db_CommissionType();
         $collection = $commType->loadCollectionFromRecordset($select->getAllRows());
         $context->setCommissionTypeObject($collection->get(0));
     } catch (Gpf_DbEngine_NoRowException $e) {
         $context->debug("Recognizing country specific commission type eneded - no country secpific commission defined");
         return;
     } catch (Gpf_DbEngine_TooManyRowsException $e) {
         $context->debug("STOPPING ecognizing country specific commission type eneded: more than one commision type is defined for country " . $context->getTransactionObject()->getCountryCode());
         return;
     } catch (Gpf_Exception $e) {
         $context->debug("STOPPING recognizing country specific commission type eneded: " . $e->getMessage());
     }
 }
 /**
  * @return Pap_Db_Table_CommissionTypes
  */
 public static function getInstance() {
     if(self::$instance === null) {
         self::$instance = new self;
     }
     return self::$instance;
 }
	private function changeCommissionTypeChildsStatus($commtypeId, $status) {
		$update = new Gpf_SqlBuilder_UpdateBuilder();
		$update->from->add(Pap_Db_Table_CommissionTypes::getName(), 't');
		$update->set->add('t.'.Pap_Db_Table_CommissionTypes::STATUS, $status);
		$update->where->add('t.'.Pap_Db_Table_CommissionTypes::PARENT_COMMISSIONTYPE_ID, '=', $commtypeId);
		$update->execute();
	}
	/**
	 * @service commission read
	 * @param Gpf_Rpc_Params $params
	 */
	public function loadReferralCommissions(Gpf_Rpc_Params $params) {
		return Pap_Db_Table_CommissionTypes::getInstance()->getAllCommissionTypes(null, Pap_Common_Constants::TYPE_REFERRAL);		
	}
 function buildFrom() {
     $this->_selectBuilder->from->add(Pap_Db_Table_Transactions::getName(), "t");
     $onCondition = "t.".Pap_Db_Table_Transactions::CAMPAIGN_ID." = c.".Pap_Db_Table_Campaigns::ID;
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Campaigns::getName(), 'c', $onCondition);
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), "pu", "t.userid = pu.userid");
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(), "gu", "pu.accountuserid = gu.accountuserid");
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), "au", "gu.authid = au.authid");
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Channels::getName(), "ch", "t.channel = ch.channelid");
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_CommissionTypes::getName(), "ct", "t.commtypeid = ct.commtypeid");
     $this->_selectBuilder->from->addLeftJoin(Gpf_Db_Table_Currencies::getName(), 'cs', 't.originalcurrencyid = cs.currencyid');
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Banners::getName(), 'b', 'b.bannerid = t.bannerid');
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_PayoutsHistory::getName(), 'ph',
         'ph.'.Pap_Db_Table_PayoutsHistory::ID.' = t.'.Pap_Db_Table_Transactions::PAYOUTHISTORY_ID);
 }
    protected function addReferralCommissions(Pap_Affiliates_User $affiliate) {
        try {
            $commissionType = Pap_Db_Table_CommissionTypes::getReferralCommissionType();
        } catch (Gpf_Exception $e) {
            return;
        }
        $referralCommissions = Pap_Db_Table_Commissions::getReferralCommissions();
        if ($commissionType->getStatus() == 'D' || $referralCommissions->getSize() < 1) {
            return;
        }
        if ($commissionType->getApproval() == Pap_Db_CommissionType::APPROVAL_MANUAL) {
            $status = 'P';
        } else {
            $status = $affiliate->getStatus();
        }

        $saveZeroCommissions = $commissionType->getSaveZeroCommissions();

        $iterator = $referralCommissions->getIterator();

        while (($affiliate = $affiliate->getParentUser()) !== null) {
            if ($iterator->valid()) {
                $commission = $iterator->current();
                $this->addTransaction($affiliate->getId(), Pap_Db_Transaction::TYPE_REFERRAL, $commission->get(Pap_Db_Table_Commissions::VALUE), $status, $commission,$saveZeroCommissions);
                $iterator->next();
            } else {
                break;
            }
        }
    }
 protected function getCountryCodes() {
     $subSelect = new Gpf_SqlBuilder_SelectBuilder();
     $subSelect->select->add('GROUP_CONCAT(DISTINCT ct.'.Pap_Db_Table_CommissionTypes::COUNTRYCODES.')','countrycode');
     $subSelect->from->add(Pap_Db_Table_CommissionTypes::getName(),'ct');
     $subSelect->where->add('ct.'.Pap_Db_Table_CommissionTypes::CAMPAIGNID,'=','c.'.Pap_Db_Table_Campaigns::ID,'AND',false);
     return $subSelect->toString();
 }
   /**
     * @return Gpf_Data_RecordSet
     */
    public function getReferralCommissions() {
        $select = new Gpf_SqlBuilder_SelectBuilder();
        $select->select->add('c.'.Pap_Db_Table_Commissions::ID, Pap_Db_Table_Commissions::ID);
        $select->select->add('c.'.Pap_Db_Table_Commissions::TIER, Pap_Db_Table_Commissions::TIER);
        $select->select->add('c.'.Pap_Db_Table_Commissions::SUBTYPE, Pap_Db_Table_Commissions::SUBTYPE);
        $select->select->add('c.'.Pap_Db_Table_Commissions::TYPE, 'commissiontype');
        $select->select->add('c.'.Pap_Db_Table_Commissions::VALUE, 'commissionvalue');
        $select->select->add('c.'.Pap_Db_Table_Commissions::TYPE_ID, 'commtypeid');
        $select->from->add(Pap_Db_Table_Commissions::getName(), 'c');
        $select->from->addInnerJoin(Pap_Db_Table_CommissionTypes::getName(), 'ct',
            'c.'.Pap_Db_Table_Commissions::TYPE_ID.'=ct.'.Pap_Db_Table_CommissionTypes::ID);
        $select->where->add(Pap_Db_Table_CommissionTypes::TYPE, '=', Pap_Db_Transaction::TYPE_REFERRAL);
        $select->orderBy->add(Pap_Db_Table_Commissions::TIER);

        return $select->getAllRows();
    }
    protected function isMultiTierTransaction(Gpf_Rpc_Form $form) {
        try {
            $commTypeId = $form->getFieldValue(Pap_Db_Table_Transactions::COMMISSIONTYPEID);
            $rtype = $this->getCommType($commTypeId)->getType();
        } catch (Gpf_Data_RecordSetNoRowException $e) {
            $rtype = $this->getRTypeFromForm($form);
        } catch (Gpf_DbEngine_NoRowException $e) {
            $rtype = $this->getRTypeFromForm($form);
        }
        if (Pap_Db_Table_CommissionTypes::isSpecialType($rtype)) {
            return false;
        }
        if ($form->getFieldValue('multiTier') != Gpf::YES) {
            return false;
        }

        return true;
    }
 public function init() {
     $this->setTable(Pap_Db_Table_CommissionTypes::getInstance());
     parent::init();
 }
    private function getCommissionTypes() {
        $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::ID, Pap_Db_Table_CommissionTypes::ID);
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::TYPE, Pap_Db_Table_CommissionTypes::TYPE);
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::STATUS, Pap_Db_Table_CommissionTypes::STATUS);
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::NAME, Pap_Db_Table_CommissionTypes::NAME);
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::APPROVAL, Pap_Db_Table_CommissionTypes::APPROVAL);
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::CODE, Pap_Db_Table_CommissionTypes::CODE);
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::RECURRENCEPRESETID, Pap_Db_Table_CommissionTypes::RECURRENCEPRESETID);
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::ZEROORDERSCOMMISSION, Pap_Db_Table_CommissionTypes::ZEROORDERSCOMMISSION);
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::SAVEZEROCOMMISSION, Pap_Db_Table_CommissionTypes::SAVEZEROCOMMISSION);
        $selectBuilder->select->add(Pap_Db_Table_CommissionTypes::CAMPAIGNID, Pap_Db_Table_CommissionTypes::CAMPAIGNID);
        $selectBuilder->from->add(Pap_Db_Table_CommissionTypes::getName());

        return $selectBuilder;
    }