You are here

function uc_reports_store_csv in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_reports/uc_reports.module \uc_reports_store_csv()
  2. 7.3 uc_reports/uc_reports.admin.inc \uc_reports_store_csv()

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

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

Parameters

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

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

7 calls to uc_reports_store_csv()
uc_reports_customers in uc_reports/uc_reports.module
Display the customer report
uc_reports_products in uc_reports/uc_reports.module
Display the product reports
uc_reports_products_custom in uc_reports/uc_reports.module
Display the product reports
uc_reports_sales_custom in uc_reports/uc_reports.module
uc_reports_sales_year in uc_reports/uc_reports.module

... See full list

File

uc_reports/uc_reports.module, line 1247
Displays reports on sales, customers, and products to store admin

Code

function uc_reports_store_csv($report_id, $rows) {
  global $user;
  $user_id = empty($user->uid) ? session_id() : $user->uid;
  foreach ($rows as $row) {
    foreach ($row as $index => $column) {
      $row[$index] = '"' . str_replace('"', '""', $column) . '"';
    }
    $csv_output .= implode(',', $row) . "\n";
  }
  cache_set('uc_reports_' . $report_id . '_' . $user_id, 'cache', $csv_output, time() + 86400);
  return array(
    'user' => $user_id,
    'report' => $report_id,
    'csv' => $csv_output,
  );
}