You are here

public function apply_for_role_application_admin_page::content in Apply for role 8

Content, renders table of applications, paged.

1 string reference to 'apply_for_role_application_admin_page::content'
apply_for_role.routing.yml in ./apply_for_role.routing.yml
apply_for_role.routing.yml

File

src/Controller/apply_for_role_application_admin_page.php, line 35

Class

apply_for_role_application_admin_page

Namespace

Drupal\apply_for_role\Controller

Code

public function content() {
  $table_header = array(
    $this
      ->t('Application id'),
    $this
      ->t('User Name (UID)'),
    $this
      ->t('Roles'),
    $this
      ->t('Status'),
    $this
      ->t('Created'),
    $this
      ->t('Message'),
    $this
      ->t('Operations'),
  );
  $pager_number = \Drupal::request()->query
    ->getInt('page');
  $total_application_count = Database::getConnection()
    ->select('apply_for_role_applications', 'a')
    ->countQuery()
    ->execute()
    ->fetchField();
  $results = Database::getConnection()
    ->select('apply_for_role_applications', 'a')
    ->fields('a')
    ->orderBy('aid', 'DESC')
    ->range($pager_number * 20, 20)
    ->execute();
  $page = pager_default_initialize($total_application_count, $this->applications_per_page);
  $table_render = array(
    'table' => array(
      '#type' => 'table',
      '#header' => $table_header,
      '#empty' => $this
        ->t('Currently there are no applications available for review.'),
    ),
    'page' => array(
      '#type' => 'pager',
    ),
  );
  while ($result_row = $results
    ->fetchAssoc()) {
    $table_render['table'][$result_row['aid']] = array(
      'aid' => array(
        '#plain_text' => $result_row['aid'],
      ),
      'uid' => array(
        '#plain_text' => $this
          ->display_username($result_row['uid']),
      ),
      'rids' => array(
        '#plain_text' => $this->application_manager
          ->rids_to_text(Serialization\Json::decode($result_row['rids'])),
      ),
      'status' => array(
        '#plain_text' => $this
          ->display_status($result_row['status']),
      ),
      'created' => array(
        '#plain_text' => $result_row['created'],
      ),
      'message' => array(
        '#plain_text' => $result_row['message'],
      ),
      'operations' => array(
        '#markup' => $this
          ->generate_operations_links($result_row['aid'], $result_row['status']),
      ),
    );
  }
  return $table_render;
}