You are here

function views_attach_get_user_views in Views attach 7.2

Same name and namespace in other branches
  1. 6.2 views_attach.module \views_attach_get_user_views()
  2. 6 views_attach.module \views_attach_get_user_views()

Get a list of views and displays attached to the specified category.

This function will cache its results into the views cache, so it gets cleared by Views appropriately.

Parameters

$category: The category of profile information we want to display. If NULL is specified, we use an internal keyword of "Default".

Return value

An array of view name/display name values, or an empty array().

1 call to views_attach_get_user_views()
views_attach_user in ./views_attach.module
Implementation of hook_user().

File

./views_attach.module, line 134

Code

function views_attach_get_user_views($category) {
  static $used_views = array();
  if (is_null($category)) {
    $category = 'Default';
  }
  if (empty($used_views)) {
    views_include('cache');
    $cache = views_cache_get("views_attach:profile");
    if (isset($cache->data)) {
      $used_views = $cache->data;
    }
    else {

      // Build and cache the data, both in the DB and statically.
      $views = views_get_applicable_views('uses hook user');
      foreach ($views as $data) {
        list($view, $display_id) = $data;
        $view_category = $view->display_handler
          ->get_option('category');
        if (empty($view_category)) {
          $view_category = 'Default';
        }
        $used_views[$view_category][] = array(
          'name' => $view->name,
          'display' => $display_id,
        );
        $view
          ->destroy();
      }
      views_cache_set("views_attach:profile", $used_views);
    }
  }
  return isset($used_views[$category]) ? $used_views[$category] : array();
}