Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 2.18 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How do i distribute round robin times equally?
  2. <?php
  3.  
  4.     $teams = array('Team 1','Team 2','Team 3','Team 4','Team 5','Team 6');
  5.  
  6.     $season = 1;
  7.     $league = 'Mens';
  8.     $date = '2012-02-01';
  9.     $times =  array('19:00','20:00','21:00');
  10.  
  11.     $date_bits = explode('-',$date);
  12.     $start_day = mktime(0, 0, 0, $date_bits[1], $date_bits[2], $date_bits[0]);          
  13.  
  14.     $weeks = 12;
  15.  
  16.     $count = count($teams);
  17.     $times = array_slice($times,0,floor($count/2));
  18.     $times_count = count($times);
  19.     $start = 1;
  20.  
  21.     if($count%2!=0)
  22.     {
  23.         $teams[] = 'Bye';
  24.         $count++;
  25.     }
  26.  
  27.     $date_i = 0;
  28.     for($i=0;$i<$weeks;$i++)
  29.     {
  30.         $keyA = $start;
  31.         $keyB = $keyA-1; if($keyB<1)$keyB = $count-1;
  32.         $tA = array();
  33.         $tB = array();
  34.         for($k=0;$k<$count-1;$k++)
  35.         {
  36.             $tA[] = $teams[$keyA];
  37.             $tB[] = $teams[$keyB];
  38.             $keyA++; if($keyA>$count-1) $keyA = 1;
  39.             $keyB--; if($keyB<1) $keyB = $count-1;
  40.         }
  41.         array_unshift($tA,$teams[0]);
  42.         $tB[] = $teams[0];          
  43.  
  44.         $inc = 0; // time increment
  45.         for($k=0;$k<$count;$k++)
  46.         {
  47.             if($tA[$k]=='Bye'||$tB[$k]=='Bye') continue;
  48.  
  49.             $col = array();
  50.             $col['season'] = $season; //season
  51.             $col['league'] = $league; //league
  52.             $col['round'] = 'Round '.($i+1); //round
  53.             $col['date'] = date('Y-m-d',strtotime("+{$i} week",$start_day)); //date
  54.             $col['time'] = $times[$inc]; //time
  55.             $col['teamA'] = $tA[$k]; //result_teamA
  56.             $col['teamA_result'] = 0; //result_teamA
  57.             $col['teamB'] = $tB[$k]; //result_teamB
  58.             $col['teamB_result'] = 0;
  59.             $data['results'][] = $col;
  60.  
  61.             $inc++;
  62.             if($inc==$times_count) break;
  63.         }
  64.  
  65.         $start--; if($start<1) $start = $count-1;
  66.  
  67.         // shift allocated times
  68.         $first = $times[0];
  69.         $times = array_slice($times,1,count($times));
  70.         array_push($times,$first);
  71.  
  72.     }
  73.     echo '<table border="1">';
  74.     foreach($data['results'] as $result)
  75.     {
  76.         echo '<tr><td>'.implode('</td><td>',array_values($result)).'</td></tr>';
  77.     }
  78.     echo '</table>';
  79.  
  80. ?>