You are here

public function AbjsDefaultController::abjsConditionAdmin in A/B Test JS 2.0.x

Same name and namespace in other branches
  1. 8 src/Controller/AbjsDefaultController.php \Drupal\abjs\Controller\AbjsDefaultController::abjsConditionAdmin()

Lists all conditions in default table, sorted by modified date.

For each condition, link to edit form, and list created and edited info.

1 string reference to 'AbjsDefaultController::abjsConditionAdmin'
abjs.routing.yml in ./abjs.routing.yml
abjs.routing.yml

File

src/Controller/AbjsDefaultController.php, line 180

Class

AbjsDefaultController
Default controller for the abjs module.

Namespace

Drupal\abjs\Controller

Code

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;
}