You are here

function insight_page_alerts in Insight 7

Form builder: Builds the node administration overview.

1 call to insight_page_alerts()
insight_page_alerts_page in ./insight.page_alerts.inc
Menu callback: content administration.

File

./insight.page_alerts.inc, line 18

Code

function insight_page_alerts($include = 'active') {
  $analyzer_defs = insight_analyzer_info(TRUE);
  $content_reports = $analyzer_defs['#meta']['reports_by_type']['content'];
  $report_defs = $analyzer_defs['#meta']['reports'];
  unset($analyzer_defs['#meta']);

  // Build the sortable table header.
  $header = array(
    'level' => array(
      'data' => t('Level'),
      'field' => 'a.status',
    ),
    //'active' => array('data' => t('Active'), 'field' => 'a.active'),
    'message' => array(
      'data' => t('Message'),
      'field' => 'a.message',
    ),
    'report' => array(
      'data' => t('Report'),
      'field' => 'a.report',
    ),
    'node' => array(
      'data' => t('Node'),
      'field' => 'a.nid',
    ),
  );
  $header['operations'] = array(
    'data' => t('Operations'),
  );
  $query = db_select('insight_alert', 'a')
    ->extend('PagerDefault')
    ->extend('TableSort');
  insight_page_report_build_filter_query($query);
  $query
    ->fields('a')
    ->condition('a.report', $content_reports)
    ->limit(50)
    ->orderByHeader($header);
  $n_alias = $query
    ->innerJoin('node', 'n', '%alias.nid = a.nid');
  $query
    ->addField($n_alias, 'title', 'node_title');
  if ($include != 'all') {
    $v = $include == 'active' ? 1 : ($include == 'ignore' ? 0 : -1);
    $query
      ->condition('a.active', $v);
    $r_alias = $query
      ->innerJoin('insight_report', 'r', '%alias.irid = a.irid');
    $query
      ->condition('r.active', $v);
  }
  $alerts = $query
    ->execute()
    ->fetchAll();

  // Prepare the list of nodes.
  $destination = drupal_get_destination();
  $options = array();
  foreach ($alerts as $alert) {
    $node = new stdClass();
    $node->nid = $alert->nid;
    $status = 'message';
    $level_vars = array(
      'path' => 'misc/message-24-message.png',
      'alt' => 'message',
    );
    if ($alert->status == 1) {
      $level_vars['path'] = 'misc/message-24-warning.png';
      $level_vars['alt'] = 'warning';
      $status = 'warning';
    }
    elseif ($alert->status == 0) {
      $level_vars['path'] = 'misc/message-24-error.png';
      $level_vars['alt'] = 'error';
      $status = 'error';
    }
    $options[$alert->iaid]['data'] = array(
      'level' => theme('image', $level_vars),
      //'active' => $alert->active,
      'message' => $alert->message,
      'report' => l($report_defs[$alert->report]['title'], 'admin/reports/insight/report/' . $alert->irid, array(
        'query' => drupal_get_destination(),
      )),
      'node' => l($alert->node_title, 'node/' . $alert->nid, array(
        'query' => drupal_get_destination(),
      )),
    );

    //$options[$alert->iaid]['class'] = array($status);

    // Build a list of all the accessible operations for the current node.
    $operations = array();
    if ($alert->active == 1) {
      $operations['dismiss'] = array(
        'title' => t('dismiss'),
        'href' => 'admin/reports/insight/alert/active/' . $alert->iaid . '/dismiss',
        'query' => $destination,
      );
      $operations['ignore'] = array(
        'title' => t('ignore'),
        'href' => 'admin/reports/insight/alert/active/' . $alert->iaid . '/ignore',
        'query' => $destination,
      );
    }
    elseif ($alert->active == 0) {
      $operations['activate'] = array(
        'title' => t('activate'),
        'href' => 'admin/reports/insight/alert/active/' . $alert->iaid . '/activate',
        'query' => $destination,
      );
    }
    $options[$alert->iaid]['data']['operations'] = array(
      'data' => array(
        '#theme' => 'links',
        '#links' => $operations,
        '#attributes' => array(
          'class' => array(
            'links',
            'inline',
          ),
        ),
      ),
    );
  }

  // Only use a tableselect when the current user is able to perform any
  // operations.
  if (FALSE && $admin_access) {
    $form['alerts'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $options,
      '#empty' => t('No active content alerts.'),
    );
  }
  else {
    $form['alerts'] = array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $options,
      '#empty' => t('No active content alerts.'),
    );
  }
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  return $form;
}