You are here

function theme_users_export_flatfile in Users Export 7

Formats export table data as a text delimited representation of table

Parameters

$header: An array containing the table headers. Each element of the array can be either a localized string or an associative array with the following keys:

  • "data": The localized title of the table column.
  • "field": The database field represented in the table column (required if user is to be able to sort on this column).
  • "sort": A default sort order for this column ("asc" or "desc").
  • Any HTML attributes, such as "colspan", to apply to the column header cell.

$rows: An array of table rows. Every row is an array of cells, or an associative array with the following keys:

  • "data": an array of cells
  • Any HTML attributes, such as "class", to apply to the table row.

Each cell can be either a string or an associative array with the following keys:

  • "data": The string to display in the table cell.
  • "header": Indicates this cell is a header.
  • Any HTML attributes, such as "colspan", to apply to the table cell.

Here's an example for $rows: @verbatim $rows = array( // Simple row array( 'Cell 1', 'Cell 2', 'Cell 3' ), // Row with attributes on the row and some of its cells. array( 'data' => array('Cell 1', array('data' => 'Cell 2', 'colspan' => 2)), 'class' => 'funky' ) ); @endverbatim

string $type: Expecting 'csv', 'txt', 'xls'

bool $html: Set to FALSE to apply strip_tags() on all cells

string $prefix: A string to preceed the table data

string $suffix: A string to follow the table data

Return value

string

Related topics

1 theme call to theme_users_export_flatfile()
users_export_form_submit in ./users_export.admin.inc
Form submission handler

File

./users_export.admin.inc, line 206
Administration page callbacks for the users_export module.

Code

function theme_users_export_flatfile($vars) {
  $output = '';
  $formatting = new stdClass();
  $format->eol = "\n";
  $format->html = $vars['html'];
  switch ($vars['type']) {
    case 'csv':
      $format->left = '"';
      $format->right = '"';
      $format->sep = ',';
      $format->escape = '\\';
      break;
    case 'txt':
      $format->left = '';
      $format->right = '';
      $format->sep = "\t";
      $format->escape = '\\';
      break;
    case 'xls':
      $format->left = '"';
      $format->right = '"';
      $format->sep = "\t";
      $format->escape = '\\';
      break;
  }
  if (!empty($vars['prefix'])) {
    $output .= $vars['prefix'] . $format->eol;
  }

  // Format the header row:
  if (count($vars['header'])) {
    $output .= _users_export_collapse_row($vars['header'], $format);
  }

  // Format the rows:
  if (count($vars['rows'])) {
    foreach ($vars['rows'] as $row) {
      $output .= _users_export_collapse_row($row, $format);
    }
  }
  if (!empty($vars['suffix'])) {
    $output .= $vars['suffix'] . $format->eol;
  }
  return $output;
}