You are here

function certificate_admin_clear_form in Certificate 4.x

Same name and namespace in other branches
  1. 8.3 certificate.admin.inc \certificate_admin_clear_form()
  2. 6.2 certificate.admin.inc \certificate_admin_clear_form()
  3. 6 certificate.admin.inc \certificate_admin_clear_form()
  4. 7.2 certificate.admin.inc \certificate_admin_clear_form()
  5. 3.x certificate.admin.inc \certificate_admin_clear_form()

Form to clear certificate snapshots.

File

./certificate.admin.inc, line 32
Administrative pages for Certificate module.

Code

function certificate_admin_clear_form($form, &$form_state) {
  $form = array();
  $header = array(
    array(),
    array(
      'data' => 'Title',
      'field' => 'n.title',
    ),
    array(
      'data' => 'Count',
      'field' => 'count',
    ),
  );
  $sql = "SELECT *, count(cs.uid) AS count FROM {certificate_snapshots} cs\n  INNER JOIN {node} n ON (cs.nid = n.nid)\n  GROUP BY cs.nid";

  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
  $result = \Drupal::database()
    ->query($sql);
  $nids = array();
  while ($row = $result
    ->fetch()) {
    $nids[$row->nid] = '';
    $form['cs']['title'][$row->nid]['#markup'] = $row->title;
    $form['cs']['count'][$row->nid]['#markup'] = $row->count;
  }
  $form['cs']['nids'] = array(
    '#type' => 'checkboxes',
    '#options' => $nids,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Clear',
  );
  return $form;
}