Changeset 120


Ignore:
Timestamp:
13/10/07 02:59:34 (5 years ago)
Author:
nigel.sim
Message:
  • Updated schema
  • Code comments
  • Make it possible to use multiple entries per period
Location:
roster/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roster/trunk/roster.install

    r115 r120  
    1414      PRIMARY KEY (bid))"); 
    1515 
    16     db_query("CREATE TABLE {roster_assignment} ( 
    17       bid int unsigned NOT NULL default '0', 
    18       person int unsigned NOT NULL default '0', 
    19       period int unsigned NOT NULL default '0', 
    20       notes text, 
    21       PRIMARY KEY (bid, person, period))"); 
     16    db_query("CREATE TABLE IF NOT EXISTS {roster_assignment} ( 
     17      `aid` int(11) NOT NULL auto_increment, 
     18      `bid` int(10) unsigned NOT NULL default '0', 
     19      `person` int(10) unsigned NOT NULL default '0', 
     20      `period` int(10) unsigned NOT NULL default '0', 
     21      `notes` text, 
     22      PRIMARY KEY  (`aid`) 
     23      )"); 
    2224 
    2325    break; 
  • roster/trunk/roster.module

    r119 r120  
    6767} 
    6868 
     69/** 
     70 * Rewrite the form callbacks so that roster_assignment_form* 
     71 * use the roster_assignment_form method 
     72 */ 
    6973function roster_forms() { 
    70  
    7174  # get the form id 
    7275  $args = func_get_args(); 
     
    8487} 
    8588 
     89/** 
     90 * Get the booth information 
     91 */ 
    8692function roster_get_booth($bid){ 
    8793  $results = db_query("SELECT bid, name, last_votes, last_votes_total FROM {roster_booths} WHERE bid = %d", $bid); 
     
    8995} 
    9096 
     97/** 
     98 * Get all the booths for an election 
     99 */ 
    91100function roster_get_booths($nid){ 
    92101  $res = array(); 
     
    99108} 
    100109 
     110/** 
     111 * Get the roster for an election, and use the booth_id then period as the key 
     112 */ 
    101113function roster_get_roster($nid){ 
    102114  $res = array(); 
     
    108120    else 
    109121      $booth = array(); 
    110     $booth[$row->period] = $row; 
     122    if ($booth[$row->period] == NULL) 
     123      $booth[$row->period] = array($row); 
     124    else 
     125      $booth[$row->period][] = $row; 
    111126    $res[$row->bid] = $booth; 
    112127  } 
     
    114129} 
    115130 
     131/** 
     132 * Intercept load and save calls so we can use the body to store the extra details 
     133 */ 
    116134function roster_nodeapi(&$node, $op){ 
    117135  switch($op){ 
     
    216234    '#weight' => 1, 
    217235  ); 
     236 
     237  // Get roster data 
    218238  $booths = roster_get_booths($node->nid); 
    219239  $roster = roster_get_roster($node->nid); 
     
    224244  } 
    225245   
     246  // Init unique form ID 
    226247  $rosterFormId = 0; 
    227248 
     249  // Format roster table for display 
    228250  $table = "<table><tr><th>Booth</th><th>Morning</th><th>Afternoon</th></tr>"; 
    229251  foreach ($booths as $booth){ 
    230252    $table .= "<tr><td>".l($booth->name,'node/'.arg(1).'/booth/'.$booth->bid)."</td>"; 
    231     $person = ($roster[$booth->bid] != NULL)?$roster[$booth->bid][0]:NULL; 
    232     $table .= "<td>".drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, $person, $booth->bid, 0)."</td>"; 
    233     $person = ($roster[$booth->bid] != NULL)?$roster[$booth->bid][1]:NULL; 
    234     $table .= "<td>".drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, $person, $booth->bid, 1)."</td>"; 
     253    $people = ($roster[$booth->bid] != NULL)?$roster[$booth->bid][0]:NULL; 
     254    $table .= "<td>"; 
     255    foreach ($people as $person) 
     256      drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, $person, $booth->bid, 0); 
     257    // A new one too 
     258    drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, NULL, $booth->bid, 0); 
     259    $table .= "</td>"; 
     260    $people = ($roster[$booth->bid] != NULL)?$roster[$booth->bid][1]:NULL; 
     261    $table .= "<td>"; 
     262    foreach ($people as $person) 
     263      drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, $person, $booth->bid, 1) 
     264    // A new one too 
     265    drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, NULL, $booth->bid, 1) 
     266    $table .= "</td>"; 
    235267    $table .= "</tr>"; 
    236268  } 
     
    241273  ); 
    242274 
     275  // Set body to null to hide on the view 
    243276  $node->content['body'] = NULL; 
    244277  return $node; 
     
    268301} 
    269302 
     303/** 
     304 * Get the CiviCRM group members by group id 
     305 */ 
    270306function roster_get_group_members($group_id) { 
    271307 // Check if CiviCRM is installed here. 
     
    278314 $groups =& crm_get_groups(array('id' => $group_id)); 
    279315 
    280  // Pass 'group' => group.id into search API to find members of that group 
    281  // Only one group with that title, so we can reference 
    282  // first object in returned array from get_groups. 
    283316 $params = array('group' => array($groups[0]->id => 1)); 
    284317 
     
    294327} 
    295328 
     329/** 
     330 * Get a list of the CiviCRM groups 
     331 */ 
    296332function roster_get_groups() { 
    297333 // Check if CiviCRM is installed here. 
Note: See TracChangeset for help on using the changeset viewer.