You are here

function viewreference_get_views in View reference 6.3

Same name and namespace in other branches
  1. 7.3 viewreference.module \viewreference_get_views()

Get an array of views.

Parameters

$append_id: Whether to append the id to the returned display names.

$filter: A list of IDs in the format view_name:display_key to restrict results by.

$full: If TRUE will return all the data, rather than just the title.

$string: String to match against the title to filter results by.

$exact_string: If TRUE the $string parameter must match exactly.

$long_key: If TRUE will key array by the title and ID, not just the ID.

Return value

The array of views.

6 calls to viewreference_get_views()
viewreference_allowed_values in ./viewreference.module
Implementation of hook_allowed_values().
viewreference_autocomplete in ./viewreference.module
Retrieve a pipe delimited string of autocomplete suggestions.
viewreference_autocomplete_validate in ./viewreference.module
Validate an autocomplete element.
viewreference_autocomplete_value in ./viewreference.module
Value for a viewreference autocomplete element.
viewreference_field in ./viewreference.module
Implementation of hook_field().

... See full list

File

./viewreference.module, line 702
Defines a field type for referencing a view from a node.

Code

function viewreference_get_views($append_id = FALSE, $filter = NULL, $full = FALSE, $string = '', $exact_string = FALSE, $long_key = FALSE) {
  $views = array();
  $loaded_views = views_get_all_views();
  $filter = $filter ? array_filter($filter) : NULL;
  foreach ((array) $loaded_views as $view_name => $view) {
    foreach ((array) $view->display as $display_key => $display) {

      // Skip this one if it's a 'default' view.
      if ($display_key != 'default') {
        $id = $view_name . ":" . $display_key;

        // Skip this one if it's not 'allowed'.
        if (empty($filter) || in_array($id, $filter)) {

          // Get display title.
          $display_title = theme('viewreference_display_title', $view, $view_name, $display_key, $append_id);

          // Determine whether and what to return.
          $key = $long_key ? $display_title . ($append_id ? '' : ' [' . $id . ']') : $id;
          if ($string) {
            if (!$exact_string && (stripos($display_title, $string) !== FALSE || stripos($key, $string) !== FALSE)) {
              $views[$key] = $full ? $display : $display_title;
            }
            else {
              if ($display_title == $string) {
                $views[$key] = $full ? $display : $display_title;
              }
            }
          }
          else {
            $views[$key] = $full ? $display : $display_title;
          }
        }
      }
    }
  }
  return $views;
}