~chad-apartmentlines/drupal/signup

« back to all changes in this revision

Viewing changes to signup.module

  • Committer: Chad Phillips
  • Date: 2006-04-17 15:55:50 UTC
  • Revision ID: thehunmonkgroup@yahoo.com-20060417155550-1e6e39641e8e64cf
removed conflict code.  changed _signup_list_user_signups to signup_list_user_signups--not really an internal function.  removed some unnecessary comparison checks. removed tablesort_pager call per HEAD change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
// $Id: signup.module,v 1.41 2006/04/13 05:49:45 thehunmonkgroup Exp $
 
2
// $Id: signup.module,v 1.45 2006/04/17 00:03:45 thehunmonkgroup Exp $
3
3
 
4
4
//  TODO's
5
5
//  1. add support limiting signups to certain roles, per node
61
61
      if (user_access('access content')) {
62
62
        switch ($delta) {
63
63
          case 0:
64
 
            $titles = _signup_list_user_signups($user->uid);
65
 
            $conflicts = _signup_get_conflicts($user->uid);
66
 
            if (count($conflicts)) {
67
 
              $conflict_teaser = '<br>'. l(t('%number schedule %conflict', array('%number' => $conflicts['total'], '%conflict' => format_plural($conflicts['total'], t('conflict exists'), t('conflicts exist')))), "user/$user->uid");
68
 
            } else {
69
 
              $conflict_teaser = '';
70
 
            }
71
 
            if (count($titles) > 0) {
 
64
            $titles = signup_list_user_signups($user->uid);
 
65
            if (count($titles)) {
72
66
              $block['subject'] = t('Current Signups');
73
 
              $block['content'] = theme_item_list($titles) . l(t('view signup schedule'), "user/$user->uid/signups"). $conflict_teaser;
 
67
              $block['content'] = theme_item_list($titles) . l(t('view signup schedule'), "user/$user->uid/signups");
74
68
            }
75
69
            return $block;
76
70
        }
175
169
      'access' => $access);
176
170
    $items[] = array('path' => 'admin/signup/overview', 'title' => t('overview'),
177
171
        'access' => $access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
178
 
    $items[] = array('path' => 'admin/signup/conflicts', 'title' => t('conflicts'),
179
 
        'callback' => 'signup_conflict_summary', 'access' => $access,
180
 
        'type' => MENU_LOCAL_TASK, 'weight' => 0);
181
 
    $items[] = array('path' => 'admin/signup/conflict_detail', 'title' => t('conflict detail'),
182
 
        'callback' => 'signup_conflict_detail', 'access' => $access,
183
 
        'type' => MENU_LOCAL_TASK, 'weight' => 3);
184
172
 
185
173
    //user signup callbacks
186
174
    $items[] = array('path' => 'signup', 'access' => TRUE, 'type' => MENU_CALLBACK, 'callback' => 'signup_user_signup');
243
231
    case 'view':
244
232
 
245
233
      //grab list of events the user signed up for
246
 
      $signups = _signup_list_user_signups($user->uid);
247
 
      if (count($signups) > 0) {
 
234
      $signups = signup_list_user_signups($user->uid);
 
235
      if (count($signups)) {
248
236
        $output = t('<h4>Current Signups -- '. l(t('view signup schedule'), "user/$user->uid/signups") .'<h4>') . theme_item_list($signups);
249
237
      }
250
238
 
251
 
      //grab list of signup conflict data for this user
252
 
      $conflicts = _signup_user_conflicts($user->uid);
253
 
      if (isset($conflicts)) {
254
 
        $output .= $conflicts['title'] . $conflicts['data'];
255
 
      }
256
239
      if (isset($output)) {
257
240
        return array(t('Signup information') => array( array('value' => $output, 'class' => 'user')));
258
241
      }
520
503
    $rows[] = $row;
521
504
  }
522
505
  $output .= theme('table', $header, $rows, array('style' => 'width:100%'));
523
 
  $pager = theme('pager', NULL, 25, 0, tablesort_pager());
 
506
  $pager = theme('pager', NULL, 25, 0);
524
507
  if (!empty($pager)) {
525
508
    $output .= $pager;
526
509
  }
565
548
}
566
549
 
567
550
/**
568
 
 * Callback function for generating a detail report of signup conflicts
569
 
 * @ingroup signup_callback
570
 
 */
571
 
function signup_conflict_detail() {
572
 
 
573
 
  //pull all users who have signed up for a node
574
 
  $result = db_query('SELECT DISTINCT u.uid, u.name FROM {users} u INNER JOIN {signup_log} s on u.uid = s.uid ORDER BY u.name');
575
 
 
576
 
  //for each user, build a conflict detail section, and add their number of conflicts to the total
577
 
  while ($user = db_fetch_object($result)) {
578
 
    $conflicts = _signup_user_conflicts($user->uid);
579
 
    if (isset($conflicts)) {
580
 
      $sum .= $conflicts['title'] . $conflicts['data'];
581
 
      $total_conflicts += $conflicts['total'];
582
 
    } else {
583
 
      $sum .= t('<h4>%user, 0 schedule conflicts</h4>', array('%user' => l($user->name, "user/$user->uid")));
584
 
    }
585
 
  }
586
 
 
587
 
  //list the number of conflicts at the top of the page
588
 
  if (isset($total_conflicts)) {
589
 
    $output = t('<h2>%total total %conflict</h2>', array('%total' => $total_conflicts, '%conflict' => format_plural($total_conflicts, t('conflict'), t('conflicts')))) . $sum;
590
 
  } else {
591
 
    $output = t('<h2>No schedule conflicts</h2>');
592
 
  }
593
 
  print theme('page', $output);
594
 
}
595
 
 
596
 
/**
597
 
 * Callback function for generating a summary report of signup conflicts
598
 
 * @ingroup signup_callback
599
 
 */
600
 
function signup_conflict_summary() {
601
 
 
602
 
  //pull all users who have signed up for a node
603
 
  $result = db_query('SELECT DISTINCT u.uid, u.name FROM {users} u INNER JOIN {signup_log} s on u.uid = s.uid ORDER BY u.name');
604
 
 
605
 
  //for each user, build summary table row, and add their number of conflicts to the total
606
 
  while ($user = db_fetch_object($result)) {
607
 
    $conflicts = _signup_user_conflicts($user->uid);
608
 
    $user_total = (count($conflicts) ? $conflicts['total'] : 0);
609
 
    $rows[] = array(l($user->name, "user/$user->uid"), $user_total);
610
 
    $total_conflicts += $user_total;
611
 
  }
612
 
 
613
 
  //list the number of conflicts at the top of the page
614
 
  if ($total_conflicts > 0) {
615
 
    $header = array(t('user'), t('conflicts'));
616
 
    $output = t('<h2>%total total %conflict</h2>', array('%total' => $total_conflicts, '%conflict' => format_plural($total_conflicts, t('conflict'), t('conflicts'))));
617
 
    $output .= theme('table', $header, $rows);
618
 
  } else {
619
 
    $output = t('<h2>No schedule conflicts</h2>');
620
 
  }
621
 
  print theme('page', $output);
622
 
}
623
 
 
624
 
/**
625
551
 * Callback function for reopening signups
626
552
 * @ingroup signup_callback
627
553
 */
686
612
}
687
613
 
688
614
/**
 
615
 * Returns an array of node titles w/ links for all events the specified user has signed up for.
 
616
 */
 
617
function signup_list_user_signups($uid) {
 
618
 
 
619
  $titles = array();
 
620
 
 
621
  //tests for optional support of event.module
 
622
  $_EVENT = module_exist('event');
 
623
  $event_join = $_EVENT ? ' LEFT JOIN {event} e ON e.nid = n.nid' : '';
 
624
  $event_where = $_EVENT ? ' AND (e.event_start >= '. time() . ' OR e.event_start IS NULL)' : '';
 
625
  $order_by = $_EVENT ? 'e.event_start' : 'n.title';
 
626
 
 
627
  //pull all open signup nodes for this user
 
628
  $result = db_query("SELECT n.title, n.nid FROM {signup_log} s_l INNER JOIN {node} n ON n.nid = s_l.nid
 
629
    $event_join WHERE s_l.uid = '%s'$event_where ORDER BY $order_by", $uid);
 
630
 
 
631
  while ($node = db_fetch_array($result)) {
 
632
    $titles[$node['nid']] = l($node['title'], 'node/'. $node['nid']);
 
633
  }
 
634
  return $titles;
 
635
}
 
636
 
 
637
/**
689
638
 * Signs up a user to a node. NOTE: other modules can call this function. To do so, edit must be as follows:
690
639
 *
691
640
 * edit['nid'] : nid of the node to which the user will be signed up
794
743
  $user = user_load(array('uid' => arg(1)));
795
744
  drupal_set_title(t('Signups for %user', array('%user' => $user->name)));
796
745
 
797
 
  $titles = _signup_list_user_signups($user->uid);
 
746
  $titles = signup_list_user_signups($user->uid);
798
747
 
799
748
  // theme each signup
800
749
  foreach ($titles as $nid => $title) {
923
872
  return $form;
924
873
}
925
874
 
926
 
/**
927
 
 * Returns an array of conflict information for the specified uid
928
 
 * @ingroup signup_internal
929
 
 */
930
 
function _signup_get_conflicts($uid) {
931
 
 
932
 
  $conflicts = array();
933
 
  if (module_exist('event')) {
934
 
 
935
 
    //pull all signup nodes for the specified user
936
 
    $signups = db_query('SELECT n.nid, n.title, e.event_start AS start, e.event_end AS end FROM {signup_log} s INNER JOIN {node} n ON s.nid = n.nid INNER JOIN {event} e ON n.nid = e.nid WHERE s.uid = %d', $uid);
937
 
 
938
 
    //for each signup, pull all nodes that have a time conflict.  ignore duplicate conflicts
939
 
    while ($events = db_fetch_array($signups)) {
940
 
      $nid = $events['nid'];
941
 
      $title = $events['title'];
942
 
      $end = $events['end'];
943
 
      $start = $events['start'];
944
 
      $nodes[$nid][] = (integer) $nid;
945
 
      $skip = implode(', ', $nodes[$nid]);
946
 
      $conflicting = db_query('SELECT n.nid, n.title, e.event_start AS start, e.event_end AS end FROM {signup_log} s INNER JOIN {node} n ON s.nid = n.nid INNER JOIN {event} e ON n.nid = e.nid WHERE s.uid = %d AND ((event_start < %d AND event_start > %d) OR(event_end < %d AND event_end > %d) OR (event_end >= %d AND event_start <= %d)) AND n.nid NOT IN(%s)', $uid, $end, $start, $end, $start, $end, $start, $skip);
947
 
 
948
 
      //if there are conflicts, build a conflict array.  mark conflicts to prevent duplicates
949
 
      if (db_num_rows($conflicting)) {
950
 
        $conflicts[$nid][] = array('nid' => $nid, 'title' => $title, 'start' => $start, 'end' => $end);
951
 
        while ($conflict = db_fetch_array($conflicting)) {
952
 
          $conflicts[$nid][] = $conflict;
953
 
          $total_conflicts++;
954
 
          $nodes[$conflict['nid']][] = $nid;
955
 
        }
956
 
      }
957
 
    }
958
 
 
959
 
    if ($conflicts) {
960
 
      $conflicts['total'] = $total_conflicts;
961
 
    }
962
 
  }
963
 
  return $conflicts;
964
 
}
965
 
 
966
 
/**
967
 
 * Returns an array of node titles w/ links for all events the specified user has signed up for
968
 
 * @ingroup signup_internal
969
 
 */
970
 
function _signup_list_user_signups($uid) {
971
 
 
972
 
  $titles = array();
973
 
 
974
 
  //tests for optional support of event.module
975
 
  $_EVENT = module_exist('event');
976
 
  $event_join = $_EVENT ? ' LEFT JOIN {event} e ON e.nid = n.nid' : '';
977
 
  $event_where = $_EVENT ? ' AND (e.event_start >= '. time() . ' OR e.event_start IS NULL)' : '';
978
 
  $order_by = $_EVENT ? 'e.event_start' : 'n.title';
979
 
 
980
 
  //pull all open signup nodes for this user
981
 
  $result = db_query("SELECT n.title, n.nid FROM {signup_log} s_l INNER JOIN {node} n ON n.nid = s_l.nid
982
 
    $event_join WHERE s_l.uid = '%s'$event_where ORDER BY $order_by", $uid);
983
 
 
984
 
  while ($node = db_fetch_array($result)) {
985
 
    $titles[$node['nid']] = l($node['title'], 'node/'. $node['nid']);
986
 
  }
987
 
  return $titles;
988
 
}
989
 
 
990
 
/**
991
 
 * Returns a formatted list of conflict information for the specified user
992
 
 * @ingroup signup_internal
993
 
 */
994
 
function _signup_user_conflicts($uid) {
995
 
 
996
 
  $user = user_load(array('uid' => $uid));
997
 
  $conflicts = _signup_get_conflicts($uid);
998
 
 
999
 
  //if there are conflicts, pull the total from the array, and build a title section
1000
 
  if (count($conflicts)) {
1001
 
    $return['total'] = array_pop($conflicts);
1002
 
    $return['title'] = t('<h4>%user, %total schedule %conflict:</h4>', array('%total' => $return['total'], '%conflict' => format_plural($return['total'], t('conflict'), t('conflicts')), '%user' => l($user->name, "user/$user->uid")));
1003
 
 
1004
 
    $output = '';
1005
 
 
1006
 
    //pull the main event off the array, and then loop through and put all the conflicts to that event in an item list
1007
 
    foreach($conflicts as $nid) {
1008
 
      $list = array();
1009
 
      $node = array_shift($nid);
1010
 
      $output .= l(check_plain($node['title']), 'node/'. $node['nid']) .' '. t('conflicts with:');
1011
 
      foreach ($nid as $conflict) {
1012
 
        $list[] = l(check_plain($conflict['title']), 'node/'. $conflict['nid']);
1013
 
      }
1014
 
      $output .= theme('item_list', $list);
1015
 
    }
1016
 
    $return['data'] = $output;
1017
 
  }
1018
 
  return $return;
1019
 
}
1020
875
?>
 
 
b'\\ No newline at end of file'