class apply_for_role_application_admin_page in Apply for role 8
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\apply_for_role\Controller\apply_for_role_application_admin_page
Expanded class hierarchy of apply_for_role_application_admin_page
File
- src/
Controller/ apply_for_role_application_admin_page.php, line 18
Namespace
Drupal\apply_for_role\ControllerView source
class apply_for_role_application_admin_page extends ControllerBase {
private $application_manager;
private $applications_per_page;
/**
* Constructor, loads application manager and amount of applications per page is set here.
*/
public function __construct() {
$this->application_manager = new application_manager();
$this->applications_per_page = 20;
}
/**
* Content, renders table of applications, paged.
*/
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;
}
/**
* Display a presentable username.
*/
protected function display_username($uid) {
$account = \Drupal\user\Entity\User::load($uid);
return $account
->getDisplayName() . ' (' . $uid . ')';
}
/**
* Helper function to display a clean text representation of a status.
*/
protected function display_status($status) {
switch ($status) {
case 0:
return 'Needs Review';
break;
case 1:
return 'Accepted';
break;
case 2:
return 'Denied';
break;
default:
// @TODO: Add error handling here if desired.
return FALSE;
}
}
/**
* Helper function that returns operations links based on AID and status.
*/
protected function generate_operations_links($aid, $status) {
if ($status == 0) {
$approval_url = Url::fromRoute('apply_for_role.application_approve', array(
'action' => 'approve',
'aid' => intval($aid),
));
$denial_url = Url::fromRoute('apply_for_role.application_deny', array(
'action' => 'deny',
'aid' => intval($aid),
));
$approval_link = Link::fromTextAndUrl($this
->t('Approve Application'), $approval_url);
$denial_link = Link::fromTextAndUrl($this
->t('Deny Application'), $denial_url);
$approval_link_rendered = $approval_link
->toRenderable();
$denial_link_rendered = $denial_link
->toRenderable();
return render($approval_link_rendered) . ' | ' . render($denial_link_rendered);
}
else {
return '';
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
apply_for_role_application_admin_page:: |
private | property | ||
apply_for_role_application_admin_page:: |
private | property | ||
apply_for_role_application_admin_page:: |
public | function | Content, renders table of applications, paged. | |
apply_for_role_application_admin_page:: |
protected | function | Helper function to display a clean text representation of a status. | |
apply_for_role_application_admin_page:: |
protected | function | Display a presentable username. | |
apply_for_role_application_admin_page:: |
protected | function | Helper function that returns operations links based on AID and status. | |
apply_for_role_application_admin_page:: |
public | function | Constructor, loads application manager and amount of applications per page is set here. | |
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
40 |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |