From 80c7c7ab95312a913267bdfcb6c643d93fd8b7fb Mon Sep 17 00:00:00 2001 From: Yoann Date: Thu, 21 Apr 2011 11:30:29 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20de=20la=20liaison=20de=20la=20nouv?= =?UTF-8?q?elle=20page=20de=20cr=C3=A9ation=20de=20partie=20avec=20le=20se?= =?UTF-8?q?rveur.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/serveur/php/createGame.php | 4 ++ code/serveur/php/pticlic.php | 65 ++++++++++++++++++++++- code/serveur/php/ressources/createGame.js | 14 +++-- code/serveur/php/server.php | 8 +++ 4 files changed, 86 insertions(+), 5 deletions(-) diff --git a/code/serveur/php/createGame.php b/code/serveur/php/createGame.php index 1cfdf8a..627c62c 100644 --- a/code/serveur/php/createGame.php +++ b/code/serveur/php/createGame.php @@ -49,6 +49,10 @@ if(!isset($_SESSION['userId'])) .wordLinesTable .lightLine { background-color : #F0F0D0; } + + .wordLinesTable td:first-child { + text-align : right; + } #center { diff --git a/code/serveur/php/pticlic.php b/code/serveur/php/pticlic.php index 86bfbe8..e595b53 100644 --- a/code/serveur/php/pticlic.php +++ b/code/serveur/php/pticlic.php @@ -25,7 +25,7 @@ require_once("db.php"); * normalizeProbas($row); * setGame($user, $pgid, $gid, $answers); * get_game_relations(); - getGameRelationsJSON(); +* getGameRelationsJSON(); * setGameGetScore($user, $pgid, $gid, $answers); * insertNode($node); * getNodeEid($node); @@ -297,6 +297,69 @@ function cgInsert($centerEid, $cloud, $r1, $r2, $totalDifficulty) $db->exec("commit;"); } +function decodeGame($json) { + $game = JSON_decode($json,true); + + $centerEid = getNodeEid($game['centralWord']); + foreach($game['cloud'] as $w) + $cloud[] = Array("eid" => getNodeEid($w['name']), + "pos" => $key, + "d" => 5, + "probaR1" => $w['relations'][0] ? "1" : "0", + "probaR2" => $w['relations'][0] ? "1" : "0", + "probaR0" => $w['relations'][0] ? "1" : "0", + "probaTrash" => $w['relations'][0] ? "1" : "0"); + + + print_r($cloud); +} + +function insertCreatedGame($centerEid, $cloud, $r1, $r2, $totalDifficulty) +{ + $db = getDB(); + // Insère dans la base une partie avec le mot central $centerEid, le nuage $cloud et les relations $r1 et $r2 + $db->exec("begin transaction;"); + $db->exec("INSERT INTO game(gid, eid_central_word, relation_1, relation_2, difficulty) + VALUES (null, $centerEid, $r1, $r2, $totalDifficulty);"); + $gid = $db->lastInsertRowID(); + + $t = time(); + $db->exec("INSERT INTO played_game(pgid, gid, login, timestamp) + VALUES (null, $gid, null, $t);"); + $pgid1 = $db->lastInsertRowID(); + $db->exec("INSERT INTO played_game(pgid, gid, login, timestamp) + VALUES (null, $gid, null, $t);"); + $pgid2 = $db->lastInsertRowID(); + $db->exec("INSERT INTO played_game(pgid, gid, login, timestamp) + VALUES (null, $gid, null, $t);"); + $pgid0 = $db->lastInsertRowID(); + $db->exec("INSERT INTO played_game(pgid, gid, login, timestamp) + VALUES (null, $gid, null, $t);"); + $pgidT = $db->lastInsertRowID(); + + // TODO : R0 et Trash + corrections + foreach ($cloud as $c) + { + $totalWeight = $c['probaR1'] + $c['probaR2'] + $c['probaR0'] + $c['probaTrash']; + $db->exec("INSERT INTO game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash) + VALUES ($gid, ".$c['pos'].", ".$c['d'].", ".$c['eid'].", $totalWeight, ".$c['probaR1'].", ".$c['probaR2'].", ".$c['probaR0'].", ".$c['probaTrash'].");"); + + $db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score) + VALUES ($pgid1, $gid, 0, ".$c['pos'].", $r1, ".$c['probaR1'].", 0);"); + + $db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score) + VALUES ($pgid2, $gid, 0, ".$c['pos'].", $r2, ".$c['probaR2'].", 0);"); + + $db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score) + VALUES ($pgid0, $gid, 0, ".$c['pos'].", 0, ".$c['probaR0'].", 0);"); + + $db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score) + VALUES ($pgidT, $gid, 0, ".$c['pos'].", -1, ".$c['probaTrash'].", 0);"); + } + + $db->exec("commit;"); +} + /** Retourne un identifiant de partie aléatoire de la liste de parties jouables * @return gid : Identifiant de partie. */ diff --git a/code/serveur/php/ressources/createGame.js b/code/serveur/php/ressources/createGame.js index 5be3ddb..aca1e9b 100644 --- a/code/serveur/php/ressources/createGame.js +++ b/code/serveur/php/ressources/createGame.js @@ -153,12 +153,18 @@ $(function() { cloud:[]}; for(i=1;i