From 7f17a1954f153ecdfecd524d3f7c921b3b0bd08a Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Fri, 2 Nov 2007 11:23:45 +0100 Subject: NEW FEATURE: count game points, partly done ;) a table will be shown now for score keeping. fox, karlchen and dokos are accounted for normal win, calling something and winning should be accounted for still missing: both parties call or one party calls and doesn't acchieve it's goal --- db.php | 209 ++++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 137 insertions(+), 72 deletions(-) (limited to 'db.php') diff --git a/db.php b/db.php index 4afa9e1..db1910f 100644 --- a/db.php +++ b/db.php @@ -1,7 +1,7 @@ '$hash'"); - + $r = mysql_fetch_array($queryresult,MYSQL_NUM); if($r) return $r[0]; @@ -905,14 +918,14 @@ function DB_get_partner_hash_by_hash($hash) function DB_format_gameid($gameid) { $session = DB_get_session_by_gameid($gameid); - + /* get number of game */ $result = mysql_query("SELECT COUNT(*),create_date FROM Game". " WHERE session='$session' ". " AND TIMEDIFF(create_date, (SELECT create_date FROM Game WHERE id='$gameid'))<=0 ". " GROUP by session"); $r = mysql_fetch_array($result,MYSQL_NUM); - + return $session.".".$r[0]; } @@ -923,7 +936,7 @@ function DB_get_reminder($user,$gameid) " AND game_id=$gameid ". " AND DATE_SUB(CURDATE(),INTERVAL 1 DAY) <= create_date". " GROUP BY user_id " ); - + $r = mysql_fetch_array($queryresult,MYSQL_NUM); if($r) return $r[0]; @@ -952,4 +965,56 @@ function DB_is_session_active($session) return -1; } +function DB_get_score_by_gameid($gameid) +{ + /* returns the points of a game from the point of the re parth (<0 if they lost) */ + $queryresult = mysql_query("SELECT COUNT(*),party FROM Score ". + " WHERE game_id=$gameid ". + " GROUP BY party "); + + $re = 0; + $contra = 0; + + while($r = mysql_fetch_array($queryresult,MYSQL_NUM) ) + { + if($r[1] == "re") + $re += $r[0]; + else if ($r[1] == "contra") + $contra += $r[0]; + }; + + return ($re - $contra); +} + +function DB_get_gameids_of_finished_games_by_session($session) +{ + $ids = array (); + + $queryresult = mysql_query("SELECT id FROM Game ". + " WHERE session=$session ". + " AND status='gameover' ". + " ORDER BY create_date ASC"); + + $i=0; + while($r = mysql_fetch_array($queryresult,MYSQL_NUM) ) + { + $ids[$i] = $r[0]; + $i++; + } + + return $ids; +} + +function DB_get_card_value_by_cardid($id) +{ + $queryresult = mysql_query("SELECT points FROM Card ". + " WHERE id=$id "); + + $r = mysql_fetch_array($queryresult,MYSQL_NUM); + if($r) + return $r[0]; + else + return NULL; +} + ?> \ No newline at end of file -- cgit v1.2.3-18-g5258