| 1 |
<?php
|
| 2 |
// $Id: spaces_dashboard.module,v 1.14.6.3 2008/10/01 06:00:59 yhahn Exp $
|
| 3 |
|
| 4 |
/*
|
| 5 |
* Implementation of hook_menu()
|
| 6 |
*/
|
| 7 |
function spaces_dashboard_menu($may_cache) {
|
| 8 |
if ($may_cache) {
|
| 9 |
$items[] = array(
|
| 10 |
'path' => 'group_dashboard',
|
| 11 |
'title' => t('Group Dashboard'),
|
| 12 |
'description' => t('Allows a user in multiple groups to get a birds-eye view of her groups.'),
|
| 13 |
'callback' => 'spaces_dashboard_group_dashboard',
|
| 14 |
'access' => user_access('access content'),
|
| 15 |
'type' => MENU_NORMAL_ITEM,
|
| 16 |
);
|
| 17 |
if (module_exists('ucreate')) {
|
| 18 |
$items[] = array(
|
| 19 |
'path' => 'group_dashboard/team',
|
| 20 |
'title' => t('Users'),
|
| 21 |
'description' => t('A full listing of users on the spaces.'),
|
| 22 |
'callback' => 'spaces_dashboard_team',
|
| 23 |
'access' => user_access('create users'),
|
| 24 |
'type' => MENU_NORMAL_ITEM,
|
| 25 |
);
|
| 26 |
}
|
| 27 |
}
|
| 28 |
return $items;
|
| 29 |
}
|
| 30 |
|
| 31 |
/**
|
| 32 |
* Implementation of hook_help()
|
| 33 |
*/
|
| 34 |
function spaces_dashboard_help($page) {
|
| 35 |
switch ($page) {
|
| 36 |
case 'group_dashboard':
|
| 37 |
case 'group_dashboard/dashboard':
|
| 38 |
return "<p>". t('The group dashboard shows you the latest content across all of your groups. You can limit the listing by using the dropdown filter.') ."</p>";
|
| 39 |
case 'group_dashboard/group_directory':
|
| 40 |
return "<p>". t('The directory lists all groups you have access to. You may join groups that interest you if they allow others to join or request membership.') ."</p>";
|
| 41 |
case 'group_dashboard/team':
|
| 42 |
return "<p>". t('You can manage user accounts and group membership from this page. Select multiple users to add or remove them from a group.') ."</p>";
|
| 43 |
break;
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
/*
|
| 48 |
* Implementation of hook_form_alter()
|
| 49 |
*/
|
| 50 |
function spaces_dashboard_form_alter($form_id, &$form) {
|
| 51 |
switch ($form_id) {
|
| 52 |
case 'ucreate_user_form':
|
| 53 |
context_set('spaces', 'feature', 'group_dashboard');
|
| 54 |
break;
|
| 55 |
case 'views_filters':
|
| 56 |
// Switch nid text filter to a select
|
| 57 |
if ($form['view']['#value']->name == 'spaces_group_dashboard') {
|
| 58 |
global $user;
|
| 59 |
$options = array(
|
| 60 |
'**ALL**' => '-- '. t('All of my groups') .' --',
|
| 61 |
);
|
| 62 |
foreach ($user->og_groups as $gid => $group) {
|
| 63 |
$options[$gid] = truncate_utf8($group['title'], 30, false, true);
|
| 64 |
}
|
| 65 |
$form['filter0'] = array(
|
| 66 |
'#type' => 'select',
|
| 67 |
'#options' => $options,
|
| 68 |
'#default_value' => $_GET['filter0'] ? $_GET['filter0'] : '**ALL**',
|
| 69 |
);
|
| 70 |
$form['#action'] = 'group_dashboard';
|
| 71 |
}
|
| 72 |
break;
|
| 73 |
}
|
| 74 |
}
|
| 75 |
|
| 76 |
/**
|
| 77 |
* Implementation of hook_context_define()
|
| 78 |
*/
|
| 79 |
function spaces_dashboard_context_define() {
|
| 80 |
global $user;
|
| 81 |
$items = array();
|
| 82 |
$items[] = array(
|
| 83 |
'namespace' => 'spaces',
|
| 84 |
'attribute' => 'feature',
|
| 85 |
'value' => 'group_dashboard',
|
| 86 |
'node' => og_get_types('group'),
|
| 87 |
'views' => array('spaces_group_dashboard', 'spaces_group_directory', 'spaces_group_my'),
|
| 88 |
'block' => array(
|
| 89 |
array(
|
| 90 |
'module' => 'views',
|
| 91 |
'delta' => 'spaces_group_my',
|
| 92 |
'region' => 'right',
|
| 93 |
'weight' => -11,
|
| 94 |
),
|
| 95 |
),
|
| 96 |
'menu' => array('group_dashboard'),
|
| 97 |
);
|
| 98 |
return $items;
|
| 99 |
}
|
| 100 |
|
| 101 |
/**
|
| 102 |
* Implementation of hook_default_views
|
| 103 |
*/
|
| 104 |
function spaces_dashboard_views_default_views() {
|
| 105 |
$default_views = array(
|
| 106 |
'_spaces_dashboard_views_group_dashboard',
|
| 107 |
'_spaces_dashboard_views_group_directory',
|
| 108 |
'_spaces_dashboard_views_group_my'
|
| 109 |
);
|
| 110 |
foreach ($default_views as $v) {
|
| 111 |
$view = call_user_func($v);
|
| 112 |
if (is_object($view) && $view->name) {
|
| 113 |
$views[$view->name] = $view;
|
| 114 |
}
|
| 115 |
}
|
| 116 |
return $views;
|
| 117 |
}
|
| 118 |
|
| 119 |
/**
|
| 120 |
* Implements a group dashboard for users in multiple groups
|
| 121 |
* TODO: implement "fires" listing
|
| 122 |
*/
|
| 123 |
function spaces_dashboard_group_dashboard() {
|
| 124 |
global $user;
|
| 125 |
if ($space = spaces_get_space()) {
|
| 126 |
$space->redirect('home');
|
| 127 |
}
|
| 128 |
else if ($user->uid != 0) {
|
| 129 |
// User is a member of many groups, show the dashboard.
|
| 130 |
if (count($user->og_groups)) {
|
| 131 |
return views_build_view('page', views_get_view('spaces_group_dashboard'), null, true, 25);
|
| 132 |
}
|
| 133 |
else {
|
| 134 |
// Set the context as if the view were built
|
| 135 |
context_ui_set('views', 'spaces_group_dashboard');
|
| 136 |
|
| 137 |
// Check whether any 'joinable' groups exist
|
| 138 |
$group_count = db_result(db_query("SELECT count(n.nid) FROM {node} n JOIN {og} og ON n.nid = og.nid WHERE n.status = 1 AND og.selective = 0"));
|
| 139 |
|
| 140 |
// There are groups to join
|
| 141 |
if ($group_count) {
|
| 142 |
$message = t("You are currently not a member of any groups. You can browse the group directory and join groups that interest you.");
|
| 143 |
$buttons = l(t('Group Directory'), 'group_dashboard/group_directory', array('class' => 'button'));
|
| 144 |
}
|
| 145 |
else {
|
| 146 |
// User can make groups
|
| 147 |
if (node_access('create', $group_types[0])) {
|
| 148 |
$message = t("There are currently no groups available for you to join. Please create your first group to get started.");
|
| 149 |
$buttons = spaces_node_links();
|
| 150 |
}
|
| 151 |
// User has no groups to join, and can't make one
|
| 152 |
else {
|
| 153 |
$message = t("You are currently not a member of any groups. Please ask a site administrator to add your account to one of the site's groups.");
|
| 154 |
}
|
| 155 |
}
|
| 156 |
drupal_set_message("<p>$message</p><div class='buttons'>$buttons</div>");
|
| 157 |
return '';
|
| 158 |
}
|
| 159 |
}
|
| 160 |
else {
|
| 161 |
// User shouldn't be here.
|
| 162 |
drupal_access_denied();
|
| 163 |
exit;
|
| 164 |
}
|
| 165 |
}
|
| 166 |
|
| 167 |
/*
|
| 168 |
* A user listing page
|
| 169 |
*/
|
| 170 |
function spaces_dashboard_team($gid = null) {
|
| 171 |
context_set('spaces', 'feature', 'group_dashboard');
|
| 172 |
|
| 173 |
// Add contextual button for adding users
|
| 174 |
if (user_access('create users')) {
|
| 175 |
$links = array();
|
| 176 |
$links[] = array(
|
| 177 |
'title' => t('User account'),
|
| 178 |
'href' => 'user/add',
|
| 179 |
);
|
| 180 |
context_set('spaces', 'links', $links);
|
| 181 |
}
|
| 182 |
|
| 183 |
drupal_add_css(drupal_get_path('module', 'spaces_dashboard') .'/spaces_dashboard.css');
|
| 184 |
drupal_add_js(drupal_get_path('module', 'spaces_dashboard') .'/spaces_dashboard.js');
|
| 185 |
|
| 186 |
$output .= drupal_get_form('spaces_dashboard_users');
|
| 187 |
return $output;
|
| 188 |
}
|
| 189 |
|
| 190 |
function spaces_views_handler_field_nodelink($fieldinfo, $fielddata, $value, $data) {
|
| 191 |
if ($fielddata['options'] == 'nolink') {
|
| 192 |
return check_plain($value);
|
| 193 |
}
|
| 194 |
return l($value, "node/$data->nid");
|
| 195 |
}
|
| 196 |
|
| 197 |
function spaces_dashboard_users() {
|
| 198 |
$form = array();
|
| 199 |
|
| 200 |
$form['groups'] = array(
|
| 201 |
'#title' => t('Group'),
|
| 202 |
'#type' => 'select',
|
| 203 |
'#options' => array('---') + og_all_groups_options(),
|
| 204 |
);
|
| 205 |
$form['actions'] = array(
|
| 206 |
'#title' => t('Actions'),
|
| 207 |
'#type' => 'select',
|
| 208 |
'#disabled' => true,
|
| 209 |
'#options' => array(
|
| 210 |
0 => '---',
|
| 211 |
t('Groups') => array(
|
| 212 |
'join' => t('Add to Group'),
|
| 213 |
'yank' => t('Remove from Group'),
|
| 214 |
),
|
| 215 |
t('Status') => array(
|
| 216 |
'active' => t('Make Active'),
|
| 217 |
'block' => t('Block Users'),
|
| 218 |
),
|
| 219 |
),
|
| 220 |
);
|
| 221 |
$form['submit'] = array(
|
| 222 |
'#type' => 'submit',
|
| 223 |
'#value' => t('Submit'),
|
| 224 |
);
|
| 225 |
|
| 226 |
$team = spaces_og_get_users(true, false, true, 20);
|
| 227 |
foreach ($team as $account) {
|
| 228 |
$account = (object) $account;
|
| 229 |
$account = user_load($account);
|
| 230 |
$form['username'][$account->uid] = array(
|
| 231 |
'#type' => 'markup',
|
| 232 |
'#value' => theme('username', $account),
|
| 233 |
);
|
| 234 |
$form['email'][$account->uid] = array(
|
| 235 |
'#type' => 'markup',
|
| 236 |
'#value' => l($account->mail, 'mailto:'. $account->mail),
|
| 237 |
);
|
| 238 |
$form['#accounts'][$account->uid] = $account;
|
| 239 |
$users[$account->uid] = '';
|
| 240 |
}
|
| 241 |
$form['users'] = array(
|
| 242 |
'#type' => 'checkboxes',
|
| 243 |
'#options' => $users,
|
| 244 |
);
|
| 245 |
$form['pager'] = array('#value' => theme('pager', NULL, 20, 0));
|
| 246 |
$form['#theme'] = 'spaces_dashboard_users';
|
| 247 |
return $form;
|
| 248 |
}
|
| 249 |
|
| 250 |
function spaces_dashboard_users_submit($form_id, $form_values) {
|
| 251 |
$gid = $form_values['groups'];
|
| 252 |
$action = $form_values['actions'];
|
| 253 |
$users = array();
|
| 254 |
foreach ($form_values['users'] as $uid => $selected) {
|
| 255 |
if ($selected) {
|
| 256 |
$users[] = $uid;
|
| 257 |
}
|
| 258 |
}
|
| 259 |
_spaces_dashboard_user_batch($action, $users, $gid);
|
| 260 |
return 'group_dashboard/team';
|
| 261 |
}
|
| 262 |
|
| 263 |
function _spaces_dashboard_user_batch($op = 'active', $users, $gid = null) {
|
| 264 |
switch ($op) {
|
| 265 |
case 'active':
|
| 266 |
case 'block':
|
| 267 |
$status = ($op == 'active') ? 1 : 0;
|
| 268 |
foreach ($users as $uid) {
|
| 269 |
$account = user_load(array('uid' => $uid));
|
| 270 |
user_save($account, array('status' => $status));
|
| 271 |
}
|
| 272 |
return true;
|
| 273 |
case 'join':
|
| 274 |
// check gid for validity
|
| 275 |
if (is_numeric($gid) && $node = node_load($gid)) {
|
| 276 |
if (og_is_group_type($node->type)) {
|
| 277 |
foreach ($users as $uid) {
|
| 278 |
$account = user_load(array('uid' => $uid));
|
| 279 |
if (!isset($account->og_groups[$gid])) {
|
| 280 |
og_save_subscription($gid, $uid, array('is_active' => 1));
|
| 281 |
}
|
| 282 |
}
|
| 283 |
return true;
|
| 284 |
}
|
| 285 |
}
|
| 286 |
return false;
|
| 287 |
case 'yank':
|
| 288 |
// check gid for validity
|
| 289 |
if (is_numeric($gid) && $node = node_load($gid)) {
|
| 290 |
if (og_is_group_type($node->type)) {
|
| 291 |
foreach ($users as $uid) {
|
| 292 |
$account = user_load(array('uid' => $uid));
|
| 293 |
if (isset($account->og_groups[$gid])) {
|
| 294 |
og_delete_subscription($gid, $uid);
|
| 295 |
}
|
| 296 |
}
|
| 297 |
return true;
|
| 298 |
}
|
| 299 |
}
|
| 300 |
return false;
|
| 301 |
}
|
| 302 |
}
|
| 303 |
|
| 304 |
function theme_spaces_dashboard_users($form) {
|
| 305 |
$row = array();
|
| 306 |
$labels[] = $form['groups']['#title'];
|
| 307 |
$labels[] = $form['actions']['#title'];
|
| 308 |
$labels[] = '';
|
| 309 |
unset($form['groups']['#title']);
|
| 310 |
unset($form['actions']['#title']);
|
| 311 |
$row[] = drupal_render($form['groups']);
|
| 312 |
$row[] = drupal_render($form['actions']);
|
| 313 |
$row[] = drupal_render($form['submit']);
|
| 314 |
$output .= theme('table', $labels, array($row));
|
| 315 |
|
| 316 |
// Overview table:
|
| 317 |
$header = array(theme('table_select_header_cell'), t('Name'), t('User Info'));
|
| 318 |
if (isset($form['username']) && is_array($form['username'])) {
|
| 319 |
foreach (element_children($form['username']) as $key) {
|
| 320 |
$groups = $groupnames = array();
|
| 321 |
foreach ($form['#accounts'][$key]->og_groups as $gid => $node) {
|
| 322 |
$groupnames[] = $node['title'];
|
| 323 |
$groups[] = 'og-'. $gid;
|
| 324 |
}
|
| 325 |
$groups = implode(' ', $groups);
|
| 326 |
$groupnames = "<div class='groupnames'>". implode(', ', $groupnames) ."</div>";
|
| 327 |
$row = array();
|
| 328 |
$row[] = drupal_render($form['users'][$key]);
|
| 329 |
$row[] = array('data' => drupal_render($form['username'][$key]), 'class' => 'name');
|
| 330 |
$row[] = drupal_render($form['email'][$key]) . $groupnames;
|
| 331 |
// $row[] = $form['#accounts'][$key]->status ? t('Active') : t('Blocked');
|
| 332 |
$rows[] = array(
|
| 333 |
'data' => $row,
|
| 334 |
'class' => $groups . ($form['#accounts'][$key]->status ? '' : ' blocked'),
|
| 335 |
);
|
| 336 |
}
|
| 337 |
|
| 338 |
}
|
| 339 |
else {
|
| 340 |
$rows[] = array(array('data' => t('No users found.'), 'colspan' => '4'));
|
| 341 |
}
|
| 342 |
|
| 343 |
$output .= theme('table', $header, $rows);
|
| 344 |
if ($form['pager']['#value']) {
|
| 345 |
$output .= drupal_render($form['pager']);
|
| 346 |
}
|
| 347 |
|
| 348 |
$output .= drupal_render($form);
|
| 349 |
|
| 350 |
return $output;
|
| 351 |
}
|
| 352 |
|
| 353 |
/**
|
| 354 |
* Provides a links array suitable for use with theme_links() to the
|
| 355 |
* dashboard pages.
|
| 356 |
*/
|
| 357 |
function spaces_dashboard_nav_links() {
|
| 358 |
$links = array();
|
| 359 |
$links[] = array(
|
| 360 |
'title' => t('Dashboard'),
|
| 361 |
'href' => 'group_dashboard',
|
| 362 |
);
|
| 363 |
$links[] = array(
|
| 364 |
'title' => t('Directory'),
|
| 365 |
'href' => 'group_dashboard/group_directory',
|
| 366 |
);
|
| 367 |
if (module_exists('ucreate') && user_access('create users')) {
|
| 368 |
$links[] = array(
|
| 369 |
'title' => t('Users'),
|
| 370 |
'href' => 'group_dashboard/team',
|
| 371 |
);
|
| 372 |
}
|
| 373 |
return $links;
|
| 374 |
}
|
| 375 |
|
| 376 |
/*
|
| 377 |
* EXPORTED VIEWS ======================================================
|
| 378 |
*/
|
| 379 |
|
| 380 |
function _spaces_dashboard_views_group_dashboard() {
|
| 381 |
$view = new stdClass();
|
| 382 |
$view->name = 'spaces_group_dashboard';
|
| 383 |
$view->description = '';
|
| 384 |
$view->access = array ();
|
| 385 |
$view->view_args_php = '';
|
| 386 |
$view->page = TRUE;
|
| 387 |
$view->page_title = 'Group Dashboard';
|
| 388 |
$view->page_empty = '<p>'. t('No posts found in your groups.') .'</p>';
|
| 389 |
$view->page_empty_format = '4';
|
| 390 |
$view->page_type = 'table';
|
| 391 |
$view->use_pager = TRUE;
|
| 392 |
$view->nodes_per_page = '25';
|
| 393 |
$view->sort = array (
|
| 394 |
array (
|
| 395 |
'tablename' => 'node_comment_statistics',
|
| 396 |
'field' => 'last_changed',
|
| 397 |
'sortorder' => 'DESC',
|
| 398 |
'options' => 'normal',
|
| 399 |
),
|
| 400 |
);
|
| 401 |
$view->argument = array ();
|
| 402 |
$view->field = array (
|
| 403 |
array (
|
| 404 |
'tablename' => 'og_node_data',
|
| 405 |
'field' => 'title',
|
| 406 |
'label' => 'Group',
|
| 407 |
'handler' => 'spaces_views_handler_crayon_name',
|
| 408 |
'options' => 'og',
|
| 409 |
),
|
| 410 |
array (
|
| 411 |
'tablename' => 'node',
|
| 412 |
'field' => 'title',
|
| 413 |
'label' => 'Title',
|
| 414 |
'handler' => 'spaces_views_handler_field_nodelink',
|
| 415 |
'options' => 'link',
|
| 416 |
),
|
| 417 |
array (
|
| 418 |
'tablename' => 'node',
|
| 419 |
'field' => 'type',
|
| 420 |
'label' => 'Type',
|
| 421 |
),
|
| 422 |
array (
|
| 423 |
'tablename' => 'node_comment_statistics',
|
| 424 |
'field' => 'last_comment_name',
|
| 425 |
'label' => 'Last post',
|
| 426 |
),
|
| 427 |
array (
|
| 428 |
'tablename' => 'node_comment_statistics',
|
| 429 |
'field' => 'last_changed',
|
| 430 |
'label' => 'On',
|
| 431 |
'handler' => 'views_handler_field_since',
|
| 432 |
'options' => 1,
|
| 433 |
),
|
| 434 |
);
|
| 435 |
if (variable_get('spaces_calendar_feed_itemtype', '')) {
|
| 436 |
$excluded = array('shout', variable_get('spaces_calendar_feed_itemtype', ''));
|
| 437 |
}
|
| 438 |
else {
|
| 439 |
$excluded = array('shout');
|
| 440 |
}
|
| 441 |
$view->filter = array (
|
| 442 |
array (
|
| 443 |
'tablename' => 'node',
|
| 444 |
'field' => 'status',
|
| 445 |
'operator' => '=',
|
| 446 |
'options' => '',
|
| 447 |
'value' => '1',
|
| 448 |
),
|
| 449 |
array (
|
| 450 |
'tablename' => 'node',
|
| 451 |
'field' => 'type',
|
| 452 |
'operator' => 'NOR',
|
| 453 |
'options' => '',
|
| 454 |
'value' => array_merge(
|
| 455 |
og_get_types('group'),
|
| 456 |
$excluded
|
| 457 |
),
|
| 458 |
),
|
| 459 |
array (
|
| 460 |
'tablename' => 'og_uid_node',
|
| 461 |
'field' => 'currentuid',
|
| 462 |
'operator' => '=',
|
| 463 |
'options' => '',
|
| 464 |
'value' => '***CURRENT_USER***',
|
| 465 |
),
|
| 466 |
array (
|
| 467 |
'tablename' => 'node',
|
| 468 |
'field' => 'changed',
|
| 469 |
'operator' => '>',
|
| 470 |
'options' => -1*SPACES_ARCHIVE_TIMESTAMP,
|
| 471 |
'value' => 'now',
|
| 472 |
),
|
| 473 |
array (
|
| 474 |
'tablename' => 'og_ancestry',
|
| 475 |
'field' => 'gid',
|
| 476 |
'operator' => '=',
|
| 477 |
'options' => '',
|
| 478 |
'value' => '',
|
| 479 |
),
|
| 480 |
);
|
| 481 |
$view->exposed_filter = array (
|
| 482 |
array (
|
| 483 |
'tablename' => 'og_ancestry',
|
| 484 |
'field' => 'gid',
|
| 485 |
'label' => 'Posts in my groups',
|
| 486 |
'optional' => '1',
|
| 487 |
'is_default' => '0',
|
| 488 |
'operator' => '1',
|
| 489 |
'single' => '1',
|
| 490 |
),
|
| 491 |
);
|
| 492 |
$view->requires = array(node_comment_statistics, og_node_data, node, og_uid_node, og_ancestry);
|
| 493 |
return $view;
|
| 494 |
}
|
| 495 |
|
| 496 |
function _spaces_dashboard_views_group_my() {
|
| 497 |
$view = new stdClass();
|
| 498 |
$view->name = 'spaces_group_my';
|
| 499 |
$view->description = '';
|
| 500 |
$view->access = array ();
|
| 501 |
$view->view_args_php = '';
|
| 502 |
$view->page = FALSE;
|
| 503 |
$view->block = TRUE;
|
| 504 |
$view->block_title = 'My Groups';
|
| 505 |
$view->block_empty = '<p>'. t('No groups found') .'</p>';
|
| 506 |
$view->block_empty_format = '2';
|
| 507 |
$view->block_type = 'spaces_datetitle';
|
| 508 |
$view->nodes_per_block = '99';
|
| 509 |
$view->sort = array (
|
| 510 |
array (
|
| 511 |
'tablename' => 'node',
|
| 512 |
'field' => 'title',
|
| 513 |
'sortorder' => 'ASC',
|
| 514 |
'options' => '',
|
| 515 |
),
|
| 516 |
);
|
| 517 |
$view->argument = array (
|
| 518 |
);
|
| 519 |
$view->field = array (
|
| 520 |
array (
|
| 521 |
'tablename' => 'node',
|
| 522 |
'field' => 'title',
|
| 523 |
'label' => '',
|
| 524 |
'handler' => '_spaces_dashboard_views_handler_field_nodelink',
|
| 525 |
'options' => 'link',
|
| 526 |
),
|
| 527 |
array (
|
| 528 |
'tablename' => 'og',
|
| 529 |
'field' => 'private',
|
| 530 |
'label' => '',
|
| 531 |
),
|
| 532 |
);
|
| 533 |
$view->filter = array (
|
| 534 |
array (
|
| 535 |
'tablename' => 'og_uid',
|
| 536 |
'field' => 'currentuidsimple',
|
| 537 |
'operator' => '=',
|
| 538 |
'options' => '',
|
| 539 |
'value' => '***CURRENT_USER***',
|
| 540 |
),
|
| 541 |
);
|
| 542 |
$view->exposed_filter = array ();
|
| 543 |
$view->requires = array(node, og_uid);
|
| 544 |
return $view;
|
| 545 |
}
|
| 546 |
|
| 547 |
function _spaces_dashboard_views_group_directory() {
|
| 548 |
$view = new stdClass();
|
| 549 |
$view->name = 'spaces_group_directory';
|
| 550 |
$view->description = '';
|
| 551 |
$view->access = array ();
|
| 552 |
$view->view_args_php = '';
|
| 553 |
$view->menu = TRUE;
|
| 554 |
$view->menu_title = t('Directory');
|
| 555 |
$view->page = TRUE;
|
| 556 |
$view->page_title = t('Group Directory');
|
| 557 |
$view->page_type = 'table';
|
| 558 |
$view->url = 'group_dashboard/group_directory';
|
| 559 |
$view->use_pager = TRUE;
|
| 560 |
$view->nodes_per_page = '25';
|
| 561 |
$view->sort = array (
|
| 562 |
array (
|
| 563 |
'tablename' => 'node',
|
| 564 |
'field' => 'title',
|
| 565 |
'sortorder' => 'ASC',
|
| 566 |
'options' => '',
|
| 567 |
),
|
| 568 |
);
|
| 569 |
$view->argument = array ();
|
| 570 |
$view->field = array (
|
| 571 |
array (
|
| 572 |
'tablename' => 'node',
|
| 573 |
'field' => 'title',
|
| 574 |
'label' => 'Group',
|
| 575 |
'handler' => '_spaces_dashboard_views_handler_field_nodelink',
|
| 576 |
'options' => 'link',
|
| 577 |
),
|
| 578 |
array (
|
| 579 |
'tablename' => 'og',
|
| 580 |
'field' => 'private',
|
| 581 |
'handler' => '_spaces_dashboard_views_handler_field_private',
|
| 582 |
'label' => 'Privacy',
|
| 583 |
),
|
| 584 |
array (
|
| 585 |
'tablename' => 'og',
|
| 586 |
'field' => 'count',
|
| 587 |
'label' => 'Members',
|
| 588 |
),
|
| 589 |
);
|
| 590 |
$view->filter = array (
|
| 591 |
array (
|
| 592 |
'tablename' => 'node',
|
| 593 |
'field' => 'status',
|
| 594 |
'operator' => '=',
|
| 595 |
'options' => '',
|
| 596 |
'value' => '1',
|
| 597 |
),
|
| 598 |
array (
|
| 599 |
'tablename' => 'node',
|
| 600 |
'field' => 'type',
|
| 601 |
'operator' => 'OR',
|
| 602 |
'options' => '',
|
| 603 |
'value' => og_get_types('group'),
|
| 604 |
),
|
| 605 |
);
|
| 606 |
$view->exposed_filter = array ();
|
| 607 |
$view->requires = array(node, og);
|
| 608 |
return $view;
|
| 609 |
}
|
| 610 |
|
| 611 |
/**
|
| 612 |
* Custom views field handler for adding a class to distinguish
|
| 613 |
* between public/private group nodes. Requires a field for
|
| 614 |
* og_private in the view.
|
| 615 |
*/
|
| 616 |
function _spaces_dashboard_views_handler_field_nodelink($fieldinfo, $fielddata, $value, $data) {
|
| 617 |
if ($fielddata['options'] == 'nolink') {
|
| 618 |
return check_plain($value);
|
| 619 |
}
|
| 620 |
return $data->og_private ? l($value, "node/$data->nid", array('class' => 'private')) : l($value, "node/$data->nid", array('class' => 'public'));
|
| 621 |
}
|
| 622 |
|
| 623 |
/**
|
| 624 |
* Handler to display public/private text.
|
| 625 |
*/
|
| 626 |
function _spaces_dashboard_views_handler_field_private($fieldinfo, $fielddata, $value, $data) {
|
| 627 |
return $data->og_private ? t('Private') : t('Public');
|
| 628 |
}
|