You are here

protected function GdprTasksSarWorker::writeCsv in General Data Protection Regulation 3.0.x

Same name and namespace in other branches
  1. 8.2 modules/gdpr_tasks/src/Plugin/QueueWorker/GdprTasksSarWorker.php \Drupal\gdpr_tasks\Plugin\QueueWorker\GdprTasksSarWorker::writeCsv()
  2. 8 modules/gdpr_tasks/src/Plugin/QueueWorker/GdprTasksSarWorker.php \Drupal\gdpr_tasks\Plugin\QueueWorker\GdprTasksSarWorker::writeCsv()

Write data to a CSV file.

@todo Use something like this instead: \Consolidation\OutputFormatters\Formatters\CsvFormatter

Parameters

string $filename: The filename to write to (supports streams).

array $content: The data to write, an array containing each row as an array.

1 call to GdprTasksSarWorker::writeCsv()
GdprTasksSarWorker::build in modules/gdpr_tasks/src/Plugin/QueueWorker/GdprTasksSarWorker.php
Build the export files.

File

modules/gdpr_tasks/src/Plugin/QueueWorker/GdprTasksSarWorker.php, line 458

Class

GdprTasksSarWorker
Processes SARs tasks when data processing is required.

Namespace

Drupal\gdpr_tasks\Plugin\QueueWorker

Code

protected function writeCsv($filename, array $content) {
  $handler = fopen($filename, 'wb');

  // Write the UTF-8 BOM header so excel handles the encoding.
  fprintf($handler, chr(0xef) . chr(0xbb) . chr(0xbf));
  foreach ($content as $row) {
    fputcsv($handler, $row);
  }
  fclose($handler);
}