Views Fusion

With Views Fusion you can fuse multiple views into one. So you can build "fusioned" views that display information that is stored in multiple content types - useful for tabular views. It uses node relations for joining the appropriate node types together.

Currently the Views Fusion module requires the nodefamily module for getting the node type relation information. For information on how to use the nodefamily relation to build extended user listings that include nodeprofile information, see this page from the nodeprofile documentation.
However, in future, other node relation modules could also provide their data for Views Fusion as the Fusion module is coded generically.

There is also a patch for the CCK nodereference field, which adds support for Views Fusion.
As there is already documentation for how to use Views Fusion with a nodefamily relation, this page covers using Views Fusion with the CCK nodereference fields.

  • First, make sure you have applied the latest patch for the nodereference module from the issue mentioned previously and, of course, install the Views Fusion module.
  • Let's assume you have the node types "cd" and "artist", where "cd" contains a node reference for artists.
    Create two tabular views, one that lists the nodes of type "cd" and another one for artists. Add some fields to both of the views.
  • Decide which view you want to fuse into the other. As an example, let's fuse the artists view into the cd view, so that we get a view of cds containing the artist information. This means, we create a new fusion at 'admin/build/views/fusion' with the primary view "cd" fused with the view for artists by using the right nodereference field in normal direction (not reversed!).
  • Then go to the page of the cd view and you'll see the fused view: Now it also contains the fields from the artists view.
  • If we would like a view of artists that contains data of their cds, you have to create a fusion with the primary view "artist" fused with cds by using the reversed nodereference information!

Views Fusion can also fuse views which are already fused. It's also working well for external filters. But unfortunately there is no easy way for reordering the fields of the resulting view, so if you want to mix up the fields of fused views in the resulting view you have to do it in a theme or wait for views 2.0 :)

possible way for reordering fields of fused views

olio - August 29, 2007 - 12:10

Hi,
I found a quite simple way (after a long and desperate search ... ) to reorder the fields of a fused table. It only needs two more lines inside the overridden theming function 'theme_views_view_table($view, $nodes, $type) ' and a small helper function. Both functions needs to be placed inside template.php.

Do the following:
1. copy this function inside your template.php. Then change the name of the function according to the name of your view ()

function phptemplate_views_view_table_<name_of_your_view>($view, $nodes, $type) {
  $fields = _views_get_fields();

  foreach($nodes as $node){
    $row = array();
   
    foreach($view->field as $field){
      $cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
      $cell['class'] = "view-field ". views_css_safe('view-field-'. $field['queryname']);
      $row[] = $cell;
    }
    // This changes the order of the table cells. In this example, we switch the fifth ('4') and the first ('0') element. Change these two arguments to fit your needs.
    $new_row = array_move(4, 0, $row);
    $rows[] = $new_row;
  }
  // This changes the order of header cells: The first and second argument have to be the same as in the call ( of array_move() ) above.
  $new_header = array_move(4, 0, $view->table_header);

  return theme('table', $new_header, $rows);
}

You have to adapt the lines
'$new_row = array_move(4, 0, $row);'
and
$new_header = array_move(4, 0, $view->table_header);
to the order of the columns you want to switch. So, for example, change the '4' to '3' and the '0' to '1' to switch the fourth ('3') and the second column ('1').

2. Also copy this function into template.php. It takes care of switching the values inside the arrays that build the table header and the table data rows.

/**
* Function that takes a given element from the array and moves it before a given element into the same array.
*/
function array_move($which, $where, $array) {
    $tmp  = array_splice($array, $which, 1);
    array_splice($array, $where, 0, $tmp);
    return $array;
}

Thanks to the original author of the comment on php.net (http://de3.php.net/manual/de/function.array-splice.php#69329).

Content type with nodreference is Primary

hal9000_jr - January 11, 2008 - 18:21

Which ever View you defined to retrieve the CCK type with the node reference in it is the primary becomes the Primary View in Fusion. The View that retrieves the CCK type that is referenced is the Fused View. In this example, "cd" contains the node references to "artists", therefore its View is Primary.

If you reverse the Views, you will either get a blank page or a Cartesian product where every the result from the Primary View is multiples by the result from the Fused View. :)

 
 

Drupal is a registered trademark of Dries Buytaert.