When the user responds "no" to the invitation, their totalguests value should be 0 because logically if they're not attending then they shouldn't take up a seat. Right now it stays at 1, and this is then used elsewhere to build totals, e.g. the guest list.

Comments

firebus’s picture

Status: Active » Closed (works as designed)

i think this is correct behavior, or else you need to provide more specifics about how this is a bug.

when a guest responds no, they are added to the "Attend not" section of the guest list. that is to say, there is now one user not attending the event. it's useful to know how many guests have said they are not attending, and it makes sense to use totalguests for this.

it's certainly possible that there's a bug, however, where total guests for the whole event is being calculated but response is not being respected, so that non-attending guests are being counted. if you've found a bug like this, please be specific, and explain how to reproduce it.

thanks!

damienmckenna’s picture

Status: Closed (works as designed) » Active

When you export the list as a CSV you should not see non-zero numbers for people who have said they are not coming. If you total up the totalguests column it should only include people who have either confirmed, haven't responded or have said "maybe" - the total should not account for people who are *not* coming.

firebus’s picture

Hmm. I still think this might be by design.

Some users might want to know how many total guests, including "no"s. Some users might want only "yes" or "maybe" like you. Some users might want only "yes". I like to come up with a probability formula based on the percentage yes and percentage no to figure out the likely end value for maybe :)

Does it say in the spreadsheet what the reply is? If so, you should be able to make a formula in the spreadsheet that repects the reply column instead of just summing the whole list. Or use a filter to remove the "no"s before writing your formula.

I'll take a look at the spreadsheet (on my installation it doesn't seem to be working at all, but i've hacked some stuff so i need to check on a default install) and see if there's any way to make it clearer...

firebus’s picture

aha, export wasn't working because i needed your patch from http://drupal.org/node/961858 :)

okay, IMO this is by design and you should write an excel function to calculate or group your rows according to response. for example, you could use the subtotals function.

but i'm not going to change the category back to by design if you disagree with me :)

sdsheridan’s picture

Well, instead of forcing the user to have to fiddle with Excel functions after a download (one of my clients is a lawyer... not going to happen!), why not have four columns for "yes", "no", "maybe", and "no response"? That way the end-user experience is easier, and they don't have to fiddle with Excel other than clicking the sigma button a few times.

Shawn

sdsheridan’s picture

Also, looking at the function rsvp_csv_hash_form, there seems to be a lot of unnecessary processing... or am I missing something? Creation of the header row in the CSV file seems to go through a lot of stuff (loops, function calls to strip slashes and replace double quotes with double-double quotes) when it looks like one could just output a simple sting... after all, the headers are enumerated in $field_list = array( 'response', 'email', 'invited', 'received', 'totalguests' );. So why can't you replace

  $attendees = rsvp_function_load_guests($rid);
  $attendee = db_fetch_object($attendees);
  $header = array();
  $content = '';

  //get header row
  foreach ($attendee as $key => $value) {
    if (in_array( $key, $field_list ))
      $header[]  = $key;
  }

and all of

  $result = '';

  $seperator     = ',';
  $enclosed      = '"';
  $escaped       = $enclosed;
  $add_character = "\015\012";
  $print = true;
  $schema_insert = '';
  foreach ( $header as $field ) {
    if ($enclosed == '') {
        $schema_insert .= stripslashes($field);
    }
    else {
        $schema_insert .=
              $enclosed
            . str_replace($enclosed, $escaped . $enclosed, stripslashes($field))
            . $enclosed;
    }
    $schema_insert     .= $seperator;
  } // end while

  // need to add PMA_exportOutputHandler functionality out here, rather than
  // doing it the moronic way of assembling a buffer
  $out = trim(substr($schema_insert, 0, -1)) . $add_character;
  if ($print) {
    echo $out;
  }
  else {
    $result .= $out;
  }

with (after the calls to header())

  echo '"' . implode('","', $field_list) . '"' . "\015\012";

particularly since the field list is single words, and the whole bit of logic that builds the $header array is just creating a copy of $field_list (which is clear when you look at the function rsvp_function_load_guests and see what it returns).

I'm also wondering why there's code like if ($print) {... when $print is set to true and never changed. Seems like a bit of a waste of memory and cycles, not to mention adding to the complexity.

Does this function need a good refactoring?

Shawn

sdsheridan’s picture

OK, here's the refactored function (with the old bits still there but commented out so you can see what I did). This seems to be working just fine and has the bonus of making it easy to see how many are in each category. I added the comment field too, as my client wanted to see that as part of the extract. Thoughts? Comments? Would be great if this was included in the next release.

Shawn

function rsvp_csv_hash_form(&$form_state, $rsvp, $invite_target) {

  $form = array();
  	
  //fields to export
  $field_list = array( 'response', 'email', 'invited', 'received', 'comment', 'totalguests' );

  if (is_null($rsvp)) {
    $rid = $invite_target->rid;
  }
  else {
    $rid = $rsvp->rid;
  }
  
/*  $attendees = rsvp_function_load_guests($rid);
  $attendee = db_fetch_object($attendees);
  $header = array();
  $content = '';

  //get header row
  foreach ($attendee as $key => $value) {
    if (in_array( $key, $field_list ))
      $header[]  = $key;
  } */
  
  $filename = str_replace(' ', '_', $rsvp->name) .'_'. date("Y-m-d") .'.csv';

  $now       = gmdate('D, d M Y H:i:s') .' GMT';
  $mime_type = 'text/x-csv';
  $ext       = 'csv';

  // send the write header statements to the browser
  header('Content-Type: '. $mime_type);
  header('Expires: '. $now);

  // lem9 & loic1: IE need specific headers
  $is_ie = strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' );
  if ($is_ie) {
    header('Content-Disposition: inline; filename="'. $filename .'"');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
  }
  else {
    header('Content-Disposition: attachment; filename="'. $filename .'"');
    header('Pragma: no-cache');
  }

/*  $result = ''; */

  $seperator     = ',';
  $enclosed      = '"';
  $escaped       = $enclosed;
  $add_character = "\015\012";
/*  $print = true;
  $schema_insert = '';
  foreach ( $header as $field ) {
    if ($enclosed == '') {
        $schema_insert .= stripslashes($field);
    }
    else {
        $schema_insert .=
              $enclosed
            . str_replace($enclosed, $escaped . $enclosed, stripslashes($field))
            . $enclosed;
    }
    $schema_insert     .= $seperator;
  } // end while

  // need to add PMA_exportOutputHandler functionality out here, rather than
  // doing it the moronic way of assembling a buffer
  $out = trim(substr($schema_insert, 0, -1)) . $add_character;
  if ($print) {
    echo $out;
  }
  else {
    $result .= $out;
  } */
  
  $header = array_merge($field_list, array('yes', 'no', 'maybe', 'no response',));
  echo '"' . implode('","', $header) . '"' . "\015\012";

//  $i = 0;   // --> this is never used, so not sure why it's here...
  $fields_cnt = count($field_list);

  $attendees = rsvp_function_load_guests($rid);

  while ($row = db_fetch_object($attendees)) {
      $schema_insert = '';
      $yes_no_maybe_noresp = array(
        'yes'    => '',
        'no'     => '',
        'maybe'  => '',
        'none'   => '',
      );
      foreach ( $row as $j => $value ) {
        if (in_array($j, $field_list)) {
          if ($j == 'response') {
            $which_one = $value;
          }
          elseif ($j == 'totalguests') {
            $yes_no_maybe_noresp[$which_one] = ( $which_one == 'no' ? 1 : $value );
          }
          elseif ($j == 'email') {
            $value = rsvp_function_getGuestEmail($row, true);
          }
        	
          if (!isset($value) || is_null($value)) {
            $schema_insert .= '';
          }
          else if ($value == '0' || $value != '') {
            // loic1 : always enclose fields
            $value = ereg_replace("\015(\012)?", "\012", $value);
            if ($enclosed == '') {
              $schema_insert .= $value;
            }
            else {
              $schema_insert .=
                    $enclosed
                  . str_replace($enclosed, $escaped . $enclosed, $value)
                  . $enclosed;
            }
          }
          else {
            $schema_insert .= '';
          }

//          if ($j < $fields_cnt-1) {  //--> suspect this is where $i was supposed to be used, but now we're always going to want the comma so no point in correcting the defect and having the 'if' here.
            $schema_insert .= $seperator;
//          }
        } //end in field_list
      } // end foreach

      $out = $schema_insert . implode(',', $yes_no_maybe_noresp) . $add_character;
      echo $out;
/*      if ($print) {
        echo $out;
      }
      else {
        $result .= $out;
      }
      ++$i; */

  } // end for

  exit();
  
}