You are here

function uc_reports_store_csv in Ubercart 6.2

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

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

7 calls to uc_reports_store_csv()
uc_reports_customers in uc_reports/uc_reports.admin.inc
Display the customer report
uc_reports_products in uc_reports/uc_reports.admin.inc
Display the product reports
uc_reports_products_custom in uc_reports/uc_reports.admin.inc
Display the custom product report.
uc_reports_sales_custom in uc_reports/uc_reports.admin.inc
Display the custom sales report form and table.
uc_reports_sales_year in uc_reports/uc_reports.admin.inc
Display the yearly sales report form and table.

... See full list

File

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

Code

function uc_reports_store_csv($report_id, $rows) {
  global $user;
  $csv_output = '';
  $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, $csv_output, 'cache', time() + 86400);
  return array(
    'user' => $user_id,
    'report' => $report_id,
    'csv' => $csv_output,
  );
}