function view::load_views

3.x view.inc static view::load_views()
2.x view.inc view::load_views()

Static factory method to load a list of views based upon a $where clause.

Although this method could be implemented to simply iterate over views::load(), that would be very slow. Buiding the views externally from unified queries is much faster.

1 call to view::load_views()
views_get_all_views in ./views.module
Return an array of all views as fully loaded $view objects.

File

includes/view.inc, line 1395
view.inc Provides the view object type and associated methods.

Class

view
An object to contain all of the data to generate a view, plus the member functions to build the view query, execute the query and render the output.

Code

function load_views() {
  $result = db_query("SELECT DISTINCT v.* FROM {views_view} v");
  $views = array();
  $vids = array();

  // Load all the views.
  while ($data = db_fetch_object($result)) {
    $view = new view;
    $view->load_row($data);
    $view->loaded = TRUE;
    $view->type = t('Normal');
    $views[$view->name] = $view;
    $names[$view->vid] = $view->name;
  }

  // Stop if we didn't get any views.
  if (!$views) {
    return array();
  }

  $vids = implode(', ', array_keys($names));
  // Now load all the subtables:
  foreach (view::db_objects() as $key) {
    $object_name = "views_$key";
    $result = db_query("SELECT * FROM {{$object_name}} WHERE vid IN ($vids) ORDER BY vid, position");

    while ($data = db_fetch_object($result)) {
      $object = new $object_name(FALSE);
      $object->load_row($data);

      // Because it can get complicated with this much indirection,
      // make a shortcut reference.
      $location = &$views[$names[$object->vid]]->$key;

      // If we have a basic id field, load the item onto the view based on
      // this ID, otherwise push it on.
      if (!empty($object->id)) {
        $location[$object->id] = $object;
      }
      else {
        $location[] = $object;
      }
    }
  }
  return $views;
}