/** * @param string $type * @param ExportPrefs $exportPrefs * @return \ArrayObject|string * @throws \Exception */ public function export($type, ExportPrefs $exportPrefs) { $exporter = null; $datasWithChoices = $this->prepareExport($exportPrefs); switch (strtolower($type)) { case 'dwc': $exporter = new DwcExporter($datasWithChoices, $this->getExportDirPath(), $this->userGroup); break; case 'csv': $exporter = new CsvExporter($datasWithChoices, $this->getExportDirPath(), $this->userGroup); } if ($exporter instanceof AbstractExporter) { return $exporter->generate($this->user->getPrefs()); } else { throw new \Exception(sprintf('exporter %s has not been found', $type)); } }
/** * @param Prefs $prefs * @param array $options * @return string */ public function generate(Prefs $prefs, array $options = []) { $this->setDwcDelimiter($prefs->getDwcDelimiter()); $this->setDwcEnclosure($prefs->getDwcEnclosure()); $this->setDwcLineBreak($prefs->getDwcLineBreak()); $this->setDwcDateFormat($prefs->getDwcDateFormat()); $this->formattedDatas = $this->formatDatas(); $csvExporter = new CsvExporter($this->formattedDatas, $this->getExportDirPath(), $this->userGroup); $this->csvFiles = $csvExporter->generate($prefs, ['dwc' => true]); $fileExport = new Filesystem(); $fileName = $this->getExportDirPath() . '/meta.xml'; $fileExport->touch($fileName); file_put_contents($fileName, $this->generateXmlMeta()); return $this->createZipFile(); }