You are here

public function GetServices::snpSelectCreateCsv in Simple Node Importer 8

File

src/Services/GetServices.php, line 57

Class

GetServices

Namespace

Drupal\simple_node_importer\Services

Code

public function snpSelectCreateCsv($entity_type, $content_type) {
  $csv = [];
  $type = 'csv';
  if ($entity_type == 'taxonomy') {
    $csv = [
      'Vocabolary',
      'Term1',
      'Term2',
      'Term3',
      'Term4',
    ];
    $filename = $entity_type . '_template.csv';
  }
  else {
    $labelarray = $this
      ->snpGetFieldList($entity_type, $content_type, $type);
    foreach ($labelarray as $value) {
      $csv[] = $value;
    }
    $filename = $content_type . '_template.csv';
  }
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header('Content-Description: File Transfer');
  header("Content-type: text/csv");
  header("Content-Disposition: attachment; filename={$filename}");
  header("Expires: 0");
  header("Pragma: public");
  $fh = @fopen('php://output', 'w');

  // Put the data into the stream.
  fputcsv($fh, $csv);
  fclose($fh);

  // Make sure nothing else is sent, our file is done.
  exit;
}