Esempio n. 1
0
 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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
 public function testGetterSetter()
 {
     $report = new module_report(self::$DI['app'], $this->dmin, $this->dmax, 1, '');
     $bool = true;
     $report->setPrettyString($bool);
     $this->assertEquals($bool, $report->getPrettyString());
     $title = 'test';
     $report->setTitle($title);
     $this->assertEquals($title, $report->getTitle());
     $bool = false;
     $report->setCsv($bool);
     $this->assertEquals($bool, $report->getCsv());
     $filter = ['test', 'array'];
     $report->setFilter($filter);
     $this->assertEquals($filter, $report->getTabFilter());
     $periode = "2 years";
     $report->setPeriode($periode);
     $this->assertEquals($periode, $report->getPeriode());
     $postingFilter = 'my posting filter !';
     $report->setpostingFilter($postingFilter);
     $this->assertEquals($postingFilter, $report->getPostingFilter());
     $page = 223;
     $limit = 125;
     $report->setLimit($page, $limit);
     $this->assertEquals($page, $report->getNbPage());
     $this->assertEquals($limit, $report->getNbRecord());
     $report->setGroupBy($bool);
     $this->assertEquals($bool, $report->getGroupBy());
     $column = ['col1', 'col2'];
     $report->setActiveColumn($column);
     $this->assertEquals($column, $report->getActiveColumn());
     $report->setConfig($bool);
     $report->setPrint($bool);
     $report->setHasLimit($bool);
     $this->assertFalse($report->getConfig());
     $this->assertFalse($report->getPrint());
     $this->assertFalse($report->getHasLimit());
     $result = ['result', 'result'];
     $report->setResult($result);
     $this->assertEquals($result, $report->getResult());
     $total = 3200;
     $report->setTotal($total);
     $this->assertEquals($total, $report->getTotal());
     $default_display = ['a', 'b', 'c'];
     $report->setDefault_display($default_display);
     $this->assertEquals($default_display, $report->getDefault_display());
 }