You are here

function theme_commerce_registration_line_item_registrations in Commerce Registration 7.2

Theme function for rendering a table of line item registration elements.

1 theme call to theme_commerce_registration_line_item_registrations()
commerce_registration_form_commerce_order_ui_order_form_alter in ./commerce_registration.module
Implements hook_form_FORM_ID_alter().

File

./commerce_registration.module, line 1781
Commerce Registration module code.

Code

function theme_commerce_registration_line_item_registrations($variables) {
  $element = $variables['element'];
  $order = $element['#order'];
  $prodkey = $element['#prodkey'];
  $header = array(
    array(
      'data' => t('Remove'),
    ),
    array(
      'data' => t('id'),
      'field' => 'registration_id',
      'type' => 'property',
      'specifier' => 'registration_id',
    ),
    array(
      'data' => t('Email'),
    ),
    array(
      'data' => t('User'),
      'field' => 'user_uid',
      'type' => 'property',
      'specifier' => 'user_uid',
    ),
    array(
      'data' => t('Created By'),
      'field' => 'author_uid',
      'type' => 'property',
      'specifier' => 'author_uid',
    ),
    array(
      'data' => t('Count'),
      'field' => 'count',
      'type' => 'property',
      'specifier' => 'count',
    ),
    array(
      'data' => t('Created'),
      'field' => 'created',
      'sort' => 'desc',
      'type' => 'property',
      'specifier' => 'created',
    ),
    array(
      'data' => t('State'),
      'field' => 'state',
      'type' => 'property',
      'specifier' => 'state',
    ),
    array(
      'data' => t('Actions'),
    ),
  );
  $rows = array();

  // Add each registration to the line item's registrations table.
  $registration_ids = element_children($element);
  $registrations = entity_load('registration', $registration_ids);
  foreach ($registration_ids as $registration_id) {
    $data = $element[$registration_id];
    if (isset($data['delta']['#value']) && isset($order->data) && isset($order->data['register_entities'][$prodkey][$data['delta']['#value']])) {

      // Load the registration because what is in $order->data could be wildly
      // out of date.
      if (isset($registrations[$registration_id])) {
        $registration = $registrations[$registration_id];
        $wrapper = entity_metadata_wrapper('registration', $registration);
        $author = $wrapper->author
          ->value();
        $user = $wrapper->user
          ->value();
        $state = $wrapper->state
          ->value();
        $author_col = '';
        if ($registration->author_uid) {
          $author_col = theme('username', array(
            'account' => $author,
          ));
        }
        $user_col = '';
        if ($registration->user_uid) {
          $user_col = theme('username', array(
            'account' => $user,
          ));
        }
        $actions = array();
        if (entity_access('view', 'registration', $registration)) {
          $actions[] = l(t('View'), 'registration/' . $registration->registration_id);
        }
        if (entity_access('update', 'registration', $registration)) {
          $actions[] = l(t('Edit'), 'registration/' . $registration->registration_id . '/edit', array(
            'query' => drupal_get_destination(),
          ));
        }
        $context = array(
          'registration' => clone $registration,
          'order' => clone $order,
          'prodkey' => $prodkey,
        );

        // Allow other modules to add/remove actions for each registration.
        drupal_alter('commerce_registration_order_ops', $actions, $context);
        if ($wrapper->anon_mail
          ->value()) {
          $mail = $wrapper->anon_mail
            ->value();
        }
        else {
          $mail = $wrapper->mail
            ->value();
        }
        $rows[] = array(
          drupal_render($data['registration_remove']),
          l($registration->registration_id, 'registration/' . $registration->registration_id),
          l($mail, 'mailto:' . $mail),
          $user_col,
          $author_col,
          $registration->count,
          format_date($registration->created),
          $state ? filter_xss_admin(entity_label('registration_state', $state)) : '',
          implode(' | ', $actions),
        );
      }
    }
  }
  $line_item = $element['#line_item'];

  // Setup the table's variables array and build the output.
  $table_variables = array(
    'caption' => $element['#title'],
    'header' => $header,
    'rows' => $rows,
    'empty' => $element['#empty'],
    'attributes' => array(
      'id' => 'line-item-reg-' . $line_item->line_item_id,
      'tabindex' => 0,
    ),
  );
  $output = theme('table', $table_variables);
  return $output;
}