class AbjsDefaultController in A/B Test JS 8
Same name and namespace in other branches
- 2.0.x src/Controller/AbjsDefaultController.php \Drupal\abjs\Controller\AbjsDefaultController
Default controller for the abjs module.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\abjs\Controller\AbjsDefaultController
Expanded class hierarchy of AbjsDefaultController
File
- src/
Controller/ AbjsDefaultController.php, line 15
Namespace
Drupal\abjs\ControllerView source
class AbjsDefaultController extends ControllerBase {
/**
* Turns a render array into a HTML string.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $userStorage;
/**
* Provides a service to handle various date related functionality.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* Turns a render array into a HTML string.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The database connection.
*
* @var Drupal\Core\Database\Connection
*/
protected $database;
/**
* Constructs a new FeedTypeForm object.
*
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The services of date.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The render object.
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public function __construct(DateFormatterInterface $date_formatter, RendererInterface $renderer, Connection $database) {
$this->dateFormatter = $date_formatter;
$this->renderer = $renderer;
$this->database = $database;
$this->userStorage = $this
->entityTypeManager()
->getStorage('user');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('date.formatter'), $container
->get('renderer'), $container
->get('database'));
}
/**
* Lists all tests in a default table theme.
*
* Sorted by active tests first, then modified most recently, then
* created most recently. For each test, link to test, and list active
* status, conditions applied (with links), experiences with fractions
* assigned (with links), and created and edited info.
*/
public function abjsTestAdmin() {
//$db = Database::getConnection();
$date_Formatter = $this->dateFormatter;
$output = [];
$header = [
$this
->t('ID'),
$this
->t('Name'),
$this
->t('Status'),
$this
->t('Conditions'),
$this
->t('Experiences'),
$this
->t('Created'),
$this
->t('Created By'),
$this
->t('Changed'),
$this
->t('Changed By'),
];
$rows = [];
$active_array = [
$this
->t('Inactive'),
$this
->t('Active'),
];
$tests = $this->database
->query("SELECT * FROM {abjs_test} ORDER BY active DESC, changed DESC, created DESC")
->fetchAll();
foreach ($tests as $test) {
$test_link = [
'#title' => $test->name,
'#type' => 'link',
'#url' => Url::fromRoute('abjs.test_edit_form', [
'tid' => $test->tid,
]),
];
$condition_list = [];
$condition_output = '';
$conditions = $this->database
->query("SELECT tc.cid, c.name FROM {abjs_test_condition} AS tc INNER JOIN {abjs_condition} AS c ON tc.cid = c.cid WHERE tc.tid = :tid", [
':tid' => $test->tid,
])
->fetchAll();
if (!empty($conditions)) {
foreach ($conditions as $condition) {
$condition_link = [
'#title' => $condition->name . ' (c_' . $condition->cid . ')',
'#type' => 'link',
'#url' => Url::fromRoute('abjs.condition_edit_form', [
'cid' => $condition->cid,
]),
];
$condition_list[] = $this->renderer
->render($condition_link);
}
$condition_output = [
'#theme' => 'item_list',
'#items' => $condition_list,
];
}
$experience_list = [];
$experience_output = '';
$experiences = $this->database
->query("SELECT te.eid, te.fraction, e.name FROM {abjs_test_experience} AS te INNER JOIN {abjs_experience} AS e ON te.eid = e.eid WHERE te.tid = :tid", [
':tid' => $test->tid,
])
->fetchAll();
if (!empty($experiences)) {
foreach ($experiences as $experience) {
$experience_link = [
'#title' => '[' . $experience->fraction . '] ' . $experience->name . ' (e_' . $experience->eid . ')',
'#type' => 'link',
'#url' => Url::fromRoute('abjs.experience_edit_form', [
'eid' => $experience->eid,
]),
];
$experience_list[] = $this->renderer
->render($experience_link);
}
$experience_output = [
'#theme' => 'item_list',
'#items' => $experience_list,
];
}
$user_created = $this->userStorage
->load($test->created_by);
$user_changed = $this->userStorage
->load($test->changed_by);
$rows[] = [
't_' . $test->tid,
$this->renderer
->render($test_link),
$active_array[$test->active],
$this->renderer
->render($condition_output),
$this->renderer
->render($experience_output),
$date_Formatter
->format($test->created),
$user_created
->toLink(),
$date_Formatter
->format($test->changed),
$user_changed
->toLink(),
];
}
$output['add'] = [
'#title' => $this
->t('Add new test'),
'#type' => 'link',
'#url' => Url::fromRoute('abjs.test_add_form'),
'#attributes' => [
'class' => 'button button-action button--primary button--small',
],
'#suffix' => '<br><br>',
];
$output['table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
return $output;
}
/**
* Lists all conditions in default table, sorted by modified date.
*
* For each condition, link to edit form, and list created and edited info.
*/
public function abjsConditionAdmin() {
//$db = Database::getConnection();
$date_Formatter = $this->dateFormatter;
$output = [];
$header = [
$this
->t('ID'),
$this
->t('Name'),
$this
->t('Created'),
$this
->t('Created By'),
$this
->t('Changed'),
$this
->t('Changed By'),
];
$rows = [];
$conditions = $this->database
->query("SELECT * FROM {abjs_condition} ORDER BY changed DESC, created DESC")
->fetchAll();
foreach ($conditions as $condition) {
$condition_link = [
'#title' => $condition->name,
'#type' => 'link',
'#url' => Url::fromRoute('abjs.condition_edit_form', [
'cid' => $condition->cid,
]),
];
$user_created = $this->userStorage
->load($condition->created_by);
$user_changed = $this->userStorage
->load($condition->changed_by);
$rows[] = [
'c_' . $condition->cid,
$this->renderer
->render($condition_link),
$date_Formatter
->format($condition->created),
$user_created
->toLink(),
$date_Formatter
->format($condition->changed),
$user_changed
->toLink(),
];
}
$output['add'] = [
'#title' => $this
->t('Add new condition'),
'#type' => 'link',
'#url' => Url::fromRoute('abjs.condition_add_form'),
'#attributes' => [
'class' => 'button button-action button--primary button--small',
],
'#suffix' => '<br><br>',
];
$output['table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
return $output;
}
/**
* Lists all experiences in default table, sorted by modified date.
*
* For each experience, link to edit form, and list created and edited info.
*/
public function abjsExperienceAdmin() {
//$db = Database::getConnection();
$date_Formatter = $this->dateFormatter;
$output = [];
$header = [
$this
->t('ID'),
$this
->t('Name'),
$this
->t('Created'),
$this
->t('Created By'),
$this
->t('Changed'),
$this
->t('Changed By'),
];
$rows = [];
$experiences = $this->database
->query("SELECT * FROM {abjs_experience} ORDER BY changed DESC, created DESC")
->fetchAll();
foreach ($experiences as $experience) {
$experience_link = [
'#title' => $experience->name,
'#type' => 'link',
'#url' => Url::fromRoute('abjs.experience_edit_form', [
'eid' => $experience->eid,
]),
];
$user_created = $this->userStorage
->load($experience->created_by);
$user_changed = $this->userStorage
->load($experience->changed_by);
$rows[] = [
'e_' . $experience->eid,
$this->renderer
->render($experience_link),
$date_Formatter
->format($experience->created),
$user_created
->toLink(),
$date_Formatter
->format($experience->changed),
$user_changed
->toLink(),
];
}
$output['add'] = [
'#title' => $this
->t('Add new experience'),
'#type' => 'link',
'#url' => Url::fromRoute('abjs.experience_add_form'),
'#attributes' => [
'class' => 'button button-action button--primary button--small',
],
'#suffix' => '<br><br>',
];
$output['table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
return $output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbjsDefaultController:: |
protected | property | The database connection. | |
AbjsDefaultController:: |
protected | property | Provides a service to handle various date related functionality. | |
AbjsDefaultController:: |
protected | property | Turns a render array into a HTML string. | |
AbjsDefaultController:: |
protected | property | Turns a render array into a HTML string. | |
AbjsDefaultController:: |
public | function | Lists all conditions in default table, sorted by modified date. | |
AbjsDefaultController:: |
public | function | Lists all experiences in default table, sorted by modified date. | |
AbjsDefaultController:: |
public | function | Lists all tests in a default table theme. | |
AbjsDefaultController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
AbjsDefaultController:: |
public | function | Constructs a new FeedTypeForm object. | |
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:: |
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. |