Jump to:

10990 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » User Defined Forms Export - Adding Dates To CSV

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1045 Views
  • Usability Counts
    Avatar
    Community Member
    5 Posts

    User Defined Forms Export - Adding Dates To CSV Link to this post

    I added this to SubmittedFormReportField.php. Here's the code:
                   
                   foreach($tmp as $array) {
                      $csvHeaderNames[] = $array['Name'];
                      $csvHeaderTitle[] = $array['Title'];
                   }

                   // Get the created dates for each record (ADD THIS)

                   $strCreated = "SELECT DISTINCT Created FROM SubmittedForm WHERE ID IN (" . implode(',', $inClause) . ")";

                   $tmpCreated = DB::query($strCreated);
                   foreach($tmpCreated as $array) {
                      $csvCreated[] = $array['Created'];
                   }

    And...

    // For every row of data (one form submission = one row) (SLIGHTLY MODIFFIED)
                   foreach($rows as $row) {
                      
                      // Loop over all the names we can use
                      $csvData .= "\"" . $csvCreated[$j] . "\", ";
                      $j++;
                      
                      for($i=0;$i<count($csvHeaderNames);$i++) {
    // If there is no data for this column, output it as blank instead
                         if(!isset($row[$i]) || !$row[$i]) {
                            $csvData .= '"",';
                         } else {
                            $csvData .= '"'.str_replace('"', '\"', $row[$i]).'",';
                         }
                      }
                      // Start a new row for each submission
                      $csvData .= "\n";
                   }

    1045 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.