encode() public method

encodes an arbitrary variable into JSON format
public encode ( mixed $var, $options = null ) : mixed
$var mixed any number, boolean, string, array, or object to be encoded. see argument 1 to Services_JSON() above for array-parsing behavior. if var is a strng, note that encode() always expects it to be in ASCII or UTF-8 format!
return mixed JSON string representation of input var or an error if a problem occurs
Beispiel #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();
    }
 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) {
     }
 }
 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));
 }
 /**
  * @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;
 }
Beispiel #5
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);
	}
Beispiel #6
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);
 }
 protected function getSaleParams()
 {
     if (count($this->sales) == 0) {
         return '';
     }
     $json = new Gpf_Rpc_Json();
     return $json->encode($this->sales);
 }
Beispiel #8
0
	function toString()
	{
		$json = new Gpf_Rpc_Json();
		return $json->encode( $this );
	}
 public function encode()
 {
     $json = new Gpf_Rpc_Json();
     return $json->encode($this);
 }
 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';
 }
 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();
     }
 }
	private function saveParams($params) {
		$json = new Gpf_Rpc_Json();
		$encoded = $json->encode($params);
		$this->setParams($encoded);
	}