/[drupal]/contributions/modules/signup/includes/no_views.inc
ViewVC logotype

Contents of /contributions/modules/signup/includes/no_views.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.17 - (show annotations) (download) (as text)
Mon Aug 10 17:45:47 2009 UTC (3 months, 2 weeks ago) by dww
Branch: MAIN
CVS Tags: HEAD
Changes since 1.16: +2 -2 lines
File MIME type: text/x-php
#544882 by dereine: Fixed a few places that called node_load() so that
they can now make use of the node caching feature.
1 <?php
2 // $Id: no_views.inc,v 1.16 2009/01/24 04:24:25 dww Exp $
3
4
5 /**
6 * @file
7 * Provides all the code for required UI elements for sites that do
8 * not have views.module enabled. If views is enabled, there are
9 * default views for all of these things (which are therefore
10 * customizable and more powerful) in signup/views/views.inc.
11 *
12 */
13
14 /**
15 * Implementation of hook_block().
16 *
17 * @ingroup signup_core
18 *
19 * @param $op
20 * The operation that is being requested. This defaults to 'list', which
21 * indicates that the method should return which blocks are available.
22 * @param $delta
23 * The specific block to display (the offset into an array).
24 *
25 * @return
26 * One of two possibilities. The first is an array of available blocks.
27 * The other is an array containing a block.
28 */
29 function signup_block($op = 'list', $delta = 0) {
30 global $user;
31 switch ($op) {
32 case 'list':
33 $blocks[0]['info'] = t('Current signups');
34 return $blocks;
35 break;
36 case 'view':
37 if (user_access('access content')) {
38 switch ($delta) {
39 case 0:
40 $titles = signup_list_user_signups($user->uid);
41 if (count($titles)) {
42 $block['subject'] = t('Current signups');
43 $block['content'] = theme_item_list($titles) . l(t('View signup schedule'), "user/$user->uid/signups");
44 }
45 return $block;
46 }
47 }
48 }
49 }
50
51 /**
52 * Private helper as a partial implementation of hook_user().
53 *
54 * @see signup_user()
55 */
56 function _signup_user_no_views($op, &$edit, &$user, $category = NULL) {
57 switch ($op) {
58 case 'view':
59 // grab list of nodes the user signed up for.
60 $signups = signup_list_user_signups($user->uid);
61 if (count($signups) && variable_get('signup_no_views_user_info', TRUE)) {
62 $user->content['signup'] = array(
63 '#type' => 'user_profile_category',
64 '#attributes' => array('class' => 'signup'),
65 '#weight' => 5,
66 '#title' => t('Signup information'),
67 );
68 $user->content['signup']['current'] = array(
69 '#type' => 'user_profile_item',
70 '#attributes' => array('class' => 'signup-current'),
71 '#title' => t('Current signups'),
72 '#value' => theme_item_list($signups),
73 '#weight' => 0,
74 );
75 $user->content['signup']['schedule'] = array(
76 '#type' => 'user_profile_item',
77 '#attributes' => array('class' => 'signup-schedule'),
78 '#title' => t('Signup schedule'),
79 '#value' => l(t('View full signup schedule'), 'user/'. $user->uid .'/signups'),
80 '#weight' => 2,
81 );
82 }
83 break;
84 }
85 }
86
87 /**
88 * Add menu items we only need to define if views is not enabled.
89 */
90 function signup_no_views_menu(&$items) {
91 // User signup schedule callback
92 $items['user/%user/signups'] = array(
93 'title' => 'Signups',
94 'page callback' => 'signup_user_schedule',
95 'page arguments' => array(1),
96 'type' => MENU_CALLBACK,
97 'access callback' => '_signup_no_views_user_menu_access',
98 'access arguments' => array(1),
99 'file' => 'includes/no_views.inc',
100 );
101 }
102
103 function _signup_no_views_user_menu_access($account) {
104 return variable_get('signup_no_views_user_info', TRUE) && _signup_user_menu_access($account);
105 }
106
107 /**
108 * Print a schedule of the given user's signups.
109 *
110 * @ingroup signup_callback
111 */
112 function signup_user_schedule($account) {
113 $output = '';
114 drupal_set_title(t('Signups for @user', array('@user' => $account->name)));
115 $titles = signup_list_user_signups($account->uid);
116 foreach ($titles as $nid => $title) {
117 $node = node_load($nid);
118 $output .= theme('signup_user_schedule', $node);
119 }
120 return $output;
121 }
122
123 /**
124 * Return an array of all nodes the specified user has signed up for.
125 *
126 * @param $uid
127 * The ID of the user to generate a list of signups for.
128 *
129 * @return
130 * Array of all nodes the given user has signed up for. The array is indexed
131 * by node ID, and contains titles as links to each node.
132 */
133 function signup_list_user_signups($uid) {
134 $titles = array();
135
136 // We don't want to return anything for anon users.
137 if ($uid != 0) {
138 $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";
139 $result = db_query(db_rewrite_sql($sql), $uid);
140 while ($node = db_fetch_array($result)) {
141 $titles[$node['nid']] = l($node['title'], 'node/'. $node['nid']);
142 }
143 }
144 return $titles;
145 }

  ViewVC Help
Powered by ViewVC 1.1.2