Exemplo n.º 1
0
 /**
  * @param Prefs $prefs
  * @param array $options
  * @return \ArrayObject|string
  */
 public function generate(Prefs $prefs, array $options = [])
 {
     if (isset($options['dwc']) && $options['dwc'] === true) {
         $this->setCsvDelimiter($prefs->getDwcDelimiter());
         $this->setCsvEnclosure($prefs->getDwcEnclosure());
         $this->setCsvLineBreak($prefs->getDwcLineBreak());
         $this->setCsvDateFormat($prefs->getDwcDateFormat());
     } else {
         $this->setCsvDelimiter($prefs->getCsvDelimiter());
         $this->setCsvEnclosure($prefs->getCsvEnclosure());
         $this->setCsvLineBreak($prefs->getCsvLineBreak());
         $this->setCsvDateFormat($prefs->getCsvDateFormat());
     }
     $filesHandler = [];
     /* @var \AppBundle\Business\Exporter\Entity\AbstractEntityExporter $entityExporters [] */
     $entityExporters = [];
     $entitiesNameWithArray = ['Determination', 'Multimedia', 'Bibliography'];
     foreach ($this->datas as $key => $record) {
         foreach ($record as $className => $datasPerClass) {
             if (!isset($entityExporters[$className])) {
                 $entityExporters[$className] = $this->getEntityExporter($className);
             }
             // Creation des fichiers
             if (!isset($filesHandler[$className])) {
                 $this->createFile($className);
                 $filesHandler[$className] = fopen($this->files[$className]->getPathname(), 'w');
                 // Ecrit les entêtes en première ligne de csv
                 $this->fieldsName[$className] = $entityExporters[$className]->getKeysEntity();
                 $this->writeToFile($filesHandler[$className], $this->fieldsName[$className]);
             }
             if (in_array($className, $entitiesNameWithArray)) {
                 // Traitement des extensions qui peuvent avoir plusieurs enregistrements pour un specimen
                 foreach ($datasPerClass as $arrayRecord) {
                     $filteredDatas = $this->filterDatas($arrayRecord, $entityExporters[$className], $className);
                     $this->writeToFile($filesHandler[$className], $filteredDatas);
                 }
             } else {
                 // traitement des extensions n'ayant qu'un enregistrement par specimen
                 $filteredDatas = $this->filterDatas($datasPerClass, $entityExporters[$className], $className);
                 $this->writeToFile($filesHandler[$className], $filteredDatas);
             }
         }
     }
     foreach ($filesHandler as $className => $fileHandler) {
         fclose($fileHandler);
     }
     if (isset($options['dwc']) && $options['dwc'] === true) {
         return $this->getFiles();
     } else {
         return $this->createZipFile();
     }
 }
Exemplo n.º 2
0
 /**
  * @param Prefs $prefs
  */
 public function savePrefs(Prefs $prefs)
 {
     UtilityService::createFile($this->getPrefsFileName(), $this->userGroup);
     $handle = fopen($this->getPrefsFileName(), 'w');
     fwrite($handle, $prefs->toJson());
     fclose($handle);
 }
Exemplo n.º 3
0
 /**
  * @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();
 }