Index: modules/signup/signup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup.module,v
retrieving revision 1.105
diff -u -p -r1.105 signup.module
--- modules/signup/signup.module 18 Apr 2007 18:08:39 -0000 1.105
+++ modules/signup/signup.module 20 Apr 2007 22:09:22 -0000
@@ -7,44 +7,13 @@ include_once(drupal_get_path('module', '
* @defgroup signup_core Core drupal hooks
*/
-/**
- * Implementation of hook_block().
- * @ingroup signup_core
- * @param $op
- * The operation that is being requested. This defaults to 'list', which
- * indicates that the method should return which blocks are available.
- * @param $delta
- * The specific block to display (the offset into an array).
- * @return
- * One of two possibilities. The first is an array of available blocks.
- * The other is an array containing a block.
- */
-function signup_block($op = 'list', $delta = 0) {
- global $user;
- switch ($op) {
- case 'list' :
- $blocks[0]['info'] = t('List of users current signups.');
- return $blocks;
- break;
- case 'view' :
- if (user_access('access content')) {
- switch ($delta) {
- case 0:
- $titles = signup_list_user_signups($user->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;
- }
- }
- }
-}
-
function signup_init() {
if (module_exists('views')) {
require './'. drupal_get_path('module', 'signup'). '/signup_views.inc';
}
+ else {
+ require './'. drupal_get_path('module', 'signup'). '/signup_no_views.inc';
+ }
}
/**
@@ -197,15 +166,6 @@ function signup_menu($may_cache) {
}
else { // !$may_cache: dynamic menu items
- // 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)),
- );
-
// If it's a signup-enabled node, then put in a signup tab for admins.
if (arg(0) == 'node' && is_numeric(arg(1)) && db_num_rows(db_query("SELECT nid FROM {signup} WHERE nid = %d", arg(1)))) {
$node = node_load(array('nid' => arg(1)));
@@ -232,6 +192,9 @@ function signup_menu($may_cache) {
);
}
}
+ if (function_exists('signup_no_views_menu')) {
+ signup_no_views_menu($items, $may_cache);
+ }
return $items;
}
@@ -251,24 +214,6 @@ function signup_perm() {
}
/**
- * Implementation of hook_user().
- * @ingroup signup_core
- */
-function signup_user($op, &$edit, &$user, $category = NULL) {
- switch ($op) {
- case 'view':
- // grab list of events 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')));
- }
- }
-}
-
-/**
* Implementation of hook_form_alter().
* @ingroup signup_core
*/
@@ -974,11 +919,10 @@ function signup_list_user_signups($uid)
if ($uid != 0) {
$has_event = module_exists('event');
$event_join = $has_event ? ' LEFT JOIN {event} e ON e.nid = n.nid' : '';
- $event_where = $has_event ? ' AND (e.event_start >= '. time() . ' OR e.event_start IS NULL)' : '';
$order_by = $has_event ? 'e.event_start' : 'n.title';
// Pull all open signup nodes for this user.
- $result = db_query(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n INNER JOIN {signup_log} s_l ON n.nid = s_l.nid $event_join WHERE s_l.uid = '%s' $event_where ORDER BY $order_by"), $uid);
+ $result = db_query(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n INNER JOIN {signup_log} s_l ON n.nid = s_l.nid INNER JOIN {signup} s ON n.nid = s.nid $event_join WHERE s_l.uid = '%s' AND s.status = 1 ORDER BY $order_by"), $uid);
while ($node = db_fetch_array($result)) {
$titles[$node['nid']] = l($node['title'], 'node/'. $node['nid']);
}
@@ -1109,26 +1053,6 @@ function signup_sign_up_user($signup_for
}
/**
- * Prints 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) {
- drupal_not_found();
- return;
- }
- 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;
-}
-
-/**
* Prints the signup details for a single node when the signups tab is clicked
* @ingroup signup_callback
*/
Index: modules/signup/signup_views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/signup_views.inc,v
retrieving revision 1.1
diff -u -p -r1.1 signup_views.inc
--- modules/signup/signup_views.inc 7 Apr 2007 18:57:28 -0000 1.1
+++ modules/signup/signup_views.inc 20 Apr 2007 22:09:22 -0000
@@ -4,8 +4,12 @@
* @file
* Provides support for Views integration.
*
- * Currently, this only exposes signup-related data, but does not
- * define any default views.
+ * This exposes signup-related data and provides fields, filters,
+ * sorts, and arguments.
+ *
+ * Additionally, default views for standard parts of the signup UI are
+ * defined here. If views is not enabled, these UI elements are
+ * implemented in signup_no_views.inc.
*/
/**
@@ -325,3 +329,88 @@ function views_handler_filter_signup_uid
$query->add_where("%s = 0", $field);
}
}
+
+/**
+ * Default views for core features of the signup UI that should always
+ * be enabled and available.
+ *
+ * For now, this is just a single view that implements the user's
+ * signup schedule at user/N/signups and the "Current signups" block.
+ */
+function signup_views_default_views() {
+ $view = new stdClass();
+ $view->name = 'signup_current_signups';
+ $view->description = t('A list of all signups for the current user');
+ $view->access = array (
+);
+ $view->view_args_php = 'if ($type == \'block\') {
+ global $user;
+ return array(0 => $user->uid);
+}
+';
+ $view->page = TRUE;
+ $view->page_title = t('Current signups');
+ $view->page_header = '';
+ $view->page_header_format = '1';
+ $view->page_footer = '';
+ $view->page_footer_format = '1';
+ $view->page_empty = t('This user has not signed up for any content.');
+ $view->page_empty_format = '1';
+ $view->page_type = 'list';
+ $view->url = 'user/$arg/signups';
+ $view->use_pager = TRUE;
+ $view->nodes_per_page = '20';
+ $view->menu = TRUE;
+ $view->menu_title = t('Signups');
+ $view->menu_tab = TRUE;
+ $view->menu_tab_weight = '10';
+ $view->menu_tab_default = FALSE;
+ $view->block = TRUE;
+ $view->block_title = t('Current signups');
+ $view->block_header = '';
+ $view->block_header_format = '1';
+ $view->block_footer = '';
+ $view->block_footer_format = '1';
+ $view->block_empty = '';
+ $view->block_empty_format = '1';
+ $view->block_type = 'list';
+ $view->nodes_per_block = '10';
+ $view->block_more = TRUE;
+ $view->block_use_page_header = FALSE;
+ $view->block_use_page_footer = FALSE;
+ $view->block_use_page_empty = FALSE;
+ $view->sort = array();
+ $view->argument = array(
+ array(
+ 'type' => 'signup_uid',
+ 'argdefault' => '1',
+ 'title' => '',
+ 'options' => '1',
+ 'wildcard' => '',
+ 'wildcard_substitution' => '',
+ ),
+ );
+ $view->field = array(
+ array(
+ 'tablename' => 'node',
+ 'field' => 'title',
+ 'label' => '',
+ 'handler' => 'views_handler_field_nodelink_with_mark',
+ 'sortable' => '1',
+ 'options' => 'link',
+ ),
+ );
+ $view->filter = array(
+ array(
+ 'tablename' => 'signup',
+ 'field' => 'status',
+ 'operator' => '=',
+ 'options' => '',
+ 'value' => '1',
+ ),
+ );
+ $view->exposed_filter = array();
+ $view->requires = array(node, signup);
+ $views[$view->name] = $view;
+ return $views;
+}
Index: modules/signup/signup_no_views.inc
===================================================================
RCS file: modules/signup/signup_no_views.inc
diff -N modules/signup/signup_no_views.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/signup/signup_no_views.inc 20 Apr 2007 22:09:22 -0000
@@ -0,0 +1,100 @@
+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;
+ }
+ }
+ }
+}
+
+/**
+ * Implementation of hook_user().
+ * @ingroup signup_core
+ */
+function signup_user($op, &$edit, &$user, $category = NULL) {
+ switch ($op) {
+ case 'view':
+ // grab list of events 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')));
+ }
+ }
+}
+
+/**
+ * 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)),
+ );
+ }
+}
+
+/**
+ * Prints 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) {
+ drupal_not_found();
+ return;
+ }
+ 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;
+}