예제 #1
0
    /**
     * @service channel write
     *
     * @param $fields
     * @return Gpf_Rpc_Action
     */
    public function saveFields(Gpf_Rpc_Params $params) {
        $action = new Gpf_Rpc_Action($params);
        $action->setErrorMessage($this->_('Failed to save %s field(s)'));
        $action->setInfoMessage($this->_('%s field(s) successfully saved'));
        
        $fields = new Gpf_Data_RecordSet();
        $fields->loadFromArray($action->getParam("fields"));
        
        $channels = Pap_Db_Table_Channels::getUserChannels(Gpf_Session::getAuthUser()->getPapUserId());
        
        foreach ($fields as $field) {
        	$isUnique = true;
        	foreach ($channels as $channel) {
        		if ($field->get('value') == $channel->get(Pap_Db_Table_Channels::VALUE)) {
        			$isUnique = false;
        			break;
        		}
        	}
        	if ($isUnique) {
        		$this->saveField($field);
        	} else {
        		$action->setErrorMessage($this->_("Failed to save %s field(s). Data with value '".$field->get('value').
        		  "' already exist. Data must be unique."));
        		$action->addError();
        		return $action;
        	}
        }

        $action->addOk();

        return $action;
    }
	/**
     * @return Gpf_SqlBuilder_SelectBuilder
     */
    protected function createSelectBuilder() {
    	$selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
        $selectBuilder->select->add(Pap_Db_Table_Channels::ID, self::ID);
        $selectBuilder->select->add(Pap_Db_Table_Channels::NAME, self::VALUE);
        $selectBuilder->from->add(Pap_Db_Table_Channels::getName());
      
        return $selectBuilder;
    }
 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");
 }
예제 #4
0
 public function loadChannels() {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add(Pap_Db_Table_Channels::VALUE);
     $select->select->add(Pap_Db_Table_Channels::NAME);
     $select->from->add(Pap_Db_Table_Channels::getName());
     $select->where->add(Pap_Db_Table_Channels::USER_ID, '=', Gpf_Session::getAuthUser()->getPapUserId());
     
     $this->channels = array();
     foreach ($select->getAllRowsIterator() as $row) {
         $this->channels[$row->get(Pap_Db_Table_Channels::VALUE)] = $row->get(Pap_Db_Table_Channels::NAME);
     }
 }
예제 #5
0
 private function generateDefaultValue($userId) {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add('MAX(CAST(SUBSTR('.Pap_Db_Table_Channels::VALUE.', 5) AS UNSIGNED))', 'max');
     $select->from->add(Pap_Db_Table_Channels::getName());
     $select->where->add(Pap_Db_Table_Channels::VALUE, 'like', 'code%');
     $select->where->add(Pap_Db_Table_Channels::USER_ID, '=', $userId);
     try {
         $result = $select->getOneRow();
         $max = $result->get('max')+1;
     } catch (Gpf_DbEngine_NoRowException $e) {
         $max = 1;
     } catch (Gpf_DbEngine_TooManyRowsException $e) {
         Gpf_Log::error('Database not in consistent state. Error in qu_pap_channels.');
     }
     if (isset($max)) {
         return 'code'.$max;
     }
     return 'code';
 }
 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);
 }
예제 #7
0
 public function init() {
     $this->setTable(Pap_Db_Table_Channels::getInstance());
     parent::init();
 }
 protected function initChannelsSelect() {
     $this->channelsSelect = new Gpf_SqlBuilder_SelectBuilder();
     $this->channelsSelect->select->add(Pap_Db_Table_Channels::ID);
     $this->channelsSelect->select->add(Pap_Db_Table_Channels::NAME);
     $this->channelsSelect->from->add(Pap_Db_Table_Channels::getName());
     $this->channelsSelect->where->add(Pap_Db_Table_Channels::USER_ID, '=', Gpf_Session::getAuthUser()->getPapUserId());
 }
예제 #9
0
	protected function buildFrom() {
		$this->_selectBuilder->from->addSubselect($this->rawClicksSelect, "rc");
		$onCondition = "rc.".Pap_Db_Table_RawClicks::CAMPAIGNID." = c.".Pap_Db_Table_Campaigns::ID;
		$this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Campaigns::getName(), 'c', $onCondition);
		$this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Banners::getName(), 'b', "rc.bannerid = b.bannerid");
		$this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Banners::getName(), 'pb', "rc.parentbannerid = pb.bannerid");
		$this->_selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), "pu", "rc.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=rc.channel');
	}
예제 #10
0
 public static function getInstance() {
     if(self::$instance === null) {
         self::$instance = new self;
     }
     return self::$instance;
 }
 protected function buildFrom() {
     $this->_selectBuilder->from->add(Pap_Db_Table_VisitorAffiliates::getName(), "va");
     $onCondition = "va.".Pap_Db_Table_VisitorAffiliates::CAMPAIGNID." = 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", "va.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", "va.channelid = ch.channelid");
     $this->_selectBuilder->from->addLeftJoin(Pap_Db_Table_Banners::getName(), 'b', 'b.bannerid = va.bannerid');
     Gpf_Plugins_Engine::extensionPoint('AffiliateNetwork.modifyFrom',
     new Gpf_Common_SelectBuilderCompoundRecord($this->_selectBuilder,
     new Gpf_Data_Record(array('joinedAlias', 'onJoinAlias'), array('a', 'va'))));
 }