You are here

public function Reports::store_csv in Ubercart 8.4

Stores a CSV file for a report in Drupal's cache to be retrieved later.

Parameters

$report_id: A unique string that identifies the report of the CSV file.

$rows: The rows (table header included) that make CSV file.

Return value

An array containing the values need to build URL that return the CSV file of the report and the CSV data itself.

5 calls to Reports::store_csv()
Reports::customers in uc_report/src/Controller/Reports.php
Displays the customer report.
Reports::customProducts in uc_report/src/Controller/Reports.php
Displays the custom product report.
Reports::customSales in uc_report/src/Controller/Reports.php
Displays the custom sales report form and table.
Reports::products in uc_report/src/Controller/Reports.php
Displays the product reports.
Reports::yearSales in uc_report/src/Controller/Reports.php
Displays the yearly sales report form and table.

File

uc_report/src/Controller/Reports.php, line 937

Class

Reports
Provides reports for Ubercart.

Namespace

Drupal\uc_report\Controller

Code

public function store_csv($report_id, $rows) {
  $account = $this
    ->currentUser();
  $csv_output = '';
  $user_id = $account
    ->isAnonymous() ? session_id() : $account
    ->id();
  foreach ($rows as $row) {
    foreach ($row as $index => $column) {
      $row[$index] = '"' . str_replace('"', '""', $column) . '"';
    }
    $csv_output .= implode(',', $row) . "\n";
  }
  \Drupal::cache()
    ->set('uc_report_' . $report_id . '_' . $user_id, $csv_output, \Drupal::time()
    ->getRequestTime() + 86400);
  return [
    'user' => $user_id,
    'report' => $report_id,
    'csv' => $csv_output,
  ];
}