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;
 }
Example #2
0
    public function firstTimeApproved(Pap_Affiliates_User $user){
        $userInCommision = new Pap_Db_UserInCommissionGroup();

        $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
        $selectBuilder->select->addAll(Pap_Db_Table_Campaigns::getInstance(), 'ca');
        
        $selectBuilder->from->add('qu_pap_commissiongroups', 'c');
        $selectBuilder->from->addInnerJoin('qu_pap_userincommissiongroup', 'u', 'u.commissiongroupid=c.commissiongroupid');
        $selectBuilder->from->addInnerJoin(Pap_Db_Table_Campaigns::getName(), 'ca', 'ca.'.Pap_Db_Table_Campaigns::ID.'=c.campaignid');
        $selectBuilder->where->add('u.userid','=',$user->getId());
        foreach ($selectBuilder->getAllRowsIterator() as $row){
            $campaign = new Pap_Common_Campaign();
            $campaign->fillFromRecord($row);
            $userInCommision->sendInviteMail($campaign,$user->getId());
        }
    }
 private function addUserInCommissionGroup($commissionGroupId, $userId, $status) {
     $userInCommissionGroup = new Pap_Db_UserInCommissionGroup();
     $userInCommissionGroup->setCommissionGroupId($commissionGroupId);
     $userInCommissionGroup->setUserId($userId);
     $userInCommissionGroup->setStatus($status);
     $userInCommissionGroup->setDateAdded(Gpf_Common_DateUtils::getDateTime(time()));      
     $userInCommissionGroup->save();	
 }
 /**
  *
  * @return Pap_Db_UserInCommissionGroup
  */
 protected function getUserCommissionGroup() {
     if($this->userInGroup !== null) {
         return $this->userInGroup;
     }
     try {
         $userInGroup = Pap_Db_Table_UserInCommissionGroup::getInstance()->getUserCommissionGroup(
             $this->getCurrentUserId(), $this->transaction->getCampaignId());
     } catch (Gpf_DbEngine_TooManyRowsException $e) {
         Gpf_Log::error(sprintf('Database not in consistent state. User %s has many commission groups', $userId));
         Pap_Db_Table_UserInCommissionGroup::removeUserFromCampaignGroups($userId, $campaignId);
         $userInGroup = new Pap_Db_UserInCommissionGroup();
         $userInGroup->setStatus(Pap_Features_PerformanceRewards_Condition::STATUS_APPROVED);
         $userInGroup->setUserId($userId);
     }
     return $this->userInGroup = $userInGroup;
 }
    /**
     *
     * @return Pap_Db_UserInCommissionGroup
     */
    public function getUserCommissionGroup($userId, $campaignId) {
        $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
        $selectBuilder->select->addAll(Pap_Db_Table_UserInCommissionGroup::getInstance(), 'ucg');

        $selectBuilder->from->add(Pap_Db_Table_UserInCommissionGroup::getName(), 'ucg');
        $selectBuilder->from->addInnerJoin(Pap_Db_Table_CommissionGroups::getName(), 'cg',
        'ucg.'.Pap_Db_Table_UserInCommissionGroup::COMMISSION_GROUP_ID .'='. 'cg.'.Pap_Db_Table_CommissionGroups::ID);
        
        $selectBuilder->where->add('ucg.'.Pap_Db_Table_UserInCommissionGroup::USER_ID, '=', $userId);
        $selectBuilder->where->add('cg.'.Pap_Db_Table_CommissionGroups::CAMPAIGN_ID, '=', $campaignId);
                
        $userInGroup = new Pap_Db_UserInCommissionGroup();
        $userInGroup->setStatus(Pap_Features_PerformanceRewards_Condition::STATUS_APPROVED);
        try {
            $record = $selectBuilder->getOneRow();
            $userInGroup->fillFromRecord($record);
            $userInGroup->setPersistent(true);
        } catch (Gpf_DbEngine_NoRowException $e) {
            $userInGroup->setUserId($userId);
            $userInGroup->setCommissionGroupId(Pap_Db_Table_Campaigns::getInstance()->getDefaultCommissionGroup($campaignId)->getId());
        }
        return $userInGroup;
    }
 /**
  * @param $userId
  * @param $commissionGroupId
  * @param $status
  * @return Pap_Db_UserInCommissionGroup
  */
 private function createUserInCommGroup($userId, $commissionGroupId, $status) {
     $userInCommGroup = new Pap_Db_UserInCommissionGroup();
     $userInCommGroup->setUserId($userId);
     $userInCommGroup->setCommissionGroupId($commissionGroupId);
     $userInCommGroup->setStatus($status);
     return $userInCommGroup;
 }
    protected function migrateUsersInCampaigns() {
    	Pap3Compatibility_Migration_OutputWriter::log("  Migrating users in campaigns.....");

    	$selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
        $selectBuilder->select->add('*');
        $selectBuilder->from->add('wd_pa_affiliatescampaigns');

        $count = 0;
        foreach($selectBuilder->getAllRowsIterator() as $record) {
        	if($record->get('affiliateid') == '' || $record->get('campcategoryid') == '') {
        		continue;
        	}
        	$count++;
        	try {
        		$obj = new Pap_Db_UserInCommissionGroup();
        		$obj->setUserId($record->get('affiliateid'));
        		$obj->setCommissionGroupId($record->get('campcategoryid'));
        		$obj->setStatus(Pap3Compatibility_Migration_Pap3Constants::translateStatus($record->get('rstatus')));
        		$obj->setDateAdded(Gpf_Common_DateUtils::now());
        		$obj->save();
        	} catch(Gpf_Exception $e) {
        		// non important error, don't display it
        	}
        }

    	Pap3Compatibility_Migration_OutputWriter::log(" ($count) ..... DONE<br/>");
    }
 /**
  * @throws Gpf_DbEngine_NoRowException
  * @param $userInCommGroup
  */
 private function sendMail(Pap_Db_UserInCommissionGroup $userInCommGroup) {
 	$mailContext = new Pap_Features_PrivateCampaigns_MailContext();
     $mailContext->setCampaign(Pap_Common_Campaign::getCampaignById(Pap_Db_CommissionGroup::getCommissionGroupById($userInCommGroup->getCommissionGroupId())->getCampaignId()));
     $mailContext->setUser(Pap_Common_User::getUserById($userInCommGroup->getUserId()));
     $mailContext->setUserInCommissionGroup($userInCommGroup);
     Gpf_Plugins_Engine::extensionPoint('PostAffiliate.UserInCommissionGroup.changeStatus', $mailContext);
 }