Attached is a patch containing an update to README.txt and two new files (views_bonus_crosstab.module, views_bonus_crosstab.info). These will add 2 Cross Table view types to the bonus pack. From the new README.txt text:

Bonus: Cross Table - Basic
  Creates a table where field values are used as row/column coordinates. The
  first field in the fields list (in the Views UI) designates the row, the
  second the column, and subsequent selected fields are placed into the table
  cells. For example, given a set of four nodes with CCK fields Room and Time:
  Node 1: Title="Morning Cartoons", Room="Room 101, Time="10am"
  Node 2: Title="Evening Cartoons", Room="Room 101, Time="11am"
  Node 3: Title="Morning Soaps",    Room="Room 102, Time="10am"
  Node 4: Title="Evening Soaps",    Room="Room 102, Time="11am"

  With field 1 = Time, field 2 = Room, and field 3 = Title, the following
  table would be created:
  Time  Room 101          Room 102
  ====  ================  =============
  10am  Morning Cartoons  Morning Soaps
  11am  Evening Cartoons  Evening Soaps

Bonus: Cross Table - Extended
  This special version of Cross Table adds the following feature:
  Row Value: All
  A row value of "All" will display across all the columns in that row (using
  td colspan attribute). This is useful for displaying a coffee or lunch break
  in a schedule.

See also http://groups.drupal.org/node/2879 for background discussion.

This is my first patch, hopefully done correctly:
To add the two new files, the patch was created using the procedure described here: http://drupal.org/diffandpatch#comment-147010

It wasn't clear to me which directory I should create the patch from. The cvs diff only seems to work from within the module/views_bonus directory, so that's where I created it from.

The patch applied back to a test instance correctly, so hopefully it's good. If not, please point me to correct reference for creating a patch for a contributed module and/or advise on what's wrong.

Cheers!

Comments

moshe weitzman’s picture

I'd like to commit this ... Is there any way to refactor so we can emit tables through theme('table') instead of writing out own table tags?

your patch applied nicely. bonus points for figuring out how to put new files in there. many people never get that.

i will try to review it more one of these days.

webchick’s picture

Status: Active » Needs review

This is a patch.

I'll be trying to test this momentarily.

webchick’s picture

Status: Needs review » Needs work
StatusFileSize
new38.49 KB

Hm. This is not working for me... I am trying to use this on the 2007.oscms-summit.org website. See attached screenshot. What we're shooting for is something like: http://localhost/oscms/schedule

What I've got:
- Views Bonus HEAD (just checked out an hour ago; the 5.x-1.0 release seemed to be missing a bunch of files)
- Views 5.x-1.5
- CCK 5.x-1.4
- Date 5.x-1.3

Note that I've also tried HEAD versions of all four modules; didn't make a difference.

"Session" CCK type. Relevant fields:
- field_start - datestamp field
- field_room - multiselect text field (sessions can span multiple rooms)

"schedule" View:
- Provide page type = checked
- View type: Bonus: Cross Table - Basic (also tried extended)
- Use pager: unchecked
- Nodes per page: 99
- Fields (left defaults for the options):
#1: field_start
#2: field_room
#3: Node title
- Filters:
- Node type is one of "Session"

Here's a pastebin of the CCK type export and the View:

http://pastebin.ca/386754

Now, there could be a couple things going on here:
1. The conference spans two days, where http://2007.northernvoice.ca/schedule is just a single day. I can get around this once the crosstab stuff is working by passing arguments into the View and then creating a page that embeds the View twice, each with different arguments.
2. A bunch of changes to Date module recently took place... not sure if this code was written against an older version.

At any rate, something is clearly amiss. ;)

webchick’s picture

k, problem #1:

  $tablecells = array();
  $colnames = array();
  foreach ($nodes as $node) {
    $row    = $node->$rowfieldname; /// There is no $node->rowfieldname...
    $column = $node->$colfieldname; /// Nor a $node->colfieldname...
    if (!in_array($column,$colnames)) {
      $colnames[] = $column;  /// So $colnames is always $colnames[0] => NULL
    }
    $tablecells[$row][$column][] = $node; /// $tablecells is an array like $tablecells[1174575600] => "" => array(0 => ...., 1 => ...., 2 => ....));
  }
webchick’s picture

Oops! I misread the code. :) That's referring to the variables that were created up above, and that code is working properly.

Instead, what's happening is the node doesn't have the room field as one of its values when I print_r($node). For example:

    [0] => stdClass Object
        (
            [nid] => 268
            [node_data_field_start_field_start_value] => 1174558500
            [node_data_field_start_field_start_value2] => 1174562100
            [node_title] => OpenID : In Drupal core and your CMS too
            [node_changed] => 1173380496
        )

Traipsing through views_build_view now...

webchick’s picture

K, the multivalue text field was the problem. Removing the multiple value checkbox now gives me a crosstable like I'd expect. Working on the formatting issues...

webchick’s picture

StatusFileSize
new9.65 KB

Bleh. This hurts my head. :(

I've updated the patch to use theme('table') for the basic view. I've also made _format_cell_item into a theme function, so you can override this if need be (which is the only way I'm going to be able to get this to work, I think....).

This line:

    $row[] = array('data' => $tablerowname, 'class' => 'rowlabel');

needs... "something".. so that it uses the field's theme function, rather than just outputting to the browser. I'm assuming it's something like what theme_crosstab_item is doing:

views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view)

... but my head is throbbing so I can't figure this out just now. :P

Looking at the code for the Extended View type... it seems like it would be more robust if it could support a multiselect field for the X axis, rather than just "All" or "one"... then you wouldn't need an extended vs. basic at all. I'll give it another shot after dinner, but don't bet on too much. :(

webchick’s picture

StatusFileSize
new10.19 KB

Ok, here's as far as I can take this...

* Added custom validation routine, to remove the validation code from the theme function.
* Eliminated the Extended Cross Tab. Technically, this is a loss in functionality, but with all the duplicated code I think it's better to scrap that way and come up with a more elegant solution...
* Date formatting issue still exists :(
* Still need logic for colspan (and row span?) ... I can't figure out why Views and multiple value CCK fields don't want to play nicely together.

Anyway, thanks still for this patch and your documentation on the groups post. While I unfortunately can't end up using this for the OSCMS schedule, I can generate a static HTML page very easily using this View and then some small manual tweaking.

dww’s picture

apparently, this is exactly what i need for the "Event reply grid" i mention here: http://groups.drupal.org/node/3430
so, perhaps i'll be able to pick up the torch on this and get it RTBC at some point in the not-too-distant-future. if anyone else can make more progress before then, great -- i'll reply and assign this to myself if/when i actually start working on it.

dww’s picture

i've started playing with this and looking more closely at the code. the most critical limitation at this point is that none of the view field formatting handlers are dealt with at all. so, if you put a field in a cross table view that has any special formatting or handling at all, you just see the raw data, not the nicely formatted version. :( for example, node titles (as either column or row headers, or as the "payload" in the boxes) never show up as links, even if that's what you ask for when defining the view. in my case, signup_views.inc has a bunch of nice formatting stuff, all of which is being ignored by the current patch.

the code is also full of // TODO comments about unifying "cross table" and "extended cross table", and that certainly seems like a good move...

hopefully i'll be able to work on this at some point soon, but i'm not yet assigning this issue to myself, since i can't promise when i'd be able to actually start. if i find any other problems, i'll post them here, too...

dww’s picture

Assigned: Unassigned » dww
StatusFileSize
new10.74 KB

ok, i just spent a little while trying to grok the code more closely, and how views_theme_field() works. turns out i was a little wrong: the views formatting stuff (care of views_theme_field()) *does* work in the table cell "payload", just not in the header row and column. that's now fixed with the attached patch.

also, i ripped out a manual call to sort() on the column headers, so that (it seems) the default node sorting order you specify in the views UI is the sort order for the columns.

everything else is still // TODO, but at least i now understand the code a little better. ;)

for my specific needs, i'd really like to have some additional fields that are treated as if they were part of the header, which is going to create *big* problems, both from the views UI, and since theme('table') can't handle having more than 1 row as the header row. :( not exactly sure what i'm going to do about that, i'll try to find merlin on IRC and get some advice. maybe i should just go back to writing a custom query for my site for my "Event reply grid" and forget about doing it via views... ;)

rweait’s picture

Cross Tables View Type is AMAZING. Y'all rock with the volume at eleven.

mlncn’s picture

um, subscribing. Just to let dww know i care.

benjamin, Agaric Design Collective

tostinni’s picture

Does this will open the way to do COUNT/SUM in each cells to have som summaries like:

  Time  Room 101          Room 102
  ====  ================  =============
  10am  2 attendees       5 attendees
  11am  10 attendees      7 attendees

Thanks a lot for this new module.

mroswell’s picture

This looks cool. Did anything ever come of this? What would I apply that patch to? (how, I need to learn....) Will it still work more than a year later? (Did it ever work?)

dww’s picture

Assigned: dww » Unassigned

Nope, I ran out of time/interest. I might be working on this again in the future, but clearly not for over a year now, so this has no business being assigned to me. ;) You'd apply it to a views_bonus directory in your modules folder. Mostly, it's just adding 2 new files. See http://drupal.org/patch/apply for docs.

aquila’s picture

Did anyone ever follow up this patch? It looks like really interesting views functionality, especially to present data in a very clear way. It just seems to make sense to present data like this.

owen barton’s picture

Status: Needs work » Fixed

I just committed a new module for Views 2 that does crosstabs - http://drupal.org/project/views_crosstab.

Status: Fixed » Closed (fixed)

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

jhodgdon’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Closed (fixed) » Needs work

The module Owen Barton committed is different (it just counts the number of nodes in each cell as #14 was requesting, rather than listing node attributes as in torealad's original proposal, which could be used to make a schedule grid for example).

And the Views Crosstab module apparently doesn't work with Views 2 and is apparently abandoned. So I think this issue was closed as "fixed" in #18 in error.

This still seemsm like a reasonably good feature request. People need to make schedules like this all the time, and I don't think Views has a way to do them very easily. I've done custom theming to do this, but it could be a nice plugin.

owen barton’s picture

I am not sure which views crosstab you mean - but http://drupal.org/project/views_crosstab is for views 2 and is certainly not abandoned (I am not actively working on it, but I plan to in the future, and will happily submit patches if anyone cares to put them together).

I haven't looked at if it would work for the use case in the description, but I think it should be capable of it - right now it assumes some kind of aggregation, but I think that could be changed. If anyone wants to look at adding this to views_crosstab (rather than as a somewhat-duplicate module), please move this ticket to the "Views Crosstab" project.

jhodgdon’s picture

Ah, my mistake. I assumed since there had been no activity for half a year and no response to issues in the queue filed 10 weeks ago that the project had been abandoned.

Anyway, it definitely doesn't currently cover the use case mentioned here.

ezra-g’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev

Unless I'm horribly mistaken, this patch is actually for the 5.x branch.

dale42’s picture

Status: Needs work » Closed (fixed)

This was originally submitted (by me) for Views 1 and didn't get the traction it needed to get included in the bonus pack. Since there is now a cross-tabs views module, closing this issue seems the correct thing to do.