Exemplo n.º 1
0
 	public function process(Pap_Db_Table_Users $context) {
 	    $context->addConstraint(new Gpf_DbEngine_Row_RefIdLengthConstraint(
                                            Pap_Db_Table_Users::REFID,
                                            Gpf_Settings::get(self::SETTING_REFID_MIN_LENGTH),
                                            Gpf_Settings::get(self::SETTING_REFID_MAX_LENGTH),
                                            $this->_('Referral id must be longer than %s characters'),
                                            $this->_('Referral id can not be longer than %s characters')));
		return Gpf_Plugins_Engine::PROCESS_CONTINUE;
 	}
    /**
     *
     * @service affiliate_stats read
     * @param $data
     */
    public function load(Gpf_Rpc_Params $params) {
        $data = new Gpf_Rpc_Data($params);
        $filters = $data->getFilters();
		$statsParams = new Pap_Stats_Params();
		$statsParams->initFrom($filters);				
		$transactions = new Pap_Stats_Transactions($statsParams);                

        $select = new Gpf_SqlBuilder_SelectBuilder();
        $select->from->add(Pap_Db_Table_Users::getName(), "pu");
        $select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), "gu", "gu.accountuserid = pu.accountuserid");
        $select->select->add("SUM(IF(pu.rtype = '". Pap_Application::ROLETYPE_AFFILIATE ."', 1, 0))", "countAffiliates");
        $select->select->add("SUM(IF(gu.rstatus = 'A', 1, 0))", "approvedAffiliates");
        $select->select->add("SUM(IF(gu.rstatus = 'P', 1, 0))", "pendingAffiliates");
        $filters->addTo($select->where);
        $select->where->add("pu.".Pap_Db_Table_Users::TYPE, "=", Pap_Application::ROLETYPE_AFFILIATE);        
        $row = $select->getOneRow();

        $data->setValue("countAffiliates", $this->checkNullValue($row->get("countAffiliates")));
        $data->setValue("approvedAffiliates", $this->checkNullValue($row->get("approvedAffiliates")));
        $data->setValue("pendingAffiliates", $this->checkNullValue($row->get("pendingAffiliates")));
        $data->setValue("totalSales", $transactions->getTotalCost()->getAll());
        $data->setValue("approvedCommissions", $transactions->getCommission()->getApproved());
        $data->setValue("pendingCommissions", $transactions->getCommission()->getPending());

        return $data;
    }
    public function getNumberOfSubaffiliates($userid = null) {
        $result = new Gpf_Data_RecordSet();
        $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
        $selectBuilder->select->add('COUNT(u.userid)', 'amount');

        $selectBuilder->from->add(Pap_Db_Table_Users::getName(), "u");
        $selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(), "gu", "u.accountuserid = gu.accountuserid");
        $selectBuilder->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), "au", "gu.authid = au.authid");

        $selectBuilder->where->add('u.deleted', '=', Gpf::NO);
        if ($userid === null) {
            $selectBuilder->where->add('u.parentuserid', '=', Gpf_Session::getAuthUser()->getPapUserId());
        } else {
            $selectBuilder->where->add('u.parentuserid', '=', $userid);
        }
        $selectBuilder->where->add('gu.rstatus', '<>', 'D');
        if ($this->params->isDateFromDefined()) {
            $selectBuilder->where->add('u.' . Pap_Stats_Table::DATEINSERTED, '>=', $this->params->getDateFrom()->toDateTime());
        }
        if ($this->params->isDateToDefined()) {
            $selectBuilder->where->add('u.' . Pap_Stats_Table::DATEINSERTED, '<=', $this->params->getDateTo()->toDateTime());
        }
        $selectBuilder->limit->set(0, 1);

        $result->load($selectBuilder);

        if($result->getSize() == 0) {
            return 0;
        }

        foreach($result as $record) {
            return $record->get('amount');
        }
    }
    /**
     * @service pay_affiliate read
     * @param $data
     */
    public function load(Gpf_Rpc_Params $params) {
        $data = new Gpf_Rpc_Data($params);

        $select = new Gpf_SqlBuilder_SelectBuilder();
        $select->select->add("au.username","userName");
        $select->select->add("au.firstname","firstName");
        $select->select->add("au.lastname","lastname");
        $select->select->add("SUM(t.".Pap_Db_Table_Transactions::COMMISSION.")", "payout");
        $select->select->add("pu.".Pap_Db_Table_Users::MINIMUM_PAYOUT, "minimumPayout");
        $select->select->add("IFNULL(po.".Gpf_Db_Table_FieldGroups::NAME.", 'undefined')", "payoutMethod");
        $select->from->add(Pap_Db_Table_Transactions::getName(), "t");
        $select->from->addInnerJoin(Pap_Db_Table_Users::getName(), "pu", "t.userid = pu.userid");
        $select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), "gu", "pu.accountuserid = gu.accountuserid");
        $select->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), "au", "gu.authid = au.authid");
        $select->groupBy->add("t.".Pap_Db_Table_Transactions::USER_ID);
        $select->from->addLeftJoin(Gpf_Db_Table_FieldGroups::getName(), "po", "pu.payoutoptionid = po.fieldgroupid");
        $select->where->add("t.".Pap_Db_Table_Transactions::USER_ID, "=", $params->get("id"));
        $row = $select->getOneRow();

        $data->setValue("userName", $row->get("userName"));
        $data->setValue("firstName", $row->get("firstName"));
        $data->setValue("lastname", $row->get("lastname"));
        $data->setValue("payout", $row->get("payout"));
        $data->setValue("minimumPayout", $row->get("minimumPayout"));
        $data->setValue("payoutMethod", $row->get("payoutMethod"));

        return $data;
    }
Exemplo n.º 5
0
	/**
	 * @return array
	 */
	public function getChildren(Pap_Common_User $parent, $offset = '', $limit = '') {
		$children = array();

		$selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
		$selectBuilder->select->addAll(Pap_Db_Table_Users::getInstance(), 'pu');
		$selectBuilder->select->addAll(Gpf_Db_Table_AuthUsers::getInstance(), 'au');

		$selectBuilder->from->add(Pap_Db_Table_Users::getName(), 'pu');
		$selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'gu', 'pu.accountuserid = gu.accountuserid');
		$selectBuilder->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au', 'gu.authid = au.authid');

		$selectBuilder->where->add(Pap_Db_Table_Users::PARENTUSERID, '=', $parent->getId());
		$selectBuilder->where->add(Gpf_Db_Table_Users::STATUS, 'IN', array(Pap_Common_Constants::STATUS_APPROVED, Pap_Common_Constants::STATUS_PENDING));
		$selectBuilder->orderBy->add(Pap_Db_Table_Users::DATEINSERTED);

		$selectBuilder->limit->set($offset, $limit);
			
		foreach ($selectBuilder->getAllRowsIterator() as $userRecord) {
			$user = new Pap_Common_User();
			$user->fillFromRecord($userRecord);
			$children[] = $user;
		}

		return $children;
	}
Exemplo n.º 6
0
 function buildFrom() {       
     $this->_selectBuilder->from->add(Pap_Db_Table_Payouts::getName(), "p"); 
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), "pu", "p.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(Gpf_Db_Table_FieldGroups::getName(), "po", "pu.payoutoptionid = po.fieldgroupid");
     $this->_selectBuilder->from->addLeftJoin(Gpf_Db_Table_Currencies::getName(), "c", "p.currencyid = c.currencyid");
 }
 function buildFrom() {
     $this->_selectBuilder->from->add(Pap_Db_Table_Payouts::getName(), "p");
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_PayoutsHistory::getName(), "ph", "p.payouthistoryid = ph.payouthistoryid");
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), "pu", "p.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(Gpf_Db_Table_Currencies::getName(), "c", "p.currencyid = c.currencyid");
 }
 protected function buildFrom() {
     $this->_selectBuilder->from->add(Pap_Db_Table_Coupons::getName(), 'c');
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(),
         'pu', 'pu.'.Pap_Db_Table_Users::ID.'=c.'.Pap_Db_Table_Coupons::USERID);
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(),
         'gu', 'pu.'.Pap_Db_Table_Users::ACCOUNTUSERID.'=gu.'.Gpf_Db_Table_Users::ID);
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(),
         'au', 'au.'.Gpf_Db_Table_AuthUsers::ID.'=gu.'.Gpf_Db_Table_Users::AUTHID);
 }
Exemplo n.º 9
0
 private function updateThemeExistingAffiliates($themeId) {
     $update = new Gpf_SqlBuilder_UpdateBuilder();
     $update->from->add(Gpf_Db_Table_UserAttributes::getName(), 'ua');
     $update->from->addInnerJoin(Pap_Db_Table_Users::getName(), 'pu', 'ua.'.Gpf_Db_Table_UserAttributes::ACCOUNT_USER_ID.'=pu.'.Pap_Db_Table_Users::ACCOUNTUSERID);
     $update->set->add('ua.'.Gpf_Db_Table_UserAttributes::VALUE, $themeId);
     $update->where->add('ua.'.Gpf_Db_Table_UserAttributes::NAME, '=', Gpf_Auth_User::THEME_ATTRIBUTE_NAME);
     $update->where->add('pu.'.Pap_Db_Table_Users::TYPE, '=', Pap_Application::ROLETYPE_AFFILIATE);
     $update->update();
 }
 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');
 }
Exemplo n.º 11
0
 /**
  *
  * @param $transaction
  * @return Gpf_Data_Record
  */
 protected function getChildAffiliateInfo(Pap_Common_Transaction $transaction){
     $userSelect = new Gpf_SqlBuilder_SelectBuilder();
     $userSelect->select->add('t.'.Pap_Db_Table_Transactions::USER_ID);
     $userSelect->select->add('u.'.Pap_Db_Table_Users::DATEINSERTED);
     $userSelect->from->add(Pap_Db_Table_Transactions::getName(),'t');
     $userSelect->from->addInnerJoin(Pap_Db_Table_Users::getName(),'u','t.userid=u.userid');
     $userSelect->where->add('t.'.Pap_Db_Table_Transactions::TRANSACTION_ID,'=',$transaction->getParentTransactionId());
     return $userSelect->getOneRow();
 }
 protected function buildFrom() {
     $this->_selectBuilder->from->add(Pap_Db_Table_DirectLinkUrls::getName(), "l");
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), "pu", "l.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", "ch.channelid = l.channelid");
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Banners::getName(), "b", "b.bannerid = l.bannerid");
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Campaigns::getName(), "c", "c.campaignid = l.campaignid");
 }
Exemplo n.º 13
0
 protected function buildFrom() {
     $this->_selectBuilder->from->add(Pap_Db_Table_Users::getName(), 'u');
     $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');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Accounts::getName(),
         'a', 'a.accountid=gu.accountid');
     $this->_selectBuilder->from->addInnerJoin(Gpf_Db_Table_Roles::getName(),
         'r', 'r.roleid=gu.roleid');
 }
 function buildFrom() {
     $this->_selectBuilder->from->add(Pap_Db_Table_RecurringCommissions::getName(), 'rc');
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_RecurringCommissionEntries::getName(),
         "rce", "rce.recurringcommissionid = rc.recurringcommissionid AND rce.tier = 1");
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Users::getName(), "pu", "rce.userid = pu.userid");
     $this->_selectBuilder->from->addLeftJoin(Gpf_Db_Table_Users::getName(), "gu", "pu.accountuserid = gu.accountuserid");
     $this->_selectBuilder->from->addLeftJoin(Gpf_Db_Table_AuthUsers::getName(), "au", "gu.authid = au.authid");
     
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Transactions::getName(), "t", "t.transid = rc.transid");
     $this->_selectBuilder->from->addLeftJoin(Gpf_Db_Table_RecurrencePresets::getName(), 'rp', 'rp.recurrencepresetid = rc.recurrencepresetid');
 }
 protected function buildFrom() {
 	$this->_selectBuilder->from->add(Pap_Db_Table_UserInCommissionGroup::getName(), 'ucg');
 	$this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_CommissionGroups::getName(), 'cg',
 	    'cg.'.Pap_Db_Table_CommissionGroups::ID.'=ucg.'.Pap_Db_Table_UserInCommissionGroup::COMMISSION_GROUP_ID);
     $this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), 
         'u', 'ucg.userid=u.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');
 }
Exemplo n.º 16
0
 protected function getUserId($username) {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add('pu.'.Pap_Db_Table_Users::ID, 'id');
     $select->from->add(Pap_Db_Table_Users::getName(), 'pu');
     $select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'gu',
         'pu.'.Pap_Db_Table_Users::ACCOUNTUSERID.'=gu.'.Gpf_Db_Table_Users::ID);
     $select->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au',
         'gu.'.Gpf_Db_Table_Users::AUTHID.'=au.'.Gpf_Db_Table_AuthUsers::ID);
     $select->where->add('pu.'.Pap_Db_Table_Users::TYPE, '=', Pap_Application::ROLETYPE_AFFILIATE);
     $select->where->add('pu.'.Pap_Db_Table_Users::DELETED, '<>', Gpf::YES);
     $select->where->add('au.'.Gpf_Db_Table_AuthUsers::USERNAME, '=', $username);
     return $select->getOneRow()->get('id');
 }
Exemplo n.º 17
0
    /**
     * @throws Gpf_DbEngine_NoRowException
     * @return Pap_Common_User
     */
    public function getMerchant() {
    	$select = new Gpf_SqlBuilder_SelectBuilder();
		$select->select->add('pu.'.Pap_Db_Table_Users::ID, Pap_Db_Table_Users::ID);
		$select->from->add(Pap_Db_Table_Users::getName(), 'pu');
		$select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'gu',
		'pu.'.Pap_Db_Table_Users::ACCOUNTUSERID.'=gu.'.Gpf_Db_Table_Users::ID);
		$select->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au',
		'au.'.Gpf_Db_Table_AuthUsers::ID.'=gu.'.Gpf_Db_Table_Users::AUTHID);
		$select->where->add('au.'.Gpf_Db_Table_AuthUsers::USERNAME, '=', $this->getEmail());
		$select->where->add('gu.'.Gpf_Db_Table_Users::ACCOUNTID, '=', $this->getId());
		$merchantId = $select->getOneRow()->get(Pap_Db_Table_Users::ID);
		
		return Pap_Merchants_User::getUserById($merchantId);
    }
Exemplo n.º 18
0
	protected function buildData(Gpf_Data_RecordSet $fields, Gpf_Rpc_Params $params) {
		$select = new Gpf_SqlBuilder_SelectBuilder();        
        $select->select->add("name", "payoutFieldName", "ff");
        $select->select->add(Pap_Db_Table_UserPayoutOptions::VALUE, Pap_Db_Table_UserPayoutOptions::VALUE, "upo");
        $select->select->add(Pap_Db_Table_UserPayoutOptions::FORMFIELDID, Pap_Db_Table_UserPayoutOptions::FORMFIELDID, "upo");
        $select->from->add(Pap_Db_Table_Users::getName(), "pu");
        $select->from->addInnerJoin(Gpf_Db_Table_FormFields::getName(), "ff", "(ff.formid = CONCAT('payout_option_', pu.payoutoptionid))");
        $select->from->addInnerJoin(Pap_Db_Table_UserPayoutOptions::getName(), "upo", "(pu.userid = upo.userid AND ff.formfieldid = upo.formfieldid)");
        $select->where->add("pu.userid", "=", $params->get('userid'));       
        
        $i = 1;
		foreach ($select->getAllRowsIterator() as $payoutField) {
			$fields->add(array($payoutField->get(Pap_Db_Table_UserPayoutOptions::FORMFIELDID), 
								'data' . $i, 
								$this->_($payoutField->get('payoutFieldName')), 'T', 'M', null, ''));
			$this->fieldValues['data' . $i++] = $payoutField->get(Pap_Db_Table_UserPayoutOptions::VALUE);			
		}
	}
Exemplo n.º 19
0
 /**
  * @param Gpf_Auth_Info $authInfo
  * @return Gpf_SqlBuilder_SelectBuilder
  */
 protected function createAuthSelect(Gpf_Auth_Info $authInfo) {
     $select = parent::createAuthSelect($authInfo);
     $select->select->add('pu.'.Pap_Db_Table_Users::REFID, 'refid');
     $select->select->add('pu.'.Pap_Db_Table_Users::NUMBERUSERID, 'numberuserid');
     $select->select->add('pu.'.Pap_Db_Table_Users::PHOTO, 'photo');
     for ($i=1; $i<=25; $i++) {
         $select->select->add('pu.'.Pap_Db_Table_Users::getDataColumnName($i), 'data'.$i);
     }
     $select->select->add('pu.'.Pap_Db_Table_Users::PARENTUSERID, Pap_Db_Table_Users::PARENTUSERID);
     $select->select->add('pu.'.Pap_Db_Table_Users::ID, 'userid');
     $select->select->add('pu.'.Pap_Db_Table_Users::TYPE, 'rtype');
     $select->select->add('pu.'.Pap_Db_Table_Users::DATEINSERTED, 'dateinserted');
     $select->select->add('pu.'.Pap_Db_Table_Users::DATEAPPROVED, 'dateapproved');
     $select->from->addInnerJoin(Pap_Db_Table_Users::getName(), 'pu',
         'pu.accountuserid=u.accountuserid');
     $select->where->add('pu.'.Pap_Db_Table_Users::TYPE, '=', $authInfo->getRoleType());
     return $select;
 }
 /**
  * @return Gpf_SqlBuilder_SelectBuilder
  */
 private function getAffiliatesToPaySelect($payoutOptionId = null) {
     $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
     $selectBuilder->select->addAll(Pap_Db_Table_Users::getInstance(), 'pu');
     $selectBuilder->select->addAll(Gpf_Db_Table_AuthUsers::getInstance(), 'au');
     $selectBuilder->select->add('SUM('.Pap_Db_Table_Transactions::COMMISSION.')', 'amountRaw');
     
     $selectBuilder->from->add(Pap_Db_Table_Transactions::getName(), 't');    
     $selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), 'pu', 't.userid = pu.userid');
     $selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'gu', 'pu.accountuserid = gu.accountuserid');
     $selectBuilder->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au', 'gu.authid = au.authid');
     
     if ($payoutOptionId != null) {
         $selectBuilder->where->add('pu.'.Pap_Db_Table_Users::PAYOUTOPTION_ID, '=', $payoutOptionId);
     }
     $selectBuilder->where->add('t.'.Pap_Db_Table_Transactions::PAYOUTHISTORY_ID, '=', Pap_Common_Transaction::PAYMENT_PENDING_ID);
     $selectBuilder->groupBy->add(Pap_Db_Table_Transactions::USER_ID);
     
     return $selectBuilder;
 }
 /**
  * @return Gpf_SqlBuilder_SelectBuilder
  */
 protected function createSelectBuilder() {
 	$select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add("users.".Pap_Db_Table_Users::ID, self::ID);
     $select->select->add("users.".Pap_Db_Table_Users::REFID, 'refid');
     $select->select->add("authUsers.".Gpf_Db_Table_AuthUsers::USERNAME, 'username');
     $select->select->add("authUsers.".Gpf_Db_Table_AuthUsers::FIRSTNAME, 'firstname');
     $select->select->add("authUsers.".Gpf_Db_Table_AuthUsers::LASTNAME, 'lastname');
     $select->from->add(Pap_Db_Table_Users::getName(), 'users');
     $select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'accountUsers',
         'users.'.Pap_Db_Table_Users::ACCOUNTUSERID."=accountUsers.".Gpf_Db_Table_Users::ID);
     $select->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'authUsers',
         "accountUsers.".Gpf_Db_Table_Users::AUTHID."=authUsers.".Gpf_Db_Table_AuthUsers::ID);
     $select->where->add('users.'.Pap_Db_Table_Users::TYPE,
         '=', Pap_Application::ROLETYPE_AFFILIATE);
     $select->where->add('users.'.Pap_Db_Table_Users::DELETED,
         '<>', Gpf::YES);
     $select->orderBy->add("authUsers.".Gpf_Db_Table_AuthUsers::USERNAME);
     $this->modifySelect($select);
   
     return $select;
 }
Exemplo n.º 22
0
	/**
	 *
	 * Pap alert application handle, do not modify this source!
	 *
	 * @param String $dateFrom
	 * @param String $dateTo
	 * @param String $userId
	 * @return Gpf_Data_RecordSet
	 */
	public static function getTransactions(Pap_Stats_Params $statsParams) {
		$select = new Gpf_SqlBuilder_SelectBuilder();
		$select->select->add('tr.'.Pap_Db_Table_Transactions::USER_ID, 'userid');
		$select->select->add('au.'.Gpf_Db_Table_AuthUsers::FIRSTNAME, 'name');
		$select->select->add('au.'.Gpf_Db_Table_AuthUsers::LASTNAME, 'surname');
		$select->select->add('au.'.Gpf_Db_Table_AuthUsers::USERNAME, 'username');
		$select->select->add('pu.data1', 'weburl');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::TRANSACTION_ID, 'transid');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::TOTAL_COST, 'totalcost');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::FIXED_COST, 'fixedcost');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::ORDER_ID, 'orderid');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::PRODUCT_ID, 'productid');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::DATE_INSERTED, 'dateinserted');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::R_STATUS, 'rstatus');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::R_TYPE, 'transtype');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::PARRENT_TRANSACTION_ID, 'transkind');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::PAYOUT_STATUS, 'payoutstatus');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::DATE_APPROVED, 'dateapproved');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::COMMISSION, 'commission');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::REFERER_URL, 'refererurl');
		$select->select->add('c.'.Pap_Db_Table_Campaigns::ID, 'campcategoryid');
        $select->select->add('c.'.Pap_Db_Table_Campaigns::NAME, 'campaign');
		$select->select->add('tr.data1', 'data1');
		$select->select->add('tr.data2', 'data2');
		$select->select->add('tr.data3', 'data3');
		$select->select->add('tr.'.Pap_Db_Table_Transactions::COUNTRY_CODE, 'countrycode');
		$select->from->add(Pap_Db_Table_Transactions::getName(), 'tr');
		$select->from->addInnerJoin(Pap_Db_Table_Campaigns::getName(), 'c',
            'tr.'.Pap_Db_Table_Transactions::CAMPAIGN_ID.'=c.'.Pap_Db_Table_Campaigns::ID);
		$select->from->addInnerJoin(Pap_Db_Table_Users::getName(), 'pu',
            'tr.'.Pap_Db_Table_Transactions::USER_ID.'=pu.'.Pap_Db_Table_Users::ID);
		$select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'gu',
            'gu.'.Gpf_Db_Table_Users::ID.'=pu.'.Pap_Db_Table_Users::ACCOUNTUSERID);
		$select->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au',
            'gu.'.Gpf_Db_Table_Users::AUTHID.'=au.'.Gpf_Db_Table_AuthUsers::ID);

		if ($statsParams->isDateFromDefined()) {
			$select->where->add('tr.'.Pap_Db_Table_Transactions::DATE_INSERTED, '>=', $statsParams->getDateFrom()->toDateTime());
		}
		if ($statsParams->isDateToDefined()) {
			$select->where->add('tr.'.Pap_Db_Table_Transactions::DATE_INSERTED, '<=', $statsParams->getDateTo()->toDateTime());
		}
		if ($statsParams->getAffiliateId() != '') {
			$select->where->add('tr.'.Pap_Db_Table_Transactions::USER_ID, '=', $statsParams->getAffiliateId());
		}

		return $select->getAllRows();
	}
Exemplo n.º 23
0
 	public function addRefidConstraint(Pap_Db_Table_Users $usersTable) {
        $usersTable->addConstraint(new MandatoryRefid_Constraint());
		return Gpf_Plugins_Engine::PROCESS_CONTINUE;
 	}
 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);
 }
    public function getUsersInCommissionGroupCount($campaignId) {
        $selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
        $selectBuilder->select->add('COUNT(*)', 'count');
        $selectBuilder->from->add(Pap_Db_Table_UserInCommissionGroup::getName(), 'ucg');
        $selectBuilder->from->addInnerJoin(Pap_Db_Table_CommissionGroups::getName(), 'cg',
             'cg.'.Pap_Db_Table_CommissionGroups::ID.'=ucg.'.Pap_Db_Table_UserInCommissionGroup::COMMISSION_GROUP_ID);
        $selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), 'pu',
             'pu.'.Pap_Db_Table_Users::ID.'=ucg.'.Pap_Db_Table_UserInCommissionGroup::USER_ID);
        $selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'u',
             'u.'.Gpf_Db_Table_Users::ID.'=pu.'.Pap_Db_Table_Users::ACCOUNTUSERID);
        $selectBuilder->where->add('cg.'.Pap_Db_Table_CommissionGroups::CAMPAIGN_ID, '=', $campaignId);
        $selectBuilder->where->add('pu.' . Pap_Db_Table_Users::TYPE, '=', Pap_Application::ROLETYPE_AFFILIATE);
        $selectBuilder->where->add('u.'.Gpf_Db_Table_Users::STATUS, '=', Gpf_Db_User::APPROVED);
        $selectBuilder->where->add('pu.'.Pap_Db_Table_Users::DELETED, '=', Gpf::NO);

        try {
            $commissionGroupId = $selectBuilder->getOneRow();
        } catch (Gpf_DbEngine_NoRowException $e) {
            return null;
        }
        return $selectBuilder->getOneRow()->get('count');
    }
    /**
     * @service pay_affiliate read
     * @param $fields
     * @throws Gpf_Exception
     */
    public function payeesDetails(Gpf_Rpc_Params $params) {
        $data = new Gpf_Rpc_Data($params);
        $idFilter = $data->getFilters()->getFilter('id');
        if (sizeof($data) != 1) {
            throw new Gpf_Exception('No id specified');
        }
        $id = $idFilter[0]->getValue();
        $payeeData = $this->getPayeeData(array($id));
        $i = 0;
        foreach($payeeData as $id => $payee) {
            foreach($payee['users'] as $user) {
                $payeeDataObject = new Gpf_Rpc_Data();
                $payeeDataObject->setValue(Gpf_Db_Table_AuthUsers::USERNAME, $user[Gpf_Db_Table_AuthUsers::USERNAME]);
                $payeeDataObject->setValue(Gpf_Db_Table_AuthUsers::FIRSTNAME, $user[Gpf_Db_Table_AuthUsers::FIRSTNAME]);
                $payeeDataObject->setValue(Gpf_Db_Table_AuthUsers::LASTNAME, $user[Gpf_Db_Table_AuthUsers::LASTNAME]);
                $payeeDataObject->setValue(Pap_Db_Table_Payouts::AMOUNT, $user[Pap_Db_Table_Payouts::AMOUNT]);
                $payeeDataObject->setValue(Pap_Db_Table_Users::getDataColumnName(3), $user[Pap_Db_Table_Users::getDataColumnName(3)]);
                $payeeDataObject->setValue(Pap_Db_Table_Users::getDataColumnName(4), $user[Pap_Db_Table_Users::getDataColumnName(4)]);
                $payeeDataObject->setValue(Pap_Db_Table_Users::getDataColumnName(5), $user[Pap_Db_Table_Users::getDataColumnName(5)]);
                $payeeDataObject->setValue(Pap_Db_Table_Users::getDataColumnName(6), $user[Pap_Db_Table_Users::getDataColumnName(6)]);
                $payeeDataObject->setValue(Pap_Db_Table_Users::getDataColumnName(7), $user[Pap_Db_Table_Users::getDataColumnName(7)]);
                $payeeDataObject->setValue(Pap_Db_Table_Users::getDataColumnName(8), $user[Pap_Db_Table_Users::getDataColumnName(8)]);
                $payeeDataObject->setValue(Pap_Db_Table_Users::getDataColumnName(9), $user[Pap_Db_Table_Users::getDataColumnName(9)]);
                $data->setValue("user$i", $payeeDataObject->toObject());
                $i++;
            }
        }

        return $data;
    }
 private function setUserFilter() {
     $this->sqlBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), 'u',
     self::TRANSACTION_ALIAS.'.'.Pap_Db_Table_Transactions::USER_ID.'='.'u.'.Pap_Db_Table_Users::ID);
     $this->sqlBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), 'up',
         'up.'.Pap_Db_Table_Users::PARENTUSERID.'='.'u.'.Pap_Db_Table_Users::PARENTUSERID);
     $this->sqlBuilder->where->add('up.'.Pap_Db_Table_Users::ID,'=', $this->rule->getUserId());
     $this->sqlBuilder->where->add('up.'.Pap_Db_Table_Users::PARENTUSERID,'!=', null);
 }
Exemplo n.º 28
0
 function init() {
     $this->setTable(Pap_Db_Table_Users::getInstance());
     parent::init();
 }
    /**
     * Get recordset of merchants recipients
     * 
     * @param $from
     * @return Gpf_Data_RecordSet
     */
    private function getMerchantsRecipients($from) {
        $select = new Gpf_SqlBuilder_SelectBuilder();
        $select->select->addAll(Gpf_Db_Table_AuthUsers::getInstance(), 'au');
        $select->select->addAll(Gpf_Db_Table_Accounts::getInstance(), 'a');
        $select->select->addAll(Gpf_Db_Table_Users::getInstance(), 'gu');
        $select->select->addAll(Pap_Db_Table_Users::getInstance(), 'u');
        $select->from->add(Pap_Db_Table_Users::getName(), 'u');
        $select->from->addInnerJoin(Gpf_Db_Table_Users::getName(), 'gu', 'u.'.Pap_Db_Table_Users::ACCOUNTUSERID.'=gu.'.Gpf_Db_Table_Users::ID.
        ' AND u.'.Pap_Db_Table_Users::DELETED . ' = \'' . Gpf::NO . '\''.
        ' AND u.' .Pap_Db_Table_Users::TYPE . ' = \'' . Pap_Application::ROLETYPE_MERCHANT . '\'');
        $select->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), 'au', 'au.'.Gpf_Db_Table_AuthUsers::ID.'=gu.'.Gpf_Db_Table_Users::AUTHID);
        $select->from->addInnerJoin(Gpf_Db_Table_Accounts::getName(), 'a', 'a.'.Gpf_Db_Table_Accounts::ID.'=gu.'.Gpf_Db_Table_Users::ACCOUNTID);
        $select->limit->set($from, Pap_Mail_MassMailAffiliatesGrid::MAX_ROWS_PER_SQL);

        return $select->getAllRows();
    }
	private function deleteAffiliates() {
		Pap3Compatibility_Migration_OutputWriter::logOnce("&nbsp;&nbsp;Deleting affiliates .....");
		// pap users
		$sql = new Gpf_SqlBuilder_DeleteBuilder();
    	$sql->from->add(Pap_Db_Table_Users::getName());
    	$sql->where->add('rtype', '=', 'A');
    	$sql->execute();

    	// g_users
    	$inSelect = new Gpf_SqlBuilder_SelectBuilder();
    	$inSelect->select->add(Pap_Db_Table_Users::ACCOUNTUSERID);
    	$inSelect->from->add(Pap_Db_Table_Users::getName());
		$sql = new Gpf_SqlBuilder_DeleteBuilder();
    	$sql->from->add(Gpf_Db_Table_Users::getName());
    	$sql->where->add('accountuserid', 'NOT IN', $inSelect, 'AND', false);
    	$sql->execute();

    	// g_authusers
    	$inSelect = new Gpf_SqlBuilder_SelectBuilder();
        $inSelect->select->add(Gpf_Db_Table_Users::AUTHID);
        $inSelect->from->add(Gpf_Db_Table_Users::getName());
		$sql = new Gpf_SqlBuilder_DeleteBuilder();
    	$sql->from->add(Gpf_Db_Table_AuthUsers::getName());
    	$sql->where->add('authid', 'NOT IN', $inSelect, 'AND', false);
    	$sql->execute();

    	// g_userattributes
    	$inSelect = new Gpf_SqlBuilder_SelectBuilder();
        $inSelect->select->add(Gpf_Db_Table_Users::ID);
        $inSelect->from->add(Gpf_Db_Table_Users::getName());
		$sql = new Gpf_SqlBuilder_DeleteBuilder();
    	$sql->from->add(Gpf_Db_Table_UserAttributes::getName());
    	$sql->where->add('accountuserid', 'NOT IN', $inSelect, 'AND', false);
    	$sql->execute();

    	// g_gadgets
    	$inSelect = new Gpf_SqlBuilder_SelectBuilder();
        $inSelect->select->add(Gpf_Db_Table_Users::ID);
        $inSelect->from->add(Gpf_Db_Table_Users::getName());
		$sql = new Gpf_SqlBuilder_DeleteBuilder();
    	$sql->from->add(Gpf_Db_Table_Gadgets::getName());
    	$sql->where->add('accountuserid', 'NOT IN', $inSelect, 'AND', false);
    	$sql->execute();

    	Pap3Compatibility_Migration_OutputWriter::log("DONE<br/>");
	}