You are here

function template_preprocess_views_views_json_style_jqgrid in Views Datasource 7

File

views/theme/views_views_json_style.theme.inc, line 220
Views theme to render view fields as JSON.

Code

function template_preprocess_views_views_json_style_jqgrid(&$vars) {
  $view = $vars["view"];
  $rows = $vars["rows"];
  $options = $vars["options"];
  $base = $view->base_table;
  $root_object = $options["root_object"];
  $top_child_object = $options["top_child_object"];
  $plaintext_output = $options["plaintext_output"];
  $objects = array();
  foreach ($rows as $row) {
    $object = array();
    foreach ($row as $field) {
      if ($options["field_output"] == "normal") {
        if ($field->label) {
          $label = $plaintext_output ? strip_tags($field->label) : $field->label;
        }
        else {
          $label = $plaintext_output ? strip_tags($field->id) : $field->id;
        }
        if (!$field->is_multiple) {
          $content = $plaintext_output ? strip_tags(html_entity_decode($field->content, ENT_QUOTES)) : $field->content;
          $content = mb_check_encoding($content, 'UTF-8') ? $content : utf8_encode($content);
        }
        else {
          $content = array();
          foreach ($field->content as $n => $oc) {
            $content[$n] = $plaintext_output ? strip_tags($oc) : $oc;
          }
        }
      }
      elseif ($options["field_output"] == "raw") {
        $label = $plaintext_output ? strip_tags($field->id) : $field->id;
        if (!$field->is_multiple) {
          $content = $plaintext_output ? strip_tags($field->raw) : $field->raw;
        }
        else {
          $content = array();
          foreach ($field->raw as $n => $oc) {
            $content[$n] = $plaintext_output ? strip_tags($oc) : $oc;
          }
        }
      }
      $object[$label] = $content;
    }
    $objects[] = $object;
  }
  if (isset($view->query->pager)) {
    global $pager_total, $pager_total_items;
    $pager_id = $view->query->pager->options['id'];
    $very_top['page'] = $view->query->pager->current_page + 1;
    $very_top['records'] = $pager_total_items[$pager_id];
    $very_top['total'] = $pager_total[$pager_id];
    $very_top['rows'] = $objects;
  }
  $vars["rows"] = $very_top;

  //array($root_object => $objects);
}