Support

Home Forums Event Espresso Premium Customize Attendee List with Custom Question's Data in Serialized Array

Customize Attendee List with Custom Question's Data in Serialized Array

Posted: September 18, 2017 at 4:41 pm

Viewing 1 reply thread


BoostersInABox

September 18, 2017 at 4:41 pm

I am trying to get the answers from 3 custom questions (two of them store the answer as a serialized array) and the answers for 2 standard questions.

Here is my content-espresso_event_attendees.php with changes that I made:

<?php
/**
* Content Template for the [ESPRESSO_EVENT_ATTENDEES] shortcode
*
* Please be sure to change the Question ID on line 19 to match your custom Question ID
*
* Template Args that are available in this template
* @type EE_Attendee $contact
* @type EE_Event $event
* @type bool $show_gravatar whether to show gravatar or not.
*/
$custom_question_output = ”;
if( $contact instanceof EE_Attendee ) {
$prev_answer_value = EEM_Answer::instance()->get_var(
array(
array(
‘Registration.ATT_ID’ => $contact->ID(),
‘Registration.EVT_ID’ => $event->ID(),
‘QST_ID’ => 11 // Custom Question 11 Athlete Name
),
‘order_by’ => array(
‘ANS_ID’ => ‘DESC’
),
‘limit’ => 1
),
‘ANS_value’ );
if( $prev_answer_value ) {
$custom_question_output = ‘ — ‘ . $prev_answer_value;
}

$grade = ”;
if( $contact instanceof EE_Attendee ) {
$prev_answer_value = EEM_Answer::instance()->get_var(
array(
array(
‘Registration.ATT_ID’ => $contact->ID(),
‘Registration.EVT_ID’ => $event->ID(),
‘QST_ID’ => 12 // Custom Question 12 Athlete Grade
),
‘order_by’ => array(
‘ANS_ID’ => ‘DESC’
),
‘limit’ => 1
),
‘ANS_value’ );
if( $prev_answer_value ) {
$grade = ‘ — ‘ . $prev_answer_value;
}

$team = ”;
if( $contact instanceof EE_Attendee ) {
$prev_answer_value = EEM_Answer::instance()->get_var(
array(
array(
‘Registration.ATT_ID’ => $contact->ID(),
‘Registration.EVT_ID’ => $event->ID(),
‘QST_ID’ => 13 // Custom Question 13 Athlete Team
),
‘order_by’ => array(
‘ANS_ID’ => ‘DESC’
),
‘limit’ => 1
),
‘ANS_value’ );
if( $prev_answer_value ) {
$team = ‘ — ‘ . $prev_answer_value;
}

}
if ( $show_gravatar ) {
$gravatar = get_avatar( $contact->email(),
(int) apply_filters( ‘FHEE__loop-espresso_attendees-shortcode__template__avatar_size’, 32 )
);
} else {
$gravatar = ”;
}
?>
<?php do_action( ‘AHEE__content-espresso_event_attendees__before’, $contact, $show_gravatar ); ?>

  • <?php echo $gravatar . ‘ ‘ . $contact->full_name() . ‘ — ‘ . $contact->email() . ‘ — ‘ . $contact->phone() . $custom_question_output; . ‘ — ‘ . $grade; . ‘ — ‘ . $team; ?>
  • Here is the loop-espresso_event_attendees.php

    <?php
    /**
    * Loop Template for the [ESPRESSO_EVENT_ATTENDEES] shortcode
    *
    * @package Event Espresso
    * @subpackage templates
    * @since 4.6.29
    * @author Darren Ethier
    *
    * Template Args that are available in this template (yarr!)
    * @type EE_Attendee[] $contacts
    * @type EE_Event $event
    * @type EE_Datetime|null $datetime an EE_Datetime object will be available if the the datetime_id attribute is set in the shortcode and the id matches a valid datetime.
    * @type EE_Ticket|null $ticket an EE_Ticket object will be available if the the ticket_id attribute is set in the shortcode and the id matches a valid ticket.
    * @type bool $show_gravatar whether to show gravatar or not.
    */

    $no_attendees_message = apply_filters( ‘FHEE__loop-espresso_attendees-shortcode__template__no_attendees_message’, __(‘No Attendees Yet’, ‘event_espresso’ ) );

    $grade = ‘a:1:{i:0;s:3:”9th”;}a:1:{i:0;s:4:”10th”;}a:1:{i:0;s:4:”12th”;}’;
    $grade = unserialize($grade);
    echo $grade[‘Grade: ‘][0];

    $team = ‘a:1:{i:0;s:7:”Varsity”;}a:1:{i:0;s:10:”JV-Black”;}a:1:{i:0;s:11:”JV-Silver”;}a:1:{i:0;s:16:”Freshman-Black”;}a:1:{i:0;s:17:”Freshman-Silver”;}a:1:{i:0;s:17:”Freshman-White”;}a:1:{i:0;s:23:”Don’t Know At This Time”;}’;
    $team = unserialize($team);
    echo $team[‘Team: ‘][0];

    ?>

    <div class=”event-attendees”>
    <?php do_action( ‘AHEE__loop-espresso_event_attendees__before’, $contacts, $event, $datetime, $ticket, $show_gravatar ); ?>
    <?php if ( $contacts ) : ?>

      <?php foreach( $contacts as $contact ) :
      EEH_Template::get_template_part( ‘content’, ‘espresso_event_attendees’, array(
      ‘contact’ => $contact,
      ‘event’ => $event,
      ‘datetime’ => $datetime,
      ‘ticket’ => $ticket,
      ‘show_gravatar’ => $show_gravatar
      ) );
      endforeach; ?>

    <?php else : ?>
    <p><?php echo $no_attendees_message; ?></p>
    <?php endif; ?>
    <?php do_action( ‘AHEE__loop-espresso_event_attendees__after’, $contacts, $event, $datetime, $ticket, $show_gravatar ); ?>
    </div>

    I know that I missing something simple…. just can’t figure out why it won’t work. Thanks for taking a look!


    Josh

    • Support Staff

    September 18, 2017 at 5:04 pm

    In the future can you please post large blocks of code into a gist or pastebin, then link here?

    The code you posted here appears to be trying to access the data with the wrong array keys. It may help to add some debugging to your code to find the correct array keys. e.g. print_r($array);.

    Viewing 1 reply thread

    The support post ‘Customize Attendee List with Custom Question's Data in Serialized Array’ is closed to new replies.

    Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

    Event Espresso