Inheritance: implements Gpf_Rpc_DataEncoder, implements Gpf_Rpc_DataDecoder
Ejemplo n.º 1
0
    protected function execute() {
        $json = new Gpf_Rpc_Json();
        $processor = new Pap_Features_CompressedCommissionPlacementModel_Processor();
        if ($this->isPending('initAffiliatesList', $this->_('Initialization affiliates list'))) {
            $this->debug('initAffiliatesList');
            $this->userIds = $processor->initAffiliates();
            $this->setParams($json->encode($this->userIds));
            $this->setDone();
        }

        if ($this->isPending('initTransactionsList', $this->_('Initialization transactions list'))) {
            $this->debug('initTransactionsList');
            $this->userIds = $json->decode($this->getParams());
            $this->affectedTransactions = $processor->initTransactions($this->userIds);
            $this->setParams($json->encode($this->getTransactionIdsFromCollection($this->affectedTransactions)));
            $this->setDone();
        }
        $affectedTransactionIds = $this->getCollectionFromIds($json->decode($this->getParams()));
        $this->debug('process transactions');

        while ($affectedTransactionIds->getSize() > 0) {
            if ($this->isPending($this->getFirstElement($affectedTransactionIds)->getId(), $this->_('Compressed transaction: %s', $this->getFirstElement($affectedTransactionIds)->getId()))) {

                $processor->processFirstTransaction($affectedTransactionIds);
                $this->setDone();
            }
            else {
                $processor->removeByTransactionId($this->getFirstElement($affectedTransactionIds)->getId(), $affectedTransactionIds);
            }
        }
        $this->debug('finish task');
        $this->forceFinishTask();
    }
Ejemplo n.º 2
0
 private function removeMapOverlayFromAffiliatePanel() {
     $affMenu = Gpf_Settings::get(Pap_Settings::AFFILIATE_MENU);
     $json = new Gpf_Rpc_Json();
     $affMenuDecoded = $json->decode($affMenu);
     try {
         $affMenuDecoded = $this->removeMenuItem($affMenuDecoded, $this->getMapOverlayScreenId());
         Gpf_Settings::set(Pap_Settings::AFFILIATE_MENU,$json->encode($affMenuDecoded));
     } catch (Gpf_DbEngine_NoRowException $e) {
     }
 }
Ejemplo n.º 3
0
 protected function getRequestIdsIterator()
 {
     $json = new Gpf_Rpc_Json();
     $requestParams = new Gpf_Rpc_Params($json->decode($this->params->get(self::IDS_REQUEST)));
     $c = $requestParams->getClass();
     $gridService = new $c();
     if (!$gridService instanceof Gpf_View_GridService) {
         throw new Gpf_Exception(sprintf('%s is not Gpf_View_GridService class.', $requestParams->getClass()));
     }
     return $gridService->getIdsIterator($requestParams);
 }
Ejemplo n.º 4
0
 public static function render()
 {
     $encoder = new Gpf_Rpc_Json();
     $out = '';
     $response = self::getInstance();
     foreach ($response->encodedResponses as $id => $value) {
         $out .= 'window["' . $id . '"]="' . $value . '";';
     }
     foreach ($response->responses as $id => $value) {
         $out .= 'window["' . $id . '"]="' . addcslashes($encoder->encodeResponse($value), '"\\') . '";';
     }
     return '<script type="text/javascript">' . $out . '</script>';
 }
Ejemplo n.º 5
0
 public function execute() {
     $tree = Gpf_Settings::get(Pap_Settings::AFFILIATE_MENU);
     
     if (strpos($tree, '"data":{"code":')) {
         return;
     }
     
     $json = new Gpf_Rpc_Json();
     $tree = $json->decode($tree);
     
     $this->changeItem($tree);
     
     Gpf_Settings::set(Pap_Settings::AFFILIATE_MENU,$json->encode($tree));
 }
Ejemplo n.º 6
0
 /**
  * @param $request
  * @param $groupId
  * @param $validTo
  * @return string
  */
 public function __construct(Gpf_Rpc_Request $request, Gpf_DateTime $validTo = null)
 {
     parent::__construct();
     $json = new Gpf_Rpc_Json();
     if ($validTo === null) {
         $validTo = new Gpf_DateTime();
         $validTo->addDay(30);
     }
     $this->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId());
     $this->setGroupId('');
     $this->setRequest($json->encode($request->toObject()));
     $this->setValidTo($validTo->toDateTime());
     $this->insert();
     return $this;
 }
Ejemplo n.º 7
0
	public function execute(){
		$response = '';
		try {
			if(isset($_REQUEST['action'])){
				$action = @$_REQUEST['action'];
				$response = $this->createResponse($action);
			}else {
				$response = new Pap_Mobile_Response(false);
				$response->exception = Gpf_Lang::_('Unsupported action');
			}
		} catch (Gpf_Rpc_SessionExpiredException $e) {
			$response = new Pap_Mobile_Response(false);
			$response->exception = 'session_expired';
		} catch (Exception $e) {
			$response = new Pap_Mobile_Response(false);
			$response->exception = Gpf_Lang::_('Response failed on server: ').$e->getMessage();
			// 			$response->trace = $e->getTraceAsString();
		}
		$json = new Gpf_Rpc_Json();
		echo $json->encode($response);
	}
Ejemplo n.º 8
0
 private function addField($caption, $code, $type, $status, $help = '', $values = array())
 {
     $record = $this->fieldsRecordset->createRecord();
     $record->set('id', '0');
     $record->set('code', $code);
     $record->set('name', $caption);
     $record->set('help', $help);
     $record->set('type', $type);
     $record->set('status', $status);
     if (count($values) > 0) {
         $valuesRecordSet = new Gpf_Data_RecordSet();
         $valuesRecordSet->setHeader(array("id", "value"));
         foreach ($values as $id => $value) {
             if ($id != '') {
                 $valuesRecordSet->add(array($id, $value));
             }
         }
         $json = new Gpf_Rpc_Json();
         $record->set('availablevalues', $json->encode($valuesRecordSet->toObject()));
     }
     $this->fieldsRecordset->addRecord($record);
 }
 private function loadActions($actionsString) {
     if ($actionsString == '') {
         throw new Gpf_Exception($this->_('no actions in visit'));
     }
     $actionsArray = $this->json->decode($actionsString);
     if (!is_array($actionsArray)) {
         throw new Gpf_Exception($this->_('invalid action format (%s)', $actionsString));
     }
     $actions = array();
     foreach ($actionsArray as $actionObject) {
         $actions[] = new Pap_Tracking_Action_RequestActionObject($actionObject);
     }
     return $actions;
 }
Ejemplo n.º 10
0
 public function send()
 {
     $request = new Gpf_Rpc_Request($this->serverClassName, Gpf_Rpc_Server::RUN_METHOD);
     if ($this->useNewStyleRequestsEncoding) {
         $request->addParam(Gpf_Rpc_Server::REQUESTS_SHORT, $this->requests);
     } else {
         $request->addParam(Gpf_Rpc_Server::REQUESTS, $this->requests);
     }
     if ($this->sessionId != null) {
         $request->addParam("S", $this->sessionId);
     }
     $requestBody = $this->json->encodeResponse($request);
     $responseText = $this->sendRequest($requestBody);
     if ($this->debugRequests) {
         echo "REQUEST: " . $requestBody . "<br/>";
         echo "RESPONSE: " . $responseText . "<br/><br/>";
     }
     $responseArray = $this->json->decode($responseText);
     if (!is_array($responseArray)) {
         throw new Gpf_Exception("Response decoding failed: not array. Received text: {$responseText}");
     }
     if (count($responseArray) != $this->requests->getCount()) {
         throw new Gpf_Exception("Response decoding failed: Number of responses is not same as number of requests");
     }
     $exception = false;
     foreach ($responseArray as $index => $response) {
         if (is_object($response) && isset($response->e)) {
             $exception = true;
             $this->requests->get($index)->setResponseError($response->e);
         } else {
             $this->requests->get($index)->setResponse($response);
         }
     }
     if ($exception) {
         $messages = '';
         foreach ($this->requests as $request) {
             $messages .= $request->getResponseError() . "|";
         }
     }
     $this->requests = new Gpf_Rpc_Array();
     if ($exception) {
         throw new Gpf_Rpc_ExecutionException($messages);
     }
 }
Ejemplo n.º 11
0
 /**
  * array-walking function for use in generating JSON-formatted name-value pairs
  *
  * @param    string  $name   name of key to use
  * @param    mixed   $value  reference to an array element to be encoded
  *
  * @return   string  JSON-formatted name-value pair, like '"name":value'
  * @access   private
  */
 function name_value($name, $value)
 {
     $encoded_value = $this->encode($value);
     if (Gpf_Rpc_Json::isError($encoded_value)) {
         return $encoded_value;
     }
     return $this->encode(strval($name)) . ':' . $encoded_value;
 }
Ejemplo n.º 12
0
	function toString()
	{
		$json = new Gpf_Rpc_Json();
		return $json->encode( $this );
	}
Ejemplo n.º 13
0
 public function __construct($request)
 {
     $json = new Gpf_Rpc_Json();
     $this->params = new Gpf_Rpc_Params($json->decode($request));
     parent::__construct($this->params);
 }
Ejemplo n.º 14
0
 public function addAvailableValue($value, $label)
 {
     $record = $this->availableValues->createRecord();
     $record->set('id', $value);
     $record->set('name', $label);
     $this->availableValues->addRecord($record);
     $json = new Gpf_Rpc_Json();
     $this->setAvailableValues($json->encodeResponse($this->availableValues));
 }
Ejemplo n.º 15
0
 public function encode()
 {
     $json = new Gpf_Rpc_Json();
     return $json->encode($this);
 }
 protected function loadFromTask() {
     parent::loadFromTask();
     $json = new Gpf_Rpc_Json();
     $values = $json->decode($this->getParams());
     $this->paramsArray['papUserIds'] = $values->papUserIds;
 }
Ejemplo n.º 17
0
 private function addPostParams(Gpf_Rpc_Params $params) {        
     if ($params->exists('fields')) {
     	$json = new Gpf_Rpc_Json();
         foreach ($params->get('fields') as $field) {
             if (!$params->exists($field[0])) {
                 $decodedItem = $json->decode($field[1]);
                 if ($decodedItem !== null || $decodedItem != '') {
                     $params->add($field[0], $decodedItem);
                 } else {
                     $params->add($field[0], $field[1]);
                 }
             }
         }
     }
 }
Ejemplo n.º 18
0
 private function exportClientCacheFile($dirName)
 {
     $file = new Gpf_Io_File($this->getCacheFileName($dirName, false));
     $file->setFileMode('w');
     if (!$file->isExists()) {
         $file->setFilePermissions(0777);
     }
     $recordSet = new Gpf_Data_RecordSet();
     $recordSet->setHeader(array('source', 'translation'));
     foreach ($this->translations as $translation) {
         if ($translation->getType() == Gpf_Lang_Parser_Translation::TYPE_CLIENT || $translation->getType() == Gpf_Lang_Parser_Translation::TYPE_BOTH) {
             if ($translation->getStatus() != 'D') {
                 $recordSet->add(array($translation->getSourceMessage(), $translation->getDestinationMessage()));
             }
         }
     }
     $recordSet->add(array("_dateFormat", $this->getMetaValue(self::LANG_DATE_FORMAT)));
     $recordSet->add(array("_timeFormat", $this->getMetaValue(self::LANG_TIME_FORMAT)));
     $recordSet->add(array("_thousandsSeparator", $this->getMetaValue(self::LANG_THOUSANDS_SEPARATOR)));
     $recordSet->add(array("_decimalSeparator", $this->getMetaValue(self::LANG_DECIMAL_SEPARATOR)));
     $encoder = new Gpf_Rpc_Json();
     $file->write(addcslashes($encoder->encodeResponse($recordSet), '"\\'));
     $file->close();
 }
 protected function updateTask()
 {
     if ($this->doneProgress !== null) {
         $json = new Gpf_Rpc_Json();
         $this->task->setParams($json->encode($this->paramsArray));
         $this->task->setProgress($this->doneProgress);
         $this->task->setProgressMessage($this->getProgressMessage());
         $this->task->updateTask();
     }
 }
 /**
  * @return string  string representation of input var or an error if a problem occurs
  */
 public function encodeResponse(Gpf_Rpc_Serializable $response)
 {
     return '<html><script type="text/javascript">
     window.name="' . addcslashes(parent::encodeResponse($response), '"\\') . '";</script></html>';
 }
	private function saveParams($params) {
		$json = new Gpf_Rpc_Json();
		$encoded = $json->encode($params);
		$this->setParams($encoded);
	}
Ejemplo n.º 22
0
 protected function getSaleParams()
 {
     if (count($this->sales) == 0) {
         return '';
     }
     $json = new Gpf_Rpc_Json();
     return $json->encode($this->sales);
 }
Ejemplo n.º 23
0
 public function getJSONString($withRoot = true, $states = null)
 {
     if ($this->mpttArray == null) {
         throw new Gpf_Exception('No tree Records were set! There are no data to create JSON string');
     }
     $levels = array();
     $stack = 0;
     $oldDepth = -1;
     $headers = $this->getHeaders($this->mpttArray->getHeader());
     $oldStates = array();
     foreach ($this->mpttArray as $row) {
         $depth = $row->get('depth');
         // code, depth   //name,visible
         if ($depth == $oldDepth) {
             //no level change
             if (count($oldStates) > 0) {
                 array_pop($oldStates);
             }
             array_push($oldStates, $row->get('state'));
             if ($this->checkPrevioursStatesAreCorrect($oldStates, $states)) {
                 $levels[$depth][] = $this->createObject($row, $headers);
             }
         }
         if ($depth > $oldDepth) {
             //level raised
             array_push($oldStates, $row->get('state'));
             if ($this->checkPrevioursStatesAreCorrect($oldStates, $states)) {
                 $levels[$depth][] = $this->createObject($row, $headers);
             }
             $stack = $depth;
         }
         if ($depth < $oldDepth) {
             //level drop
             while ($stack > $depth) {
                 $stack--;
                 array_pop($oldStates);
                 if ($this->checkPrevioursStatesAreCorrect($oldStates, $states)) {
                     $array = $this->cloneArray($levels[$stack + 1]);
                     $levels[$stack][count($levels[$stack]) - 1]->items = $array;
                     unset($levels[$stack + 1]);
                 }
             }
             array_pop($oldStates);
             array_push($oldStates, $row->get('state'));
             if ($this->checkPrevioursStatesAreCorrect($oldStates, $states)) {
                 $levels[$depth][] = $this->createObject($row, $headers);
             }
         }
         $oldDepth = $depth;
     }
     while ($stack > 0) {
         $stack--;
         array_pop($oldStates);
         if ($this->checkPrevioursStatesAreCorrect($oldStates, $states)) {
             if (array_key_exists($stack + 1, $levels)) {
                 $levels[$stack][count($levels[$stack]) - 1]->items = $this->cloneArray($levels[$stack + 1]);
                 unset($levels[$stack + 1]);
             }
         }
     }
     $json = new Gpf_Rpc_Json();
     if ($withRoot) {
         return $json->encode($levels[0]);
     }
     if (array_key_exists(0, $levels)) {
         return $json->encode($levels[0][0]->items);
     }
     return 'null';
 }