function workspace_list_content in Workspace 7
Same name and namespace in other branches
- 6 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 - Implements hook_menu().
File
- ./
workspace.module, line 286 - Presents a user-centric view of content.
Code
function workspace_list_content($account, $filter = '') {
global $user;
$js_settings = array(
'host' => $_SERVER['HTTP_HOST'],
'modulepath' => drupal_get_path('module', 'workspace'),
'active' => t('Yes'),
'inactive' => t('No'),
'use_icons' => variable_get('workspace_use_icons', 1),
);
drupal_add_js(array(
'workspace' => $js_settings,
), 'setting');
drupal_add_js(drupal_get_path('module', 'workspace') . '/workspace.js');
drupal_add_css(drupal_get_path('module', 'workspace') . '/workspace.css');
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['maxnodes'];
$comments_enabled = module_exists('comment');
$rows = array();
if ($comments_enabled) {
// If the comment module is enabled, we need to get comment counts too.
$header = array(
array(
'data' => t('Type'),
'field' => 'type',
),
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' => 3,
),
);
$countquery = db_select('node', 'n');
$countquery
->addExpression('COUNT(n.nid)', 'ct');
$countquery
->join('node_comment_statistics', 's', 'n.nid = s.nid');
$countquery
->condition('n.uid', $account->uid);
if ($filter) {
$countquery
->condition('n.type', $filter);
}
$query = db_select('node', 'n')
->extend('PagerDefault')
->limit($max)
->extend('TableSort')
->orderByHeader($header);
$query
->setCountQuery($countquery);
$query
->fields('n', array(
'nid',
'uid',
'type',
'title',
'status',
'changed',
'comment',
'promote',
'sticky',
));
$query
->addField('s', 'comment_count');
$query
->addExpression('0', 'cid');
$query
->addExpression('1', 'node');
$query
->join('node_comment_statistics', 's', 'n.nid = s.nid');
$query
->condition('n.uid', $account->uid);
if ($filter) {
$query
->condition('n.type', $filter);
}
}
else {
// Otherwise we use a simpler query.
$header = array(
array(
'data' => t('Type'),
'field' => 'type',
),
array(
'data' => t('Title'),
'field' => 'title',
),
array(
'data' => t('Published'),
'field' => 'status',
),
array(
'data' => t('Modified'),
'field' => 'changed',
'sort' => 'desc',
),
array(
'data' => t('Operations'),
'colspan' => 3,
),
);
$countquery = db_select('node', 'n');
$countquery
->addExpression('COUNT(n.nid)', 'ct');
$countquery
->condition('n.uid', $account->uid);
if ($filter) {
$countquery
->condition('n.type', $filter);
}
$query = db_select('node', 'n')
->extend('PagerDefault')
->limit($max)
->extend('TableSort')
->orderByHeader($header);
$query
->setCountQuery($countquery);
$query
->fields('n', array(
'nid',
'uid',
'type',
'title',
'status',
'changed',
'comment',
'promote',
'sticky',
));
$query
->addExpression('0', 'cid');
$query
->addExpression('1', 'node');
$query
->condition('n.uid', $account->uid);
if ($filter) {
$query
->condition('n.type', $filter);
}
}
$records = $query
->execute();
$rows = workspace_build_rows($records, $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 .= render(drupal_get_form('workspace_add_form'));
}
$output .= render(drupal_get_form('workspace_list_form', $account->uid, $filter));
$output .= theme('workspace_list', array(
'header' => $header,
'rows' => $rows,
));
return $output;
}