You are here

function ARC_rdf_store_select_json_sub_handler::get_json_result_body_bindings in Taxonomy import/export via XML 5

Same name and namespace in other branches
  1. 5.2 arc/ARC_rdf_store_select_json_sub_handler.php \ARC_rdf_store_select_json_sub_handler::get_json_result_body_bindings()
  2. 6.2 arc/ARC_rdf_store_select_json_sub_handler.php \ARC_rdf_store_select_json_sub_handler::get_json_result_body_bindings()
  3. 6 arc/ARC_rdf_store_select_json_sub_handler.php \ARC_rdf_store_select_json_sub_handler::get_json_result_body_bindings()
1 call to ARC_rdf_store_select_json_sub_handler::get_json_result_body_bindings()
ARC_rdf_store_select_json_sub_handler::get_json_result_body in arc/ARC_rdf_store_select_json_sub_handler.php

File

arc/ARC_rdf_store_select_json_sub_handler.php, line 207

Class

ARC_rdf_store_select_json_sub_handler

Code

function get_json_result_body_bindings($args = "") {
  $ind = "  ";
  $ind2 = $ind . $ind;
  $ind3 = $ind2 . $ind;
  $ind4 = $ind3 . $ind;
  $nl = "\n";
  $jsonc = isset($args["result_type_args"]["jsonc"]) ? $args["result_type_args"]["jsonc"] : false;
  $row = isset($args["row"]) ? $args["row"] : false;
  $rs = isset($args["rs"]) ? $args["rs"] : false;
  $enc_vals = $this->config["encode_values"];
  $conv_id = in_array($this->config["id_type"], array(
    "hash_int",
    "incr_int",
  ));
  $fix_utf8 = isset($args["fix_utf8"]) ? $args["fix_utf8"] : false;
  $code = "";
  if (!$row) {
    return $code;
  }
  $result_vars = $args["infos"]["result_vars"];
  $result_vars_jsonc = count($result_vars) == 1 ? $result_vars[0] . "()" : join("(),", $result_vars) . "()";
  $jsonc_t = $jsonc ? $jsonc : $result_vars_jsonc;
  $vars = $this
    ->get_jsonc_result_vars($jsonc_t);
  $api =& $this->api;
  $api_helper =& $this->api
    ->get_api_helper();
  do {

    /* result */
    $code .= strlen($code) ? "," : "";
    $code .= $nl . $ind3 . '{';
    $vars_code = "";
    foreach ($vars as $cur_t_var) {
      $cur_var = $cur_t_var["var"];
      $compact = $cur_t_var["compact"];
      if (isset($row[$cur_var])) {
        $cur_type = isset($row[$cur_var . "__type"]) ? $row[$cur_var . "__type"] : 0;
        $val = $enc_vals ? rawurldecode($row[$cur_var]) : $row[$cur_var];
        $vars_code .= strlen($vars_code) ? "," . $nl : "";
        $vars_code .= $ind4 . '"' . $cur_var . '": ';
        $vars_code .= $compact ? "" : '{';
        if (!isset($row[$cur_var . "__type"]) || $row[$cur_var . "__type"] == 0) {
          $vars_code .= $compact ? '"' . $val . '"' : ' type: "uri", value: "' . $val . '"';
        }
        elseif ($row[$cur_var . "__type"] == 1) {
          $vars_code .= $compact ? '"' . substr($val, 2) . '"' : ' type: "bnode", value: "' . substr($val, 2) . '"';
        }
        else {
          $val = $this
            ->decode_mysql_utf8_bugs($val);
          $val = $fix_utf8 ? $api_helper
            ->escape_js_string($api_helper
            ->adjust_utf8_string($val)) : $api_helper
            ->escape_js_string($val);
          $val_type = "literal";
          $vars_code_addition = "";
          if (isset($row[$cur_var . "__lang"]) && ($lang = $row[$cur_var . "__lang"])) {
            $vars_code_addition .= $compact ? ', "' . $cur_var . '__lang": "' . $lang . '"' : ', "xml:lang": "' . $lang . '"';
          }
          elseif (isset($row[$cur_var . "__dt"]) && ($dt = $row[$cur_var . "__dt"])) {
            $dt_val = $conv_id ? $api
              ->get_val("CONV('" . $dt . "', 16, 10)") : $api
              ->get_val("'" . $dt . "'");
            if ($dt_val) {
              $val_type = "typed-literal";
              $vars_code_addition .= $compact ? ', "' . $cur_var . '__datatype": "' . htmlspecialchars($dt_val) . '"' : ', "datatype": "' . htmlspecialchars($dt_val) . '"';
            }
          }
          $vars_code .= $compact ? '"' . $val . '"' . $vars_code_addition : ' type: "' . $val_type . '"' . $vars_code_addition . ', value: "' . $val . '"';
        }
        $vars_code .= $compact ? "" : ' }';
      }
    }
    $code .= $nl . $vars_code;

    /* /result */
    $code .= $nl . $ind3 . '}';
    $row = mysql_fetch_array($rs);
  } while ($row);
  return $code;
}