0

I posted this a week ago at the drupal.org issue queue for Views PHP, but have not received a single response, so I'm hoping someone here can help me.

I have a view that displays a conference schedule. Each session is associated with a track (taxonomy), and gets a track icon to display. There's also one or more speakers per session (entity references to the speaker nodes). There's one type of session that needs to be associated with all the track types, but we don't want it to have a visual indicator. In order to get the icon to display conditionally, I used a Global PHP field. It prints the icon (if the conditions are correct) and then the session number and title, all on a single line. This works. The view is grouped first by date/time, so all sessions on Wednesday at 10 AM show up under a single heading. This also works. Here's the output code of the Global PHP field:

<?php
if(isset($data->field_field_hide_track[0]['raw']['value'])) {
    if($data->field_field_hide_track[0]['raw']['value'] == '0') {

    $image_vars = array(
        'path' => file_create_url($data->field_field_track_icon[0]["rendered"]["#item"]["uri"]),
        'alt' => $data->field_field_track_icon[0]["rendered"]["#item"]["alt"],
        'attributes' => array(
          'class' => array('session_list_track_logo')
        )
      );

    $track_logo = theme('image', $image_vars);
    print "<h3>" . $track_logo . " " . $data->field_field_session_number[0]['raw']['value'] . " | " . $row->title . "</h3>";
    }
    else {
      print "<h3>" . $data->field_field_session_number[0]['raw']['value'] . " | " . $row->title . "</h3>";
    }
}
?>

Before adding the Global PHP, it was secondarily grouped by a dummy field that had its output rewritten to concatenate session number and session title. (both individual fields were hidden from display.) This worked, but we couldn't display the icon conditionally.

That's where the Global PHP field comes in. If I group by date/time and then by the php field, it's inconsistent between session records. Sometimes it prints the php field twice, regardless of how many speakers there are. Sometimes it prints it once for each speaker. Sometimes it prints once for the first speaker, and a second time for the next chunk of speakers.


grouped by date/time and session number (both excluded from display); displaying php field enter image description here


grouped by date/time and php field (both excluded from display enter image description here


I've also tried grouping by all possible common fields (date/time, session number, session title, icon, and php field) which gives me such a mess I couldn't even get a decent screenshot of it because a single record doesn't fit on my screen!

This is the desired result: enter image description here

I'm attaching screenshots of all of these, as well as a mockup shot of the desired result. Can anyone help me out? (Note that the groupBySessionNumber.png screenshot was taken after the Global PHP field was added, and the icon/number/title line is a result of that field.)

1 Answer 1

1

Consider using a Computed Field on the Session content type to combine

  • the icon (conditionally)
  • the session number
  • the session title

Then you can use that field for the secondary sort, and leave the Global PHP out of the View. Be sure to store the computed field in the database so that Views can access it.

1
  • That looks like it might be a tremendous help. I'll look at it - thanks.
    – EmmyS
    Commented Jun 14, 2012 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.