Beispiel #1
0
 private function getCSVResponse(Application $app, \module_report $report, $type)
 {
     // set headers
     $headers = [];
     foreach (array_keys($report->getDisplay()) as $k) {
         $headers[$k] = $k;
     }
     // set headers as first row
     $result = $report->getResult();
     array_unshift($result, $headers);
     $collection = new CallbackCollection($result, function ($row) use($report) {
         // restrict fields to the displayed ones
         return array_map('strip_tags', array_intersect_key($row, $report->getDisplay()));
     });
     $filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
     $response = new CSVFileResponse($filename, function () use($app, $collection) {
         $app['csv.exporter']->export('php://output', $collection);
     });
     return $response;
 }
 private function getCSVResponse(\module_report $report, $type)
 {
     // set headers
     $headers = [];
     foreach (array_keys($report->getDisplay()) as $k) {
         $headers[$k] = $k;
     }
     // set headers as first row
     $result = $report->getResult();
     array_unshift($result, $headers);
     $collection = new CallbackCollection($result, function ($row) use($headers) {
         // restrict fields to the displayed ones
         //    return array_map("strip_tags", array_intersect_key($row, $report->getDisplay()));
         $ret = array();
         foreach ($headers as $f) {
             $ret[$f] = array_key_exists($f, $row) ? strip_tags($row[$f]) : '';
         }
         return $ret;
     });
     $filename = sprintf('report_export_%s_%s.csv', $type, date('Ymd'));
     /** @var Exporter $exporter */
     $exporter = $this->app['csv.exporter'];
     $cb = function () use($exporter, $collection) {
         $exporter->export('php://output', $collection);
     };
     $response = new CSVFileResponse($filename, $cb);
     return $response;
 }