You are here

public function ShrinkTheWebLogForm::buildForm in ShrinkTheWeb 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/ShrinkTheWebLogForm.php, line 20

Class

ShrinkTheWebLogForm

Namespace

Drupal\shrinktheweb\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = array();
  $log_records = array();

  // format the tableselect header
  $header = array(
    'domain' => array(
      'data' => t('Domain'),
      'field' => 'sl.stw_domain',
    ),
    'hash' => array(
      'data' => t('Hash'),
      'field' => 'sl.stw_hash',
    ),
    'timestamp' => array(
      'data' => t('Timestamp'),
      'field' => 'sl.stw_timestamp',
    ),
    'capturedon' => array(
      'data' => t('Captured on'),
      'field' => 'sl.stw_capturedon',
    ),
    'quality' => array(
      'data' => t('Quality'),
      'field' => 'sl.stw_quality',
    ),
    'full' => array(
      'data' => t('Full'),
      'field' => 'sl.stw_full',
    ),
    'xmax' => array(
      'data' => t('Xmax'),
      'field' => 'sl.stw_xmax',
    ),
    'ymax' => array(
      'data' => t('Ymax'),
      'field' => 'sl.stw_ymax',
    ),
    'nrx' => array(
      'data' => t('nrX'),
      'field' => 'sl.stw_nrx',
    ),
    'nry' => array(
      'data' => t('nrY'),
      'field' => 'sl.stw_nry',
    ),
    'invalid' => array(
      'data' => t('Invalid'),
      'field' => 'sl.stw_invalid',
    ),
    'stwerrcode' => array(
      'data' => t('STW error code'),
      'field' => 'sl.stw_stwerrcode',
    ),
    'error' => array(
      'data' => t('Error'),
      'field' => 'sl.stw_error',
    ),
    'errcode' => array(
      'data' => t('Error code'),
      'field' => 'sl.stw_errcode',
    ),
  );

  // get the log records
  $result = \Drupal::database()
    ->select('shrinktheweb_log', 'sl')
    ->fields('sl')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->limit(25)
    ->addTag('shrinktheweb_log_records')
    ->execute();
  foreach ($result as $record) {
    $log_records[$record->stw_siteid] = array(
      'domain' => $record->stw_domain,
      'hash' => $record->stw_hash,
      'timestamp' => date("M d, Y, H:i:s", $record->stw_timestamp),
      'capturedon' => date("M d, Y, H:i:s", $record->stw_capturedon),
      'quality' => $record->stw_quality,
      'full' => $record->stw_full,
      'xmax' => $record->stw_xmax != 0 ? $record->stw_xmax : 'Not set',
      'ymax' => $record->stw_ymax != 0 ? $record->stw_ymax : 'Not set',
      'nrx' => $record->stw_nrx,
      'nry' => $record->stw_nry,
      'invalid' => $record->stw_invalid,
      'stwerrcode' => $record->stw_stwerrcode,
      'error' => $record->stw_error,
      'errcode' => $record->stw_errcode,
    );
  }
  $form['log_records'] = array(
    '#type' => 'tableselect',
    '#empty' => t('The log is empty.'),
    '#header' => $header,
    '#options' => $log_records,
  );
  $form['pager'] = array(
    '#type' => 'pager',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete selected records'),
    '#button_type' => 'primary',
  );
  return $form;
}