public static function exportToCsv()
 {
     global $wpdb;
     $tables = array(CruiseEntry::TABLE_NAME => 'cruise', FestivalEntry::TABLE_NAME => 'festival', MurderMysteryEntry::TABLE_NAME => 'murder-mystery', ParadeEntry::TABLE_NAME => 'parade', Donation::TABLE_NAME => 'donation', FlagHandle::TABLE_NAME => 'flag-handle', Sponsorship::TABLE_NAME => 'sponsorship');
     $year = isset($_POST['pride_export']) && is_numeric($_POST['pride_export']) ? abs(round($_POST['pride_export'])) : NULL;
     $table = isset($_POST['table']) && array_key_exists($_POST['table'], $tables) ? $_POST['table'] : NULL;
     header('Content-type: text/csv');
     if ($table === NULL) {
         header('Content-disposition: attachment;filename=export.csv');
         echo 'No Data to Export';
     } else {
         header('Content-disposition: attachment;filename=' . ($year !== NULL ? $year : 'all') . '-' . $tables[$table] . '-entries.csv');
         echo "Entry Date,Entry Year,Organization,First Name,Last Name,Email,Phone,Address,City,State,Zip,";
         switch ($table) {
             case FestivalEntry::TABLE_NAME:
                 echo "Entry Type,Corner Booth,";
                 break;
             case MurderMysteryEntry::TABLE_NAME:
                 echo "Upgraded Meal,Vegetarian Count,Entry Type,";
                 break;
             case ParadeEntry::TABLE_NAME:
                 echo "Entry Types,Description,Parking Spots,Amped Sound,Group Size,Donation,";
                 break;
             case Donation::TABLE_NAME:
                 echo "Donation,";
                 break;
             case FlagHandle::TABLE_NAME:
                 echo "Message,Color,";
                 break;
         }
         echo "Qty,Amount Due,Amount Paid,Payment Method,Paid On,Notes";
         $rows = $wpdb->get_results("\n\t\t\t\tSELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\t" . $wpdb->prefix . $table . "\n\t\t\t\tWHERE\n\t\t\t\t\tentry_year " . ($year === NULL ? " > 0 " : " = " . $year) . "\n\t\t\t\tORDER BY\n\t\t\t\t\tid ASC");
         if ($rows) {
             foreach ($rows as $row) {
                 switch ($table) {
                     case CruiseEntry::TABLE_NAME:
                         $entry = new CruiseEntry();
                         break;
                     case FestivalEntry::TABLE_NAME:
                         $entry = new FestivalEntry();
                         break;
                     case MurderMysteryEntry::TABLE_NAME:
                         $entry = new MurderMysteryEntry();
                         break;
                     case ParadeEntry::TABLE_NAME:
                         $entry = new ParadeEntry();
                         break;
                     case Donation::TABLE_NAME:
                         $entry = new Donation();
                         break;
                     case FlagHandle::TABLE_NAME:
                         $entry = new FlagHandle();
                         break;
                     case Sponsorship::TABLE_NAME:
                         $entry = new Sponsorship();
                         break;
                     default:
                         $entry = new Entry();
                 }
                 $entry->loadFromRow($row);
                 echo "\r\n";
                 echo $entry->getCreatedAt('n/j/Y') . ',';
                 echo $entry->getEntryYear() . ',';
                 echo '"' . str_replace('"', '""', $entry->getOrganization()) . '",';
                 echo '"' . str_replace('"', '""', $entry->getFirstName()) . '",';
                 echo '"' . str_replace('"', '""', $entry->getLastName()) . '",';
                 echo '"' . str_replace('"', '""', $entry->getEmail()) . '",';
                 echo '"' . str_replace('"', '""', $entry->getPhone()) . '",';
                 echo '"' . str_replace('"', '""', $entry->getAddress()) . '",';
                 echo '"' . str_replace('"', '""', $entry->getCity()) . '",';
                 echo '"' . str_replace('"', '""', $entry->getState()) . '",';
                 echo '"' . str_replace('"', '""', $entry->getZip()) . '",';
                 switch ($table) {
                     case FestivalEntry::TABLE_NAME:
                         echo '"' . str_replace('"', '""', $entry->getEntryType()) . '",';
                         echo ($entry->isCornerBooth() ? 'Y' : 'N') . ',';
                         break;
                     case MurderMysteryEntry::TABLE_NAME:
                         echo ($entry->isUpgraded() ? 'Y' : 'N') . ',';
                         echo $entry->getVegetarianQty() . ',';
                         echo ($entry->isSponsor() ? 'Table' : 'Ticket') . ',';
                         break;
                     case ParadeEntry::TABLE_NAME:
                         echo '"' . str_replace('"', '""', implode(',', $entry->getEntryTypes())) . '",';
                         echo '"' . str_replace("\n", ' ', str_replace("\r", ' ', str_replace('"', '""', $entry->getDescription()))) . '",';
                         echo $entry->getFloatParkingSpaces() . ',';
                         echo ($entry->needsAmpedSound() ? 'Y' : 'N') . ',';
                         echo $entry->getGroupSize() . ',';
                         echo $entry->getDonationAmount() . ',';
                         break;
                     case Donation::TABLE_NAME:
                         echo $entry->getDonationAmount() . ',';
                         break;
                     case FlagHandle::TABLE_NAME:
                         echo '"' . str_replace("\n", ' ', str_replace("\r", ' ', str_replace('"', '""', $entry->getMessage()))) . '",';
                         echo '"' . str_replace("\n", ' ', str_replace("\r", ' ', str_replace('"', '""', $entry->getColor()))) . '",';
                         break;
                 }
                 echo $entry->getQty() . ',';
                 echo $entry->getTotal() . ',';
                 echo $entry->getPaymentAmount() . ',';
                 echo '"' . str_replace('"', '""', $entry->getPaymentMethod($entry->getPaymentMethodId())) . '",';
                 echo $entry->getPaidAt('n/j/Y') . ',';
                 echo '"' . str_replace("\n", ' ', str_replace("\r", ' ', str_replace('"', '""', $entry->getNotes()))) . '",';
             }
         }
     }
     exit;
 }
Example #2
0
 /**
  * @covers Geissler\Converter\Model\Entry::setAddress
  * @covers Geissler\Converter\Model\Entry::getAddress
  */
 public function testAddress()
 {
     $data = 'test data';
     $this->assertInstanceOf($this->class, $this->object->setAddress($data));
     $this->assertEquals($data, $this->object->getAddress());
 }