decode() public static method

Decodes the given JSON string into a PHP data structure.
public static decode ( string $json, boolean $asArray = true ) : mixed
$json string the JSON string to be decoded
$asArray boolean whether to return objects in terms of associative arrays.
return mixed the PHP data
Ejemplo n.º 1
0
 public function Resultados()
 {
     $this->CamposO = $this->CamposB;
     //Por ahora son iguales
     //consulta que funciona
     // select idPresta,NombreyApellido from Prestamos left join DatosUser on Prestamos.idUser=DatosUser.IdUser
     //otra consulta que funciona
     // select idPresta,Nombre from Prestamos left join Stock on Prestamos.IdStock=Stock.idStock
     $filtro = BaseJson::decode($this->Filtros);
     $Consulta = (new \yii\db\Query())->select('*')->from($this->Tabla)->where(['like', $this->CamposB, '%' . $this->TBusqueda . '%', false]);
     $Consulta->andWhere($filtro);
     if ($this->OrdenResu != "n") {
         //se ordena
         if ($this->OrdenResu == "d") {
             $Consulta = $Consulta->orderBy([$this->CamposO => SORT_DESC]);
         } else {
             if ($this->OrdenResu == "a") {
                 $Consulta = $Consulta->orderBy([$this->CamposO => SORT_ASC]);
             }
         }
     }
     $this->CantTot = $Consulta->count();
     $Consulta = $Consulta->offset($this->Desplaza)->limit($this->CantReg)->all();
     $this->ResBusca = $Consulta;
     return $this->toArray(['CantTot', 'ResBusca']);
 }
Ejemplo n.º 2
0
 public function actionSocial()
 {
     $req = Yii::$app->request;
     $i = $req->get('i');
     $c = $req->get('c');
     $a = $req->get('a');
     //se inicia sesion en el ampache
     $Conexion = BaseJson::decode($this->actionConnectionParams());
     $datos = "";
     $peticionAmpache = http_post_data($Conexion["url"] . 'action=' . $Conexion['action'] . "&auth=" . $Conexion['auth'] . "&timestamp=" . $Conexion['timestamp'] . "&version=" . $Conexion['version'] . "&user="******"timeout" => 1, "useragent" => ""));
     $peticionAmpache = substr($peticionAmpache, strpos($peticionAmpache, '<'));
     $peticionAmpache = substr($peticionAmpache, 0, -5);
     //return $peticionAmpache;
     $xml = simplexml_load_string($peticionAmpache);
     $token = $xml->auth;
     //se pide la informacion del album
     $peticionAmpache = http_post_data($Conexion["url"] . "auth=" . $token . "&action=album_songs&filter=" . $a, $datos);
     //return $peticionAmpache;
     $peticionAmpache = substr(substr($peticionAmpache, strpos($peticionAmpache, '<')), 0, -5);
     $xml = simplexml_load_string($peticionAmpache);
     //"renderizamos la vista"
     $salida = $this->render('index', ['urlimg' => $xml->song[0]->art, 'descripcion' => 'Escuchando ' . $xml->song[0]->album . ' en Radio Album!']);
     //le agregamos los parametros necesarios
     $salida .= '<div id="parametros" data-skin="' . $i . 'vplayer" data-album="' . $a . '" data-channel="' . $c . '"></div>' . $peticionAmpache;
     //mostramos la vista
     return $salida;
 }
 /**
  * Get field attachs
  * @return Array
  */
 public function getAttachs()
 {
     if (in_array(Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldAttachs'], $this->owner->attributes())) {
         $value = BaseJson::decode($this->owner->{Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldAttachs']});
         if (null === $value) {
             return [];
         }
         return $value;
     }
     return [];
 }
Ejemplo n.º 4
0
 public static function getPostJsonParams()
 {
     $post = file_get_contents("php://input");
     //decode json post input as php array:
     try {
         $params = BaseJson::decode($post, $asArray = true);
         if (!$params) {
             $params = [];
         }
         return $params;
     } catch (InvalidParamException $e) {
         Utils::echoErrorResponse($e->getMessage());
         die;
     }
 }
Ejemplo n.º 5
0
 public function init()
 {
     parent::init();
     $this->directorio = BaseJson::decode(WpController::actionObtenerlista());
     switch ($this->ordenwp) {
         case "azar":
             //desordenar
             shuffle($this->directorio);
             break;
         case null:
             //si no se especifica orden se ve si se definio uno en particular
             $this->OrdenArreglado();
             break;
     }
 }
Ejemplo n.º 6
0
 /**
  * Look up item using UPC code and return
  * 
  * @return array of item properties
  */
 public function getItemByUPC($upcCode)
 {
     // search upcdatabase and pre-populate fields
     // if not found, only populate barcode field value
     $upcDBUrl = Yii::$app->params['apiUrl'] . '/json/' . Yii::$app->params['apiKey'] . '/' . $upcCode;
     $curl = new curl\Curl();
     $upcResponse = $curl->get($upcDBUrl);
     if ($curl->responseCode) {
         $upcWine = BaseJson::decode($upcResponse, TRUE);
         if ($upcWine['valid'] == 'true') {
             return $upcWine;
         }
     } else {
         \Yii::info('Error accessing upcdatabase.log: ' . $curl->responseCode, Logger::LEVEL_ERROR);
     }
     return NULL;
 }
Ejemplo n.º 7
0
 public function actionChauffeur()
 {
     //$model = array();
     $a = 'amcix';
     if (!empty(Yii::$app->request->get('Transferorder')['car']) and !empty(Yii::$app->request->get('Rentorder')['from'])) {
         $model = new Rentorder();
         $timemodel = new Rentime();
         date_default_timezone_set('Asia/Baku');
         if ($model->load(Yii::$app->request->post())) {
             $jsondata = BaseJson::decode(Yii::$app->request->get('Transferorder')['car'], true);
             $model->car = $jsondata['car'];
             $amount = Yii::$app->db->createCommand('SELECT priceC , priceT , cent FROM auto  where id = :json')->bindValue(':json', $model->car)->queryOne();
             $converter = new CurrencyConverter();
             $rate = $converter->convert('USD', 'AZN');
             $reference = $model->id . time();
             $reference = sha1($reference);
             $model->reference = $reference;
             $model->pickuptime = strtotime(str_replace('/', '-', $model->pickdate) . '' . $model->time_start[0]);
             $count = count($model->time_start) - 1;
             $model->endtime = strtotime("+" . $count . " day", $model->pickuptime);
             $kmsums = $model->fplaceid;
             if ($kmsums > 35) {
                 $qiymet = $amount['cent'] * $rate * ($kmsums - 35) + $amount['priceT'] * $rate;
                 $qiymet = intval($qiymet);
             } else {
                 $qiymet = null;
             }
             if ($model->validate()) {
                 $model->save();
                 $amountC = 0;
                 foreach ($model->time_start as $i => $time) {
                     // echo strtotime($time)-strtotime($model->time_end[$i]).'<br>';
                     $dteStart = new \DateTime($time);
                     $dteEnd = new \DateTime($model->time_end[$i]);
                     $diff = $dteStart->diff($dteEnd);
                     //echo 'saat '.$diff->h.' invert '.$diff->invert.'<br>';
                     $amountC += $this->hesabla($amount['priceC'], $diff->h, $diff->invert);
                     //$hours += $model->timestart
                     Yii::$app->db->createCommand()->insert('rentime', ['rentid' => $model->id, 'time_start' => strtotime($time), 'time_end' => strtotime($model->time_end[$i])])->execute();
                 }
                 $z = 0;
                 $model->amount = intval($amountC * $rate);
                 if ($qiymet != null) {
                     $model->amount = $model->amount + $qiymet;
                 }
                 $model->amount = $model->amount . $z . $z;
                 if ($model->save() and $model->validate()) {
                     return $this->redirect(['confirmation', 'id' => $model->id, 'mode' => 'ch']);
                 } else {
                     foreach ($model->errors as $errors) {
                         var_dump($errors) . '<br>';
                     }
                 }
             } else {
                 foreach ($model->errors as $errors) {
                     var_dump($errors) . '<br>';
                 }
             }
         }
         return $this->render('chauffeurForm', ['model' => $model]);
     }
     return $this->redirect('error');
 }
Ejemplo n.º 8
0
<?php

use yii\helpers\Html;
use kartik\icons\Icon;
use yii\widgets\ActiveForm;
use yii\helpers\BaseJson;
use yii\web\UrlManager;
use frontend\assets\FormAsset;
use frontend\assets\BootstrapDateTimePickerAsset;
use frontend\assets\InternationalTelephoneAsset;
FormAsset::register($this);
BootstrapDateTimePickerAsset::register($this);
InternationalTelephoneAsset::register($this);
$this->title = 'Order chaffeured service in Azerbaijan, Baku';
$jsondata = BaseJson::decode(Yii::$app->request->get('Transferorder')['car'], true);
?>
<!-- Steps -->
<?php 
$form = ActiveForm::begin(['method' => 'post']);
?>
<!-- here we take all the data we need, then we smoke weed, weed, weed...-->
<div id="car-price" data-price="<?php 
echo $jsondata['amount'];
?>
"></div>
<div id="chaffeur-dest-placeid" data-id="<?php 
echo Yii::$app->request->get('Transferorder')['chauffeurDestPlaceId'];
?>
"></div>

<div id="transfer-price" data-price=""></div>
Ejemplo n.º 9
0
 public function actionSavemenu()
 {
     if (Yii::$app->request->isAjax) {
         $data = Yii::$app->request->post();
         $area_id = $data['area_id'];
         $menu_items = BaseJson::decode($data['menu_json']);
         if (count($menu_items) > 0) {
             // Delete Existing Menu's Before Adding New
             CmsMenu::deleteAll('area_id = ' . $area_id);
             // Insert New Set Of Menu's
             $p = $c = $sc = $sc1 = $sc2 = 1;
             foreach ($menu_items as $parent) {
                 $model = new CmsMenu();
                 $model->page_id = $parent['pageid'];
                 $model->sort_order = $p;
                 $model->area_id = $area_id;
                 $model->created_by = Yii::$app->user->id;
                 $model->save();
                 $new_parent_id = $model->menu_id;
                 //Children
                 if ($new_parent_id > 0 && isset($parent['children'])) {
                     foreach ($parent['children'] as $children) {
                         $model = new CmsMenu();
                         $model->page_id = $children['pageid'];
                         $model->sort_order = $c;
                         $model->area_id = $area_id;
                         $model->parent_menu_id = $new_parent_id;
                         $model->created_by = Yii::$app->user->id;
                         $model->save();
                         $new_child_id = $model->menu_id;
                         // Sub Child
                         if ($new_child_id > 0 && isset($children['children'])) {
                             foreach ($children['children'] as $sub_children) {
                                 $model = new CmsMenu();
                                 $model->page_id = $sub_children['pageid'];
                                 $model->sort_order = $sc;
                                 $model->area_id = $area_id;
                                 $model->parent_menu_id = $new_child_id;
                                 $model->created_by = Yii::$app->user->id;
                                 $model->save();
                                 $new_sub_child_id = $model->menu_id;
                                 // Sub Child 1
                                 if ($new_sub_child_id > 0 && isset($sub_children['children'])) {
                                     foreach ($sub_children['children'] as $sub_children1) {
                                         $model = new CmsMenu();
                                         $model->page_id = $sub_children1['pageid'];
                                         $model->sort_order = $sc1;
                                         $model->area_id = $area_id;
                                         $model->parent_menu_id = $new_sub_child_id;
                                         $model->created_by = Yii::$app->user->id;
                                         $model->save();
                                         $new_sub_child_id1 = $model->menu_id;
                                         // Sub Child 2
                                         if ($new_sub_child_id1 > 0 && isset($sub_children1['children'])) {
                                             foreach ($sub_children1['children'] as $sub_children2) {
                                                 $model = new CmsMenu();
                                                 $model->page_id = $sub_children2['pageid'];
                                                 $model->sort_order = $sc2;
                                                 $model->area_id = $area_id;
                                                 $model->parent_menu_id = $new_sub_child_id1;
                                                 $model->created_by = Yii::$app->user->id;
                                                 $model->save();
                                                 $sc2++;
                                             }
                                         }
                                         $sc1++;
                                     }
                                 }
                                 $sc++;
                             }
                         }
                         $c++;
                     }
                 }
                 $p++;
             }
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ['status' => 'success', 'message' => '<strong>Success !! </strong>Menu Item/s Succesfully Added / Updated', 'array' => $new_sub_child_id];
         } else {
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ['status' => 'failed', 'message' => '<strong>Failed !! </strong> Menu Item is empty. Kindly add atleast one menu to a area'];
         }
     } else {
         $this->redirect(['selectarea']);
     }
 }
Ejemplo n.º 10
0
 public function getOptionsToArray()
 {
     return BaseJson::decode($this->options);
 }