private function getUser() {
		$user = new Pap_Affiliates_User();
		$user->setId(Gpf_Session::getAuthUser()->getPapUserId());
		$user->load();

		return $user;
	}
    /**
     * Load affiliate detail for affiliate manager
     *
     * @service affiliate read
     * @param $fields
     */
    public function affiliateDetails(Gpf_Rpc_Params $params) {
        $data = new Gpf_Rpc_Data($params);
        $search = $data->getFilters()->getFilter("id");
        if (sizeof($search) == 1) {
            $id = $search[0]->getValue();
        }
        

        $user = new Pap_Affiliates_User();
        $user->setId($id);
        try {
            $user->load();
        } catch (Gpf_DbEngine_NoRowException $e) {
            return $data;
        }
        $data->setValue("id", $user->getId());
        $data->setValue("name", $user->getFirstName()." ".$user->getLastName());
        $data->setValue("username", $user->getUserName());

        $formFields = $this->getUserFormFields();
        foreach($formFields as $record) {
            $code = $record->get('code');
            $data->setValue($code, $user->get($code));
        }

        return $data;
    }
    /**
     * @service coupon read
     * @param $fields
     * @return Gpf_Rpc_Form
     */
    public function load(Gpf_Rpc_Params $params) {
        $form = new Gpf_Rpc_Form($params);
        $form->addField(Pap_Db_Table_Coupons::CODE, null);

        $coupon = new Pap_Db_Coupon();
        $coupon->setId($form->getFieldValue(Gpf_View_FormService::ID));
        $coupon->setCode($form->getFieldValue(Gpf_View_FormService::ID));
        $banner = new Pap_Features_Coupon_Coupon();
        $affiliate = new Pap_Affiliates_User();

        try {
            $this->loadCoupon($coupon);
            if (!$coupon->isValid()) {
                return $form;
            }
            $banner->setPrimaryKeyValue($coupon->getBannerID());
            $banner->load();
            $affiliate->setPrimaryKeyValue($coupon->getUserID());
            $affiliate->load();
            $form->addField('couponid', $coupon->getId());
            $form->addField('couponcode', $coupon->getCode());
            $form->addField('name', $banner->getName());
            $form->addField('description', $banner->getData1());
            $this->fillFromUser($form, $affiliate);
            
            Gpf_Plugins_Engine::extensionPoint('PostAffiliate.OfflineSaleForm.load', $form);
            
        } catch (Gpf_Exception $e) {
        }

        return $form;
    }
 private function initAffiliate($affiliateId) {
 	$this->affiliate = new Pap_Affiliates_User();
 	$this->affiliate->setPrimaryKeyValue($affiliateId);
     $this->affiliate->load();
     if ($this->affiliate->getType() != Pap_Application::ROLETYPE_AFFILIATE) {
     	throw new Gpf_Exception($this->_('User is not affiliate'));
     }
 }
 private function addUserToRecordSet(Gpf_Data_RecordSet $result, $userId) {
     $user = new Pap_Affiliates_User();
     $user->setId($userId);
     try {
         $user->load();
         $record = $result->createRecord();
         $record->loadFromObject(array_values($user->toArray()));
         $record->set("subaffiliates", 1);
         $result->add($record);
         if (strlen($user->getParentUserId())) {
             $this->addUserToRecordSet($result, $user->getParentUserId());
         }
     } catch (Exception $e) {
     }
 }
 public static function getAffiliateLink() {
     $mainSiteUrl = Gpf_Settings::get(Pap_Settings::MAIN_SITE_URL);
     $user = new Pap_Affiliates_User();
     $user->setId(Gpf_Session::getAuthUser()->getPapUserId());
     $user->load();
     if (Pap_Tracking_ClickTracker::getInstance()->getLinkingMethod() == Pap_Tracking_ClickTracker::LINKMETHOD_REDIRECT) {
         $affiliateLink = "";
     } elseif(Pap_Tracking_ClickTracker::getInstance()->getLinkingMethod() == Pap_Tracking_ClickTracker::LINKMETHOD_ANCHOR
            && Gpf_Settings::get(Pap_Settings::SUPPORT_SHORT_ANCHOR_LINKING) == GPF::YES) {
         $affiliateLink = $mainSiteUrl . "#" . $user->getRefId();
     } else {
         $affiliateLink = Pap_Tracking_ClickTracker::getInstance()->getClickUrl(null, $user, $mainSiteUrl);
     }
     return $affiliateLink;
 }
 /**
  *
  * @service affiliate_invoice read
  * @param $fields
  */
 public function previewInvoice(Gpf_Rpc_Params $params) {
     $form = new Gpf_Rpc_Form($params);
     
     $user = new Pap_Affiliates_User();
     
     $applyVat = $form->getFieldValue('applyVat');
     $payoutInvoice = $form->getFieldValue('payoutInvoice');
     
     
     $user->setId($form->getFieldValue('userid'));
     try {
         $user->load();
     } catch (Gpf_Exception $e) {
         $this->invoiceHtml = $this->_("You have to select user");
         return $this;
     }
     
     $currency = Pap_Common_Utils_CurrencyUtils::getDefaultCurrency();
     $payout = new Pap_Common_Payout($user, $currency, 1, 123456);
     $payout->setApplyVat($applyVat);
     $payout->generateInvoice($payoutInvoice);
     $this->invoiceHtml = $payout->getInvoice(); 
     return $this;
 }
    public function sendInviteMail(Pap_Common_Campaign $campaign, $userID) {
        if(Gpf::NO == Gpf_Settings::get(Pap_Settings::AFF_NOTIFICATION_CAMPAIGN_INVITATION)){
            return;
        }

        $affiliate = new Pap_Affiliates_User();
        $affiliate->setId($userID);
        try {
            $affiliate->load();

            $mail = new Pap_Mail_InviteToCampaign();
            $mail->setCampaign($campaign);
            $mail->setUser($affiliate);
            $mail->addRecipient($affiliate->getEmail());
            $mail->send();
        } catch (Gpf_Exception $e) {
        }
    }
Beispiel #9
0
 /**
  * @param $userid
  * @return Pap_Affiliates_User
  * @throws Gpf_Exception
  */
 private static function loadFromUserid($userid)
 {
     $user = new Pap_Affiliates_User();
     $user->setPrimaryKeyValue($userid);
     $user->load();
     return $user;
 }
 private function assignParent(Pap_Affiliates_User $affiliate) {
     if ($affiliate->getParentUser() == null && ($parentUserId = Gpf_Settings::get(Pap_Settings::ASSIGN_NON_REFERRED_AFFILIATE_TO)) != '') {
         try {
             $parentUser = new Pap_Affiliates_User();
             $parentUser->setId($parentUserId);
             $parentUser->load();
             $affiliate->setParentUserId($parentUser->getId());
         } catch (Gpf_Exception $e) {
         }
         Gpf_Plugins_Engine::extensionPoint('PostAffiliate.AffiliateForm.assignParent', $affiliate);
     }
 }
    /**
     * @param array $payoutOptionData
     */
    private function processPayoutOption($payoutOptionData, $row) {
        $user = new Pap_Affiliates_User();
        $user->setId($payoutOptionData[Pap_Db_Table_UserPayoutOptions::USERID]);
        try {
            $user->load();

            $payoutOption = new Pap_Db_PayoutOption();
            $payoutOption->setID($user->getPayoutOptionId());
            $payoutOption->load();

            $payoutField = new Gpf_Db_FormField();
            $payoutField->setFormId($payoutOption->getFormId());
            $payoutField->setCode($payoutOptionData[Gpf_Db_Table_FormFields::CODE]);
            $payoutField->loadFromData(array(Gpf_Db_Table_FormFields::FORMID, Gpf_Db_Table_FormFields::CODE));

            $userPayoutOption = new Pap_Db_UserPayoutOption();
            $userPayoutOption->setUserId($payoutOptionData[Pap_Db_Table_UserPayoutOptions::USERID]);
            $userPayoutOption->setFormFieldId($payoutField->getId());
            $userPayoutOption->setValue($payoutOptionData[Pap_Db_Table_UserPayoutOptions::VALUE]);
            $userPayoutOption->save();
            $this->incrementSuccessfulCount();
            $this->logger->debug('Data from line: ' . $this->getFile()->getActualCSVLineNumber() . ' was inserted.');
        } catch (Gpf_Exception $e) {
        	$this->logError('Payout option', $row, $e);
        	$this->appendOutputMessage($this->getSaveErrorMessage($this->getFile()->getActualCSVLineNumber(), $e->getMessage()));
            $this->incrementWrongCount();
        }
    }