Download & Extend

Create a table out of multiple-field CCKs with 'relation' between their deltas

Project:Content Construction Kit (CCK)
Version:6.x-2.x-dev
Component:Views Integration
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Here's my use case:
1) I have several CCK fields, which are defined as multiple (snap.png)
2) When I populate them, there is a correlation between each delta. Meaning that field_foo[0] should be related too field_bar[0]; field_foo[1] to field_bar[1] etc'.
3) I'd like to use Views to create a table, and I don't want to group the fields.
4) In order to remove the 'duplication' of the fields (snap1.png) resulted from not-grouping the fields, I use hook_views_render hook_views_pre_render() and manipulate the $view->result to return my required results.

So the questions is - Is there a better way to achieve this so the SQL query will return already the expected result?

AttachmentSize
snap.png19.97 KB
snap1.png27.86 KB

Comments

#1

Project:Views» Content Construction Kit (CCK)
Version:6.x-2.x-dev» 6.x-2.x-dev
Component:Code» Views Integration

#2

#3

Status:active» fixed

Thanks, I close this support issue as I got the answer I was looking for.

#4

For others that may need this functionality, here's how I currently manipulate the View:

<?php
/**
* Implementation of hook_views_query_alter().
*
* Add WHERE clauses that will group all fields according to their delta.
*/
function XXX_views_query_alter(&$view, &$query) {
  if (
$view->name == 'your_view') { // <-- Your view name.
    // Get the View field aliases.
   
$aliases= $view->field;
    if (
count($aliases > 1)) {
     
// Get the first delta alias.
     
$first_field = array_shift($aliases);
     
$first_field = $first_field->table .'.delta';
      foreach (
$aliases as $value) {
       
$query->add_where(0, $first_field .'='. $value->table .'.delta');
      }
    }
  }
}
?>

#5

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.