Example #1
0
 protected function signUserToCampaign($userId, $campaignId, Gpf_Rpc_Form $form) {
     $campaign = new Pap_Common_Campaign();
     $campaign->setId($campaignId);
     try {
         $campaign->load();
     } catch (Gpf_Exception $e) {
         Gpf_Log::debug('SignupToCampaignPlugin: Invalid campaign '.$campaignId);
         return false;
     }
     if ($campaign->getCampaignType() == Pap_Common_Campaign::CAMPAIGN_TYPE_PUBLIC) {
         return false;
     }
     $userInCommGroup = new Pap_Db_UserInCommissionGroup();
     
     $user = new pap_common_user();
     $user->setId($userId);
     $user->load();
     if($user->getStatus() == Pap_Common_Constants::STATUS_PENDING){
         $userInCommGroup->addUserToGroup($campaign->getId(), $userId,
         $campaign->getDefaultCommissionGroup(), Pap_Common_Constants::STATUS_APPROVED);
         return true;
     }
     $userInCommGroup->addUserToGroupAndSendNotification($campaign->getId(), $userId,
     $campaign->getDefaultCommissionGroup(), Pap_Common_Constants::STATUS_APPROVED);
     return true;
 }
    /**
     * @service user_comm_group add
     *
     * @param Gpf_Rpc_Params $params
     * @return Gpf_Rpc_Action
     */
    public function addUsers(Gpf_Rpc_Params $params) {
        $action = new Gpf_Rpc_Action($params);
        $action->setErrorMessage($this->_('Failed to invite %s %s', '%s', $this->getRowName()));
        $action->setInfoMessage($this->_('%s %s successfully invited', '%s', $this->getRowName()));

        $campaign = new Pap_Common_Campaign();
        $campaign->setId($action->getParam('campaignId'));
        try {
            $campaign->load();
            if ($campaign->getCampaignType() == Pap_Common_Campaign::CAMPAIGN_TYPE_PUBLIC) {
                $action->setErrorMessage($this->_('Campaign is not private or public with manual approval'));
                $action->addError();
                return $action;
            }
        } catch (Gpf_DbEngine_NoRowException $e) {
            $action->setErrorMessage($this->_('Campaign not exist'));
            $action->addError();
            return $action;
        }
        $commissionGroup = $campaign->getDefaultCommissionGroup();

        foreach ($action->getIds() as $id) {
            $this->addUserNoRpc($action, $action->getParam('campaignId'), $id, $commissionGroup, 'A', $action->getParam('sendNotification') == Gpf::YES);
        }
        return $action;
    }
 public function getLinkingMethod(Pap_Common_Banner $banner = null) {
     if ($banner != null && $banner->getCampaignId() != '') {
         $campaign = new Pap_Common_Campaign();
         $campaign->setId($banner->getCampaignId());
         $campaign->load();
         if ($campaign->getLinkingMethod() != self::LINKMETHOD_DEFAULT_VALUE && 
             $campaign->getLinkingMethod() != null &&
             $campaign->getLinkingMethod() != '') {
             return $campaign->getLinkingMethod();
         }
     }
     return Gpf_Settings::get(Pap_Settings::SETTING_LINKING_METHOD);
 }
Example #4
0
    private function updateNullValidTo() {
        $select = new Gpf_SqlBuilder_SelectBuilder();
        $select->select->add('campaignid');
        $select->select->add('cookielifetime');
        $select->from->add(Pap_Db_Table_Campaigns::getName());
        $recordSet = $select->getAllRows();

        foreach ($recordSet as $record) {
            $campaign = new Pap_Common_Campaign();
            $campaign->setId($record->get('campaignid'));
            $campaign->setCookieLifetime($record->get('cookielifetime'));
            $this->updateValidityFor($campaign);
        }
    }
 /**
  * gets campaign by campaign id
  * @param $campaignId
  * @return Pap_Common_Campaign
  * @throws Gpf_Exception
  */
 public function getCampaignById(Pap_Contexts_Tracking $context, $campaignId) {
     if($campaignId == '') {
         throw new Gpf_Exception('Can not get campaign. Empty campaign id');
     }
     
     if (isset($this->campaignsCache[$campaignId.$context->getAccountId()])) {
         return $this->campaignsCache[$campaignId.$context->getAccountId()];
     }
     
     $campaign = new Pap_Common_Campaign();
     $campaign->setId($campaignId);
     $campaign->load();
     $this->checkCampaign($context, $campaign);
     $this->campaignsCache[$campaignId.$context->getAccountId()] = $campaign;
     return $campaign;
 }
Example #6
0
	private function saveCpmTransaction(Pap_Contexts_Impression $context) {
	    $campaign = new Pap_Common_Campaign();
	    $campaign->setId($context->getBannerObject()->getCampaignId());
	    $campaign->load();
	    $context->setCampaignObject($campaign);
	    $transaction = new Pap_Common_Transaction();
	    $transaction->setType(Pap_Common_Constants::TYPE_CPM);
	    $context->setTransactionObject($transaction);

	    $commissionType = new Pap_Tracking_Common_RecognizeCommType();
	    $commissionType->process($context);

	    $commissionGroup = new Pap_Tracking_Common_RecognizeCommGroup();
        $commissionGroup->recognize($context);

        $commissionSettings = new Pap_Tracking_Common_RecognizeCommSettings();
        $commissionSettings->recognize($context);

        $saveCommissions = new Pap_Tracking_Common_UpdateAllCommissions();
        $saveCommissions->process($context);
        $saveCommissions->saveChanges();
	}
 /**
  * @throws Gpf_Exception
  * @return Pap_Db_CommissionType
  */
 protected function getCommissionType($campaignId, $transactionType) {
     $campaign = new Pap_Common_Campaign();
     $campaign->setId($campaignId);
     try {
         $campaign->load();
     } catch (Gpf_Exception $e) {
         throw new Gpf_Exception($this->_('Campaign with Campaign ID: '.$campaignId.' does not exist'));
     }
     return $campaign->getCommissionTypeObject($transactionType);
 }
    protected function insertCampaignObject($id, $accountId, $name, $description, $dateIns, $status, $productid, $campaignId) {
        $obj = new Pap_Common_Campaign();
        $obj->setId($id);
        $obj->setAccountId($accountId);
        $obj->setName($name);
        $obj->set('description', $description);
        $obj->set('dateinserted', $dateIns);
        $obj->setCampaignStatus($status);

        $publicStatus = $this->getPap3Setting($campaignId, 'Aff_camp_status');

        $obj->setCampaignType(($publicStatus == 1 ? Pap_Db_Campaign::CAMPAIGN_TYPE_PUBLIC : Pap_Db_Campaign::CAMPAIGN_TYPE_ON_INVITATION));
        $obj->set('productid', $productid);
        $obj->resetOverwriteCookieToDefault();
        $obj->save();

        $commGrp = new Pap_Db_CommissionGroup();
        $commGrp->setId($obj->getDefaultCommissionGroup());
        $commGrp->load();
        $commGrp->delete();
    }
	/**
	 * Returns default commission group in campaign.
	 * If it doesn't exist, function will create & return
	 * new default commission group record.
	 * @param $campaignId
	 */
	public function getDefaultCommissionGroupId($campaignId) {
		if ($campaignId == "") {
			throw new Exception($this->_("Campaign ID cannot be empty!"));
		}
		$campaign = new Pap_Common_Campaign();
		$campaign->setId($campaignId);
		return $campaign->getDefaultCommissionGroup();
	}
Example #10
0
 /**
  * @throws Gpf_Exception
  * @return Pap_Common_Campaign
  */
 protected function getCampaign($campaignId)
 {
     if (!isset($this->campaignCache[$campaignId])) {
         $campaign = new Pap_Common_Campaign();
         $campaign->setId($campaignId);
         $campaign->load();
         $this->campaignCache[$campaignId] = $campaign;
     }
     return $this->campaignCache[$campaignId];
 }
    /**
     * @return Pap_Common_Campaign
     */
    private function createFirstCampaign() {
        $campaign = new Pap_Common_Campaign();
        $campaign->setId('11111111');
        $campaign->setName('First campaign');
        $campaign->setCampaignStatus(Pap_Common_Campaign::CAMPAIGN_STATUS_ACTIVE);
        $campaign->setCampaignType(Pap_Common_Campaign::CAMPAIGN_TYPE_PUBLIC);
        $campaign->setCookieLifetime(0);
        $campaign->resetOverwriteCookieToDefault();
        $campaign->setAccountId($this->account->getId());
        $campaign->save();

        return $campaign;
    }
Example #12
0
 /**
  * @throws Gpf_DbEngine_NoRowException
  * @param $campaignID
  * @return Pap_Common_Campaign
  */
 protected function getCampaign($campaignID) {
     $campaign = new Pap_Common_Campaign();
     $campaign->setId($this->banner->getCampaignId());
     $campaign->load();
     return $campaign;
 }
 protected function getCampaignById($campaignId) {
     $campaign = new Pap_Common_Campaign();
     $campaign->setId($campaignId);
     $campaign->load();
     return $campaign;
 }
 /**
  * @return Gpf_Settings_AccountSettings
  */
 protected function createAccountSettings() {
 	$campaign = new Pap_Common_Campaign();
 	$campaign->setId($this->transaction->getCampaignId());
 	try {
 		$campaign->load();
 		return Gpf_Settings::getAccountSettings($campaign->getAccountId());
 	} catch (Gpf_Exception $e) {
 	}
 	return Gpf_Settings::getAccountSettings(Gpf_Db_Account::DEFAULT_ACCOUNT_ID);
 }
 protected function getCampaignName($campaignId) {
     $campaign = new Pap_Common_Campaign();
     $campaign->setId($campaignId);
     try {
         $campaign->load();
         return $campaign->getName();
     } catch (Gpf_Exception $e) {
         return '';
     }
 }
Example #16
0
    /**
     * @return Pap_Common_Campaign
     */
    public static function createDefaultCampaign($accountId, $campaignName, $campaignId = null, $type = Pap_Common_Campaign::CAMPAIGN_TYPE_PUBLIC) {
        $campaign = new Pap_Common_Campaign();
        if ($campaignId != null) {
            $campaign->setId($campaignId);
        }
        $campaign->setName($campaignName);
        $campaign->setDateInserted(Gpf_Common_DateUtils::now());
        $campaign->setCampaignStatus(Pap_Common_Campaign::CAMPAIGN_STATUS_ACTIVE);
        $campaign->setCampaignType($type);
        $campaign->setCookieLifetime(0);
        $campaign->resetOverwriteCookieToDefault();
        $campaign->setAccountId($accountId);
        $campaign->setIsDefault();
        $campaign->save();

        self::createDefaultCommissionSettings($campaign);

        return $campaign;
    }
    private function getCommissionTypeAndValue($campaignId, $userId, $commissionTypeId, $tier = null) {
        if (is_null($tier) || $tier == '') {
            $tier = 1;
        }

        // getting user
        if($userId == '') {
            $this->errorMsg = $this->_("User is not valid!");
            return false;
        }
        $user = new Pap_Common_User();
        $user->setPrimaryKeyValue($userId);
        try {
            $user->load();
        } catch (Gpf_DbEngine_NoRowException $e) {
            $this->errorMsg = $this->_("User is not valid!");
            return false;
        }

        // getting campaign
        $campaign = new Pap_Common_Campaign();
        $campaign->setId($campaignId);
        try {
            $campaign->load();
        } catch (Gpf_DbEngine_NoRowException $e) {
            $this->errorMsg = $this->_("Campaign is not valid!");
            return false;
        }
        // getting commission type
        try {
            $commissionType = new Pap_Db_CommissionType();
            $commissionType->setId($commissionTypeId);
            $commissionType->setStatus(Pap_Db_CommissionType::STATUS_ENABLED);
            $commissionType->loadFromData();
        } catch (Gpf_DbEngine_NoRowException $e) {
            $this->errorMsg = $this->_("Transaction type is not valid or doesn't exist in this campaign!");
            return false;
        }
        $fixedcostType = $commissionType->getFixedcostType();
        $fixedcostValue = $commissionType->getFixedcostValue();
        // getting commission group
        $commGroupId = $campaign->getCommissionGroupForUser($userId);
        if($commGroupId == false) {
            $this->errorMsg = $this->_("Cannot recognize commission group for this user in campaign!");
            return false;
        }

        $rsCommissions = $campaign->getCommissionsCollection($commGroupId, $commissionType->getId());
        $commType = null;
        $commValue = null;
        foreach($rsCommissions as $record) {
            if($record->get('tier') == $tier && $record->get('subtype') == 'N') {
                $commType = $record->get('commissiontype');
                $commValue = $record->get('commissionvalue');
                break;
            }
        }

        if($commType == null) {
            $this->errorMsg = $this->_("Error getting commission settings!");
            return false;
        }

        return array('type' => $commType, 'value' => $commValue, 'fixedcostValue' => $fixedcostValue, 'fixedcostType' => $fixedcostType);
    }