You are here

function workspace_list_content in Workspace 6

Same name and namespace in other branches
  1. 7 workspace.module \workspace_list_content()

Menu callback. Display list of content.

Parameters

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

1 string reference to 'workspace_list_content'
workspace_menu in ./workspace.module
Implementation of hook_menu().

File

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

Code

function workspace_list_content($account) {
  global $user;
  drupal_set_title(t('Workspace: @name', array(
    '@name' => $account->name,
  )));
  $max = isset($user->workspaces) ? $user->workspaces['default']['maxnodes'] : 50;
  $comments_enabled = module_exists('comment');
  if ($comments_enabled) {

    // If the comment module is enabled, we need to get comment counts too.
    $sql = 'SELECT n.nid, n.uid, n.type, 0 as cid, n.title, n.status, n.changed, s.comment_count, 1 as node
            FROM {node} n
            LEFT JOIN {node_comment_statistics} s ON n.nid = s.nid
            WHERE n.uid = %d';
    $count_sql = 'SELECT COUNT(n.nid)
            FROM {node} n
            LEFT JOIN {node_comment_statistics} s ON n.nid = s.nid
            WHERE n.uid = %d';
  }
  else {

    // Otherwise we use a simpler query.
    $sql = 'SELECT n.nid, n.uid, n.type, 0 as cid, n.title, n.status, n.changed, 1 as node
            FROM {node} n
            WHERE n.uid = %d';
    $count_sql = 'SELECT COUNT(n.nid)
            FROM {node} n
            WHERE n.uid = %d';
  }
  $header = array(
    array(
      'data' => t('Type'),
      'field' => 'type',
    ),
    array(
      'data' => t('Title'),
      'field' => 'title',
    ),
    array(
      'data' => t('Owner'),
      'field' => 'uid',
    ),
    array(
      'data' => t('Published'),
      'field' => 'status',
    ),
    array(
      'data' => t('Modified'),
      'field' => 'changed',
      'sort' => 'desc',
    ),
    $comments_enabled ? array(
      'data' => t('Replies'),
      'field' => 'comment_count',
    ) : array(
      'data' => '',
    ),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $cols = 8;
  $result = pager_query(db_rewrite_sql($sql . tablesort_sql($header)), $max, 0, db_rewrite_sql($count_sql), $account->uid);
  $rows = workspace_build_rows($result, $account);
  $output = '';

  // Only add the content add form if the user is viewing his/her own workspace.
  if ($user->uid == 1 || user_access('view all workspaces') || $user->uid == $account->uid) {
    $output = drupal_get_form('workspace_add_form');
  }
  $output .= theme_workspace_list($header, $rows, $max, $cols);
  return $output;
}