You are here

function commerce_cardonfile_overview in Commerce Card on File 7

Displays the card data overview for the "Stored payment methods" account tab.

1 string reference to 'commerce_cardonfile_overview'
commerce_cardonfile_menu in ./commerce_cardonfile.module
Implements hook_menu().

File

includes/commerce_cardonfile.pages.inc, line 12
User page callbacks and forms for Commerce Card on File.

Code

function commerce_cardonfile_overview($account) {

  // Load the specified account's stored card data.
  $stored_cards = commerce_cardonfile_data_load_multiple($account->uid);
  $header = array(
    t('Payment method'),
    t('Operations'),
  );

  // Build a table rows array of stored card data.
  $rows = array();
  foreach ($stored_cards as $card_id => $card_data) {

    // Build the operation links for the current card.
    $links = menu_contextual_links('commerce-card-data', 'user/' . $account->uid . '/stored-payment-methods', array(
      $card_id,
    ));

    // Add the card's row to the table's rows array.
    $rows[] = array(
      theme('card_data_overview', array(
        'card_data' => $card_data,
      )),
      theme('links', array(
        'links' => $links,
        'attributes' => array(
          'class' => 'commerce-card-data links inline operations',
        ),
      )),
    );
  }

  // Add an empty message in case the tab got rendered without stored cards.
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('You do not have any stored payment methods.'),
        'colspan' => 2,
      ),
    );
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
}