You are here

function heartbeat_comments_admin_overview in Heartbeat 7

Same name and namespace in other branches
  1. 6.4 modules/heartbeat_comments/heartbeat_comments.admin.inc \heartbeat_comments_admin_overview()

Form builder; Builds the comment overview form for the admin.

Return value

The form structure.

See also

heartbeat_comments_admin_overview_validate()

heartbeat_comments_admin_overview_submit()

theme_heartbeat_comments_admin_overview()

1 string reference to 'heartbeat_comments_admin_overview'
heartbeat_comments_admin in modules/heartbeat_comments/heartbeat_comments.admin.inc
Menu callback; present an administrative comment listing.

File

modules/heartbeat_comments/heartbeat_comments.admin.inc, line 32
Admin page callbacks for the heartbeat comments module.

Code

function heartbeat_comments_admin_overview() {
  $form['options']['operation'] = array(
    '#type' => 'hidden',
    '#default_value' => 'delete',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete selected'),
  );

  // Build the sortable table header.
  $header = array(
    'comment' => array(
      'data' => t('Comment'),
      'field' => 'subject',
    ),
    'author' => t('Author'),
    'time' => array(
      'data' => t('Time'),
      'field' => 'c.time',
      'sort' => 'desc',
    ),
    'reacted_on' => array(
      'data' => t('Reacted on'),
      'field' => 'heartbeat_title',
    ),
  );
  $query = db_select('heartbeat_comments', 'c')
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->fields('c', array(
    'hcid',
    'uid',
    'uaid',
    'message',
    'cleared',
    'time',
  ));
  $query
    ->join('users', 'u', 'u.uid = c.uid');
  $query
    ->fields('u', array(
    'name',
  ));
  $query
    ->limit(50);
  $query
    ->orderByHeader($header);
  $heartbeat_comments = $query
    ->execute();

  // build a table listing the appropriate comments
  $destination = drupal_get_destination();
  foreach ($heartbeat_comments as $heartbeat_comment) {
    $options[$heartbeat_comment->hcid] = array(
      'comment' => truncate_utf8(strip_tags($heartbeat_comment->message), 70),
      'author' => $heartbeat_comment->uid ? $heartbeat_comment->name : variable_get('anonymous', 'Anonymous user'),
      'time' => format_date($heartbeat_comment->time, 'short'),
      'reacted_on' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => 'activity',
          '#href' => 'heartbeat/message/' . $heartbeat_comment->uaid,
        ),
      ),
    );
  }
  $form['heartbeat_comments'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => isset($options) ? $options : array(),
    '#empty' => t('No content available.'),
  );
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  return $form;
}