You are here

function registration_registrations_page in Entity Registration 8

Same name and namespace in other branches
  1. 8.2 registration.module \registration_registrations_page()
  2. 7.2 registration.module \registration_registrations_page()
  3. 7 registration.module \registration_registrations_page()

Page callback: Show a list of registrations for a host entity.

Parameters

string $entity_type: The host entity type.

object $entity: The host entity.

Return value

array A render array

See also

registration_administer_registrations_access()

registration_menu()

1 string reference to 'registration_registrations_page'
registration_menu in ./registration.module
@FIXME This implementation of hook_menu() cannot be automatically converted because it contains logic (i.e., branching statements, function calls, object instantiation, etc.) You will need to convert it manually. Sorry!

File

./registration.module, line 576

Code

function registration_registrations_page($entity_type, $entity) {
  $header = array(
    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'),
    ),
  );
  list($entity_id) = entity_extract_ids($entity_type, $entity);
  $label = $entity
    ->label();
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'registration')
    ->propertyCondition('entity_id', $entity_id)
    ->propertyCondition('entity_type', $entity_type)
    ->pager(20)
    ->tableSort($header)
    ->execute();
  if (!empty($result['registration'])) {
    $registrations = registration_load_multiple(array_keys($result['registration']));
    $rows = array();
    foreach ($registrations as $registration) {
      $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)) {

        // @FIXME
        // l() expects a Url object, created from a route name or external URI.
        // $actions[] = l(t('View'), 'registration/' . $registration->registration_id);
      }
      if (entity_access('update', 'registration', $registration)) {

        // @FIXME
        // l() expects a Url object, created from a route name or external URI.
        // $actions[] = l(t('Edit'), 'registration/' . $registration->registration_id . '/edit', array('query' => drupal_get_destination()));
      }
      if (entity_access('delete', 'registration', $registration)) {

        // @FIXME
        // l() expects a Url object, created from a route name or external URI.
        // $actions[] = l(t('Delete'), 'registration/' . $registration->registration_id . '/delete', array('query' => drupal_get_destination()));
      }

      // @FIXME
      // l() expects a Url object, created from a route name or external URI.
      // $rows[] = array(
      //         l($registration->registration_id, 'registration/' . $registration->registration_id),
      //         l($wrapper->mail->value(), 'mailto:' . $wrapper->mail->value()),
      //         $user_col,
      //         $author_col,
      //         $registration->count,
      //         format_date($registration->created),
      //         ($state ? filter_xss_admin($state->label()) : ''),
      //         implode(' | ', $actions)
      //       );
    }
    $settings = registration_entity_settings($entity_type, $entity_id);
    $table = array(
      'header' => $header,
      'rows' => $rows,
    );
    if ($settings['capacity'] != 0) {
      $table['caption'] = t('List of registrations for %title. !count of !capacity spaces are filled.', array(
        '%title' => $label,
        '!count' => '<strong>' . registration_event_count($entity_type, $entity_id) . '</strong>',
        '!capacity' => '<strong>' . $settings['capacity'] . '</strong>',
      ));
    }
    else {
      $table['caption'] = t('List of registrations for %title. !count spaces are filled.', array(
        '%title' => $label,
        '!count' => '<strong>' . registration_event_count($entity_type, $entity_id) . '</strong>',
      ));
    }
    $out = _theme('table', $table) . _theme('pager');
  }
  else {
    $out = t('There are no registrants for %name', array(
      '%name' => $label,
    ));
  }
  return $out;
}