uid);
if (count($titles)) {
$block['subject'] = t('Current signups');
$block['content'] = theme_item_list($titles) . l(t('View signup schedule'), "user/$user->uid/signups");
}
return $block;
}
}
}
}
/**
* Private helper as a partial implementation of hook_user().
*
* @see signup_user()
*/
function _signup_user_no_views($op, &$edit, &$user, $category = NULL) {
switch ($op) {
case 'view':
// grab list of nodes the user signed up for.
$signups = signup_list_user_signups($user->uid);
if (count($signups)) {
$output = '
'. t('Current signups') .' -- '. l(t('view signup schedule'), "user/$user->uid/signups") .'
'. theme_item_list($signups);
}
if (isset($output)) {
return array(t('Signup information') => array(array('value' => $output, 'class' => 'user')));
}
break;
}
}
/**
* Add menu items we only need to define if views is not enabled.
*/
function signup_no_views_menu(&$items, $may_cache) {
global $user;
$access = user_access('administer all signups');
if (!$may_cache) {
// User signup schedule callback
$items[] = array(
'path' => 'user/'. arg(1) .'/signups',
'access' => ($access || ($user->uid == arg(1))),
'type' => MENU_CALLBACK,
'callback' => 'signup_user_schedule',
'callback arguments' => array($uid => arg(1)),
);
}
}
/**
* Print a schedule of the given user's signups.
*
* @ingroup signup_callback
*/
function signup_user_schedule($uid) {
$output = '';
$user = user_load(array('uid' => $uid));
if (!$user) {
return drupal_not_found();
}
require_once (SIGNUP_PATH .'/theme/signup.theme');
drupal_set_title(t('Signups for @user', array('@user' => $user->name)));
$titles = signup_list_user_signups($user->uid);
foreach ($titles as $nid => $title) {
$node = node_load(array('nid' => $nid));
$output .= theme('signup_user_schedule', $node);
}
return $output;
}
/**
* Return an array of all nodes the specified user has signed up for.
*
* @param $uid
* The ID of the user to generate a list of signups for.
*
* @return
* Array of all nodes the given user has signed up for. The array is indexed
* by node ID, and contains titles as links to each node.
*/
function signup_list_user_signups($uid) {
$titles = array();
// We don't want to return anything for anon users.
if ($uid != 0) {
$sql = "SELECT n.nid, n.title FROM {node} n INNER JOIN {signup_log} s_l ON n.nid = s_l.nid WHERE s_l.uid = %d ORDER BY n.nid";
$result = db_query(db_rewrite_sql($sql), $uid);
while ($node = db_fetch_array($result)) {
$titles[$node['nid']] = l($node['title'], 'node/'. $node['nid']);
}
}
return $titles;
}