You are here

function regcode_admin_list_preparerow in Registration codes 6

Format the raw records coming from the database into something more readable

Parameters

array $row The associative array of a current row:

Return value

array The human readable array

1 call to regcode_admin_list_preparerow()
regcode_admin_list_getmarkup in ./regcode.admin.php
Return the marked up list for display

File

./regcode.admin.php, line 674
Functions and pages needed for the administration interface for the regcode module.

Code

function regcode_admin_list_preparerow($row) {
  $row = array_map('check_plain', $row);

  // Date fields are integers. Safe to check_plain().
  $datefields = array(
    'created',
    'lastused',
    'begins',
    'expires',
  );

  // Format the dates
  foreach ($datefields as $date) {
    if (empty($row[$date])) {
      $row[$date] = '-';
    }
    else {
      $row[$date] = sprintf('<span title="%s">%s</span>', format_date(strtotime($row[$date])), format_date(strtotime($row[$date]), 'custom', 'Y/n/j'));
    }
  }

  // Format the booleans
  $row['is_active'] = $row['is_active'] ? 'Yes' : 'No';

  // Format the UID
  if (!empty($row['uid'])) {
    $row['uid'] = l($row['uid'], 'user/' . $row['uid']);
  }
  else {
    $row['uid'] = '-';
  }

  // Format the maxuses
  if ($row['maxuses'] === '0') {
    $row['maxuses'] = '-';
  }

  // Add actions
  $row['actions'] = l(t('Delete'), 'admin/user/regcodes/delete/' . $row['rid'], array(
    'query' => array(
      'token' => drupal_get_token($row['rid']),
    ),
  ));

  // Allow other modules to play with the row
  foreach (module_implements('regcode_preparerow') as $module) {
    $hook = $module . '_regcode_preparerow';
    $hook($row);
  }
  return $row;
}