You are here

function _draggableviews_info in DraggableViews 7

Same name and namespace in other branches
  1. 6.3 draggableviews.inc \_draggableviews_info()

Fetch views-style-plugin information. Collect all known information in a handy array.

Parameters

$view: The views object

Return value

A structured array containing the extracted draggableviews settings, additional field information, all nodes the view returned and the view object itself. array( 'view' => view,

'order' => array( 'field' => array( 'field_name' => field_name, 'field_alias' => field_alias, 'handler' => handler, ), 'visible' => TRUE/FALSE, ),

'hierarchy' => array( 'field' => array( 'field_name' => field_name, 'field_alias' => field_alias, 'handler' => handler, ), 'visible' => TRUE/FALSE, ),

'depth_limit' => depth_limit,

'types' = array( node_type1 => "root"/"leaf", node_type2 => "root"/"leaf", .. ),

'expand_links' = array( 'show' => TRUE/FALSE, 'default_collapsed' => TRUE/FALSE, 'by_uid' => TRUE/FALSE, ),

'view_window_extensions' = array( 'extension_top' => 3, 'extension_bottom' => 3, ),

'locked' => TRUE/FALSE,

'depth' => 0,

'default_on_top' => TRUE/FALSE,

'nodes' => array( nid1 => array( 'order' => array( 0 => value, 1 => value, .. ), 'parent' => value, ), .. ), );

3 calls to _draggableviews_info()
draggableviews_views_pre_execute in ./draggableviews.module
Implements hook_views_pre_execute().
draggableviews_views_pre_render in ./draggableviews.module
Implements hook_views_pre_render
_draggableviews_reload_info in ./draggableviews.inc
Reload Info Array

File

./draggableviews.inc, line 80
Draggableviews processing functions. Rough summary of what functions in this file do:

Code

function _draggableviews_info($view, $info = NULL) {
  $options = $view->style_plugin->options;
  $fields = $view->field;
  $results = $view->result;

  // if there is already an info array just rebuild the nodes array and skip this section
  if (!isset($info)) {
    $info = array();

    // Hold a reference of the view object itself. The handlers might need it,
    // so we have to attach it now.
    $info['view'] =& $view;

    // extract draggableviews settings.
    if (!empty($options['tabledrag_order']['field']) && strcmp($options['tabledrag_order']['field'], 'none') != 0) {
      if ($handler = _draggableviews_init_handler($options['tabledrag_order'], $view)) {
        $info['order'] = array(
          'field' => array(
            'handler' => $handler,
            'field_name' => $options['tabledrag_order']['field'],
            'field_alias' => $fields[$options['tabledrag_order']['field']]->field_alias,
          ),
          'visible' => strcmp($options['tabledrag_order_visible']['visible'], 'visible') == 0 ? TRUE : FALSE,
        );
      }
      else {
        drupal_set_message(t('Draggableviews: Handler <i>@handler</i> could not be found.', array(
          '@handler' => $options['tabledrag_order']['handler'],
        )), 'error');
        unset($info['order']);
        return $info;
      }
      $info['order']['visible'] = strcmp($options['tabledrag_order_visible']['visible'], 'visible') == 0 ? TRUE : FALSE;
      if (!empty($options['tabledrag_hierarchy']['field']) && strcmp($options['tabledrag_hierarchy']['field'], 'none') != 0) {
        if ($handler = _draggableviews_init_handler($options['tabledrag_hierarchy'], $view)) {
          $info['hierarchy'] = array(
            'field' => array(
              'handler' => $handler,
              'field_name' => $options['tabledrag_hierarchy']['field'],
              'field_alias' => $fields[$options['tabledrag_hierarchy']['field']]->field_alias,
            ),
            'visible' => strcmp($options['tabledrag_hierarchy_visible']['visible'], 'visible') == 0 ? TRUE : FALSE,
          );
          $info['depth_limit'] = $options['draggableviews_depth_limit'];
          if (!isset($info['depth_limit'])) {
            $info['depth_limit'] = 10;
          }
          if (isset($options['tabledrag_types'])) {
            foreach ($options['tabledrag_types'] as $type) {
              $info['types'][$type['node_type']] = $type['type'];
            }
          }
          $info['expand_links'] = array(
            'show' => strcmp($options['tabledrag_expand']['expand_links'], 'expand_links') == 0 ? TRUE : FALSE,
            'default_collapsed' => strcmp($options['tabledrag_expand']['collapsed'], 'collapsed') == 0 ? TRUE : FALSE,
            'by_uid' => strcmp($options['tabledrag_expand']['by_uid'], 'by_uid') == 0 ? TRUE : FALSE,
          );
        }
        else {
          drupal_set_message(t('Draggableviews: Handler <i>@handler</i> could not be found.', array(
            '@handler' => $options['tabledrag_hierarchy']['handler'],
          )), 'error');
        }
      }
      if (isset($options['draggableviews_repair']['repair'])) {
        $info['repair_if_broken'] = strcmp($options['draggableviews_repair']['repair'], 'repair') == 0 ? TRUE : FALSE;
      }
      else {
        $info['repair_if_broken'] = TRUE;
      }
      $info['view_window_extensions'] = $options['draggableviews_extensions'];
      if (!isset($info['view_window_extensions']['extension_top'])) {
        $info['view_window_extensions']['extension_top'] = 3;
      }
      if (!isset($info['view_window_extensions']['extension_bottom'])) {
        $info['view_window_extensions']['extension_bottom'] = 3;
      }
      $info['locked'] = strcmp($options['tabledrag_lock']['lock'], 'lock') == 0 ? TRUE : FALSE;
      $info['needs_pager_modifications'] = $view
        ->use_pager() && (!empty($info['view_window_extensions']['extension_top']) || !empty($info['view_window_extensions']['extension_bottom']) || isset($info['hierarchy']));
    }
  }

  // Refresh the reference of the view object itself.
  $info['view'] =& $view;
  $info['depth'] = 0;
  $info['default_on_top'] = !empty($options['draggableviews_default_on_top']) ? TRUE : FALSE;

  // Get all nodes and their properties.
  $info['nodes'] = array();
  if (isset($info['order']) && isset($results) && count($results) > 0) {

    // loop through all resulting nodes
    foreach ($results as $row) {
      if (is_numeric($row->{$info['order']['field']['field_alias']})) {
        $info['nodes'][$row->{$view->base_field}]['order'][0] = $info['order']['field']['handler']
          ->get((int) $row->{$info['order']['field']['field_alias']});
      }
      else {

        // Default position of new nodes. We cannot use $view->total_rows instead of 99999999 because
        // $view->total_rows will not be calculated if paging is not used.
        $info['nodes'][$row->{$view->base_field}]['order'][0] = $info['default_on_top'] == 1 ? -1 : 99999999;
      }
      if (isset($info['hierarchy'])) {
        $info['nodes'][$row->{$view->base_field}]['parent'] = $info['hierarchy']['field']['handler']
          ->get((int) $row->{$info['hierarchy']['field']['field_alias']});
      }
    }
  }
  return $info;
}