Changeset 2914

Show
Ignore:
Timestamp:
02/04/12 09:05:44 (3 months ago)
Author:
paparazzia
Message:

see #244 (quick and dirty display for groups)

Location:
trunk/lib/phpcommon
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/phpcommon/functions.php

    r2883 r2914  
    826826} 
    827827 
     828 
    828829function getNumOpponents($idraces, $check = TRUE) { 
    829830  //force type int 
     
    857858  //              arrivés     en course       inscrits (arr + out + en course) 
    858859  return (array ($num_arrived,$num_racing,$num_arrived + $num_out + $num_racing)); 
     860} 
     861 
     862function getRacesGroupsBatch($racelist) { 
     863  $ret = Array(); 
     864  $in = "races.idraces IN ("; 
     865  $first = TRUE; 
     866  foreach ($racelist as $idr) { 
     867    if ($first) { 
     868      $first = FALSE; 
     869      $in.=$idr; 
     870    } else { 
     871      $in.=",".$idr; 
     872    } 
     873  } 
     874  $in.=")"; 
     875 
     876  $query = "SELECT races.`idraces`, group_concat(grouptag) AS grouptaglist ". 
     877           "FROM races LEFT JOIN racestogroups ON (races.idraces = racestogroups.idraces) WHERE ".$in." ". 
     878           "GROUP BY races.idraces"; 
     879  $result = wrapper_mysql_db_query_reader($query) or die($query); 
     880  while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
     881    $ret[$row['idraces']] = $row; 
     882  } 
     883  return $ret; 
    859884} 
    860885 
     
    9811006      $html .= htmlTinymap($rowdatas['idraces'], $rowdatas['racename']); 
    9821007      $html .= "</td>\n"; 
     1008      $html .= " <td class=\"grouptaglist\">"; 
     1009      foreach (split(',', $rowdatas['grouptaglist']) as $g) { 
     1010          $html .= htmlRacesGroupLink($g); 
     1011          $html .= " "; 
     1012      } 
     1013      $html .= "</td>\n"; 
    9831014      $html .= " </tr>\n"; 
    9841015      return $html; 
     
    9891020} 
    9901021 
    991 function dispHtmlRacesList($where = "") { 
    992  
    993   echo "<table>\n"; 
    994   echo "<thead>\n"; 
    995   echo "    <tr>\n"; 
    996   echo "    <th>".getLocalizedString("raceid")."</th>\n"; 
    997   echo "    <th>".getLocalizedString("racename")."</th>\n"; 
    998   echo "    <th>".getLocalizedString("departuredate")." (GMT)</th>\n"; 
    999   echo "    <th>". join('<br />', explode("/", getLocalizedString("racenumboats")))."</th>\n"; 
    1000   echo "    <th>".getLocalizedString("map")."</th>\n"; 
    1001   echo "    </tr>\n"; 
    1002   echo "   </thead>\n"; 
    1003   echo "  <tbody>\n"; 
    1004 //  echo "<tr><td></td><td></td><td></td><td></td></tr>"; 
    1005  
    1006  
    1007   // La requete qui donne la liste des courses en cours 
    1008   $query= "SELECT idraces, racename, started, deptime, startlong, startlat, ". 
    1009     "boattype, closetime, racetype, if(started=".RACE_ENDED.", 0, deptime) ". 
    1010     "AS deptimesort FROM races $where ORDER by started DESC, deptimesort ASC, ". 
    1011     "closetime DESC, idraces DESC"; 
    1012  
    1013   $result = wrapper_mysql_db_query_reader($query) or die($query); 
    1014  
    1015   if (mysql_num_rows($result)) { 
    1016       $allRacesRows = array(); 
    1017       $allRacesIds  = array(); 
    1018       while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
    1019         array_push($allRacesRows, $row); 
    1020         array_push($allRacesIds, $row['idraces']);       
    1021       } 
    1022       $allNumOpponents = getNumOpponentBatch($allRacesIds); 
    1023  
    1024       foreach($allRacesRows as $row) { 
    1025         $row['num_opps'] = $allNumOpponents[$row['idraces']]; 
    1026         echo htmlRacesListRow($row); 
    1027       } 
     1022function dispHtmlRacesList($where = "", $limit = 100) { 
     1023 
     1024    // La requete qui donne la liste des courses en cours 
     1025    $query= "SELECT races.idraces, racename, started, deptime, startlong, startlat, ". 
     1026      "boattype, closetime, racetype, if(started=".RACE_ENDED.", 0, deptime) ". 
     1027      "AS deptimesort, group_concat(grouptag) AS grouptaglist ". 
     1028      "FROM races LEFT JOIN racestogroups ON (races.idraces = racestogroups.idraces) $where ". 
     1029      "GROUP BY races.idraces ORDER by started DESC, deptimesort ASC, closetime DESC, idraces DESC ". 
     1030      "LIMIT $limit"; 
     1031 
     1032    $result = wrapper_mysql_db_query_reader($query) or die($query); 
     1033 
     1034    if (mysql_num_rows($result)) { 
     1035        $allRacesRows = array(); 
     1036        while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
     1037            $allRacesRows[$row['idraces']] = $row; 
     1038        } 
     1039        echo htmlRacesList($allRacesRows); 
     1040    } 
     1041} 
     1042 
     1043function htmlRacesList($raceslist) { 
     1044  $html = ""; 
     1045      $html .= "<table>\n"; 
     1046  $html .= "<thead>\n"; 
     1047  $html .= "    <tr>\n"; 
     1048  $html .= "    <th>".getLocalizedString("raceid")."</th>\n"; 
     1049  $html .= "    <th>".getLocalizedString("racename")."</th>\n"; 
     1050  $html .= "    <th>".getLocalizedString("departuredate")." (GMT)</th>\n"; 
     1051  $html .= "    <th>". join('<br />', explode("/", getLocalizedString("racenumboats")))."</th>\n"; 
     1052  $html .= "    <th>".getLocalizedString("map")."</th>\n"; 
     1053  $html .= "    <th>".getLocalizedString("Group(s)")."</th>\n"; 
     1054  $html .= "    </tr>\n"; 
     1055  $html .= "   </thead>\n"; 
     1056  $html .= "  <tbody>\n"; 
     1057 
     1058  $allNumOpponents = getNumOpponentBatch(array_keys($raceslist)); 
     1059  $allRacesGroups = getRacesGroupsBatch(array_keys($raceslist)); 
     1060  
     1061  foreach ($raceslist as $idraces => $row) { 
     1062      $row['num_opps'] = $allNumOpponents[$row['idraces']]; 
     1063      $row['grouptaglist'] = $allRacesGroups[$row['idraces']]['grouptaglist']; 
     1064      $html .= htmlRacesListRow($row); 
    10281065  }   
    10291066 
    1030   echo "</tbody>\n"; 
    1031   echo "</table>\n  "; 
     1067  $html .= "</tbody>\n"; 
     1068  $html .= "</table>\n  "; 
     1069 
     1070  return $html; 
     1071} 
     1072 
     1073function htmlRacesGroupLink($grouptag) { 
     1074    if (is_null($grouptag) || $grouptag == "") return ""; 
     1075    return "<a href=\"/racesgroups.php?grouptag=$grouptag\">!$grouptag</a>"; 
    10321076} 
    10331077 
     
    14651509} 
    14661510 
     1511function getFullUserObject($id, $initrow = NULL) { 
     1512    if (!is_null($uo = getUserObject($id, $initrow))) { 
     1513        return new fullUsers($id, $uo); 
     1514    } else { 
     1515        return null; 
     1516    } 
     1517} 
     1518 
    14671519function getUserObject($id, $initrow = NULL) { 
    14681520  static $uobjects = Array(); 
     
    15691621} 
    15701622 
    1571 function setUserPref($idusers,$pref_name,$pref_value, $save=true) { 
     1623function setUserPref($idusers, $pref_name, $pref_value, $save=true) { 
    15721624    //FIXME : this is duplicated in users.class 
    15731625    if ($idusers != "" and $save) { 
     
    15831635 
    15841636function getUserPref($idusers,$pref_name) { 
    1585  
    15861637    if ($idusers != "") { 
    15871638        $query_pref = "SELECT `pref_value` FROM `user_prefs` WHERE `idusers` = $idusers AND `pref_name` = '$pref_name'"; 
     
    15941645 
    15951646        return ($pref_value); 
    1596     } 
    1597 } 
    1598  
    1599 function listUserPref($idusers, $prefix = null) { 
    1600     if ($idusers != "") { 
    1601         $prefs=array(); 
    1602         $query_pref = "SELECT `pref_name`, `pref_value` FROM `user_prefs` WHERE `idusers` = $idusers"; 
    1603         if (!is_null($prefix)) $query_pref .= " AND `pref_name` LIKE '".$prefix."%'"; 
    1604         $query_pref .= " ORDER BY `pref_name`"; 
    1605         $result_pref = wrapper_mysql_db_query_reader($query_pref) or die($query_pref); 
    1606         while ( $row = mysql_fetch_array($result_pref, MYSQL_ASSOC) ) { 
    1607             $prefs[$row["pref_name"]]=$row["pref_value"]; 
    1608         } 
    1609         return($prefs); 
    16101647    } 
    16111648} 
  • trunk/lib/phpcommon/users.class.php

    r2876 r2914  
    652652    } 
    653653  } 
    654    
    655   function getMyPref($pref_name) { 
     654 
     655  function feedPrefs() { 
    656656      if (!isset($this->preferences)) { 
    657657          $query_pref = "SELECT pref_name, pref_value FROM user_prefs". 
     
    669669          $this->preferences['boatname'] = $this->users->boatname; 
    670670      } 
     671  } 
     672   
     673  function getMyPref($pref_name) { 
     674      $this->feedPrefs(); 
    671675      if (array_key_exists($pref_name, $this->preferences)) { 
    672676        return $this->preferences[$pref_name];