You are here

function workspace_list_comments in Workspace 7

Same name and namespace in other branches
  1. 6 workspace.module \workspace_list_comments()

Menu callback. Display list of comments.

Parameters

$account: User object representing user whose workspace is being listed.

1 string reference to 'workspace_list_comments'
workspace_menu in ./workspace.module
Implements hook_menu().

File

./workspace.module, line 385
Presents a user-centric view of content.

Code

function workspace_list_comments($account) {
  drupal_set_title(t('Workspace: @name', array(
    '@name' => $account->name,
  )));
  $defaults = workspace_user_config_get_defaults();
  $workspace = variable_get('workspace_user_config_' . $account->uid, $defaults);
  $max = $workspace['maxcomments'];
  $rows = array();

  #  $sql =       'SELECT c.nid, c.uid, c.cid, c.subject, c.status, c.timestamp, c.pid, 0 FROM {comments} c WHERE c.uid = %d';

  #  $count_sql = 'SELECT COUNT(cid) FROM {comments} WHERE uid = %d';

  #  // check wether this user has any comments, if not skip pager to avoid div by zero error

  #  $result = db_query('SELECT COUNT(cid) AS ct FROM {comments} WHERE uid = %d', array($account->uid));

  #  $row = db_fetch_array($result);

  #  $has_comments = $row['ct'];

  // Build the comment listing.
  $header = array(
    array(
      'data' => t('Title'),
      'field' => 'title',
    ),
    array(
      'data' => t('Published'),
      'field' => 'status',
    ),
    array(
      'data' => t('Modified'),
      'field' => 'changed',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Replies'),
      'field' => 'comment_count',
    ),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $countquery = db_select('comment', 'c');
  $countquery
    ->addExpression('COUNT(c.cid)', 'ct');
  $countquery
    ->condition('c.uid', $account->uid);
  $query = db_select('comment', 'c')
    ->extend('PagerDefault')
    ->limit($max)
    ->extend('TableSort')
    ->orderByHeader($header);
  $query
    ->setCountQuery($countquery);
  $query
    ->fields('c', array(
    'nid',
    'uid',
    'cid',
    'subject',
    'status',
    'changed',
    'pid',
  ));
  $query
    ->condition('c.uid', $account->uid);
  $records = $query
    ->execute();
  $rows = workspace_build_rows($records, $account);
  return theme('workspace_list', array(
    'header' => $header,
    'rows' => $rows,
  ));
}