You are here

function views1_load in Views (for Drupal 7) 6.2

Same name and namespace in other branches
  1. 6.3 includes/convert.inc \views1_load()

Load a version 1 view from the database.

1 call to views1_load()
views_ui_convert1 in includes/convert.inc
Page callback for the tools - Views 1 convert page

File

includes/convert.inc, line 429
convert.inc

Code

function views1_load($arg) {
  static $cache = array();
  $which = is_numeric($arg) ? 'vid' : 'name';
  if (isset($cache[$which][$arg])) {
    return $cache[$which][$arg];
  }
  $where = is_numeric($arg) ? "v.vid =  %d" : "v.name = '%s'";
  $view = db_fetch_object(db_query("SELECT v.* FROM {view_view} v WHERE {$where}", $arg));
  if (!$view->name) {
    return NULL;
  }
  $view->access = $view->access ? explode(', ', $view->access) : array();

  // load the sorting criteria too.
  $result = db_query("SELECT * FROM {view_sort} vs WHERE vid = {$view->vid} ORDER BY position ASC");
  $view->sort = array();
  while ($sort = db_fetch_array($result)) {
    if (substr($sort['field'], 0, 2) == 'n.') {
      $sort['field'] = 'node' . substr($sort['field'], 1);
    }
    $sort['id'] = $sort['field'];
    $bits = explode('.', $sort['field']);
    $sort['tablename'] = $bits[0];
    $sort['field'] = $bits[1];
    $view->sort[$sort['position']] = $sort;
  }
  $result = db_query("SELECT * FROM {view_argument} WHERE vid = {$view->vid} ORDER BY position ASC");
  $view->argument = array();
  while ($arg = db_fetch_array($result)) {
    $arg['id'] = $arg['type'];
    $view->argument[$arg['position']] = $arg;
  }
  $result = db_query("SELECT * FROM {view_tablefield} WHERE vid = {$view->vid} ORDER BY position ASC");
  $view->field = array();
  while ($arg = db_fetch_array($result)) {
    if ($arg['tablename'] == 'n') {
      $arg['tablename'] = 'node';
    }
    $arg['id'] = $arg['fullname'] = "{$arg['tablename']}.{$arg['field']}";
    $arg['queryname'] = "{$arg['tablename']}_{$arg['field']}";
    $view->field[] = $arg;
  }
  $result = db_query("SELECT * FROM {view_filter} WHERE vid = {$view->vid} ORDER BY position ASC");

  // TODO - Is it safe to ignore this $filters variable? This function depends
  // on lots of additional code needed to call hook_implements and construct
  // all the views tables, so using it will add a lot of code to this file.

  //$filters = _views_get_filters();
  $view->filter = array();
  while ($filter = db_fetch_array($result)) {
    if (substr($filter['field'], 0, 2) == 'n.') {
      $filter['field'] = 'node' . substr($filter['field'], 1);
    }
    if ($filter['operator'] == 'AND' || $filter['operator'] == 'OR' || $filter['operator'] == 'NOR') {

      // TODO - need another way to identify this type of filter
      // without being able to call hook_implements().

      //|| $filters[$filter['field']]['value-type'] == 'array' ) {
      if ($filter['value'] !== NULL && $filter['value'] !== '') {
        $filter['value'] = explode(',', $filter['value']);
      }
      else {
        $filter['value'] = array();
      }
    }
    $filter['id'] = $filter['field'];
    $bits = explode('.', $filter['field']);
    $filter['tablename'] = $bits[0];
    $filter['field'] = $bits[1];
    $view->filter[$filter['position']] = $filter;
  }
  $result = db_query("SELECT * FROM {view_exposed_filter} WHERE vid = {$view->vid} ORDER BY position ASC");
  $view->exposed_filter = array();
  while ($arg = db_fetch_array($result)) {
    $arg['id'] = $arg['field'];
    $view->exposed_filter[] = $arg;
  }
  $cache['vid'][$view->vid] = $view;
  $cache['name'][$view->name] = $view;
  return $view;
}