/** * @return Listing */ protected function getListing() { $config = \Pimcore\Model\Tool\CustomReport\Config::getByName($this->reportId); $configuration = $config->getDataSourceConfig(); $adapter = \Pimcore\Model\Tool\CustomReport\Config::getAdapter($configuration, $config); $result = $adapter->getData(null, $this->emailFieldName, 'ASC', null, null); $this->list = $result['data']; $this->elementsTotal = intval($result["total"]); $this->emailAddresses = []; foreach ($this->list as $row) { if (isset($row[$this->emailFieldName])) { $this->emailAddresses[] = $row[$this->emailFieldName]; } } return $this->list; }
public function downloadCsvAction() { set_time_limit(300); $sort = $this->getParam("sort"); $dir = $this->getParam("dir"); $filters = $this->getParam("filter") ? json_decode($this->getParam("filter"), true) : null; $drillDownFilters = $this->getParam("drillDownFilters", null); $includeHeaders = $this->getParam('headers', false); $config = CustomReport\Config::getByName($this->getParam("name")); $columns = $config->getColumnConfiguration(); $fields = []; foreach ($columns as $column) { if ($column['export']) { $fields[] = $column['name']; } } $configuration = $config->getDataSourceConfig(); //if many rows returned as an array than use the first row. Fixes: #782 $configuration = is_array($configuration) ? $configuration[0] : $configuration; $adapter = CustomReport\Config::getAdapter($configuration, $config); $result = $adapter->getData($filters, $sort, $dir, null, null, $fields, $drillDownFilters); $exportFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/report-export-" . uniqid() . ".csv"; @unlink($exportFile); $fp = fopen($exportFile, 'w'); if ($includeHeaders) { fputcsv($fp, $fields); } foreach ($result['data'] as $row) { fputcsv($fp, array_values($row)); } fclose($fp); header('Content-type: text/csv; charset=UTF-8'); header("Content-Length: " . filesize($exportFile)); header("Content-Disposition: attachment; filename=\"export.csv\""); while (@ob_end_flush()) { } flush(); readfile($exportFile); exit; }