commit c8f179794a75526510b1d3b2a71905dffd5e2fe1
parent 69a33313155c8f3a536291144ea03ea06a867cfb
Author: Yoann Bonavero <yoann.b87@voila.fr>
Date: Wed, 16 Mar 2011 22:08:37 +0100
Continuation de la page de création de partie celle-ci ne fonctionne
pas encore mais ça ne devrait plus trop tarder.
Ajout de la fonctions d'insertions dans la base de données (pas testée).
Diffstat:
2 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/code/serveur/php/createGame.php b/code/serveur/php/createGame.php
@@ -1,5 +1,6 @@
<?php
require_once("ressources/strings.inc");
+require_once("relations.php");
require_once("pticlic.php");
session_start();
@@ -55,6 +56,10 @@ function checked($name, $value) {
return 'checked';
}
+function probaOf($relation, $relation2) {
+ return 0;
+}
+
if(isset($_POST['nbcloudwords'])) {
$nbwords = $_POST['nbcloudwords'];
@@ -88,11 +93,29 @@ if(isset($_POST['nbcloudwords'])) {
if($state == 2) {
$respwords = getWordsAndResponses($nbwords);
+ $r1 = $stringRelations[$_POST['relation1']];
+ $r2 = $stringRelations[$_POST['relation2']];
+ $cloud = array();
+ $totalDifficulty = 0;
- if($respwords != -1) {
+ insertNode($centralword);
+ $centralword = getNodeEid($centralword);
+ if($respwords != -1) {
+ foreach($respwords as $key=>$rw) {
+ insertNode($respwords[$key][0]);
+ $cloud[$key] = array('pos'=>$key, 'd'=>1, 'eid'=>getNodeEid($respwords[$key][0]),
+ 'probaR1'=> probaOf("r1", $rw[1]),
+ 'probaR2'=> probaOf('r2', $rw[1]),
+ 'probaR0'=> probaOf('r0', $rw[1]),
+ 'probaTrash'=> probaOf('trash', $rw[1]));
+
+ $totalDifficulty += 1;
+ }
}
+ cgInsert($centralword, $cloud, $r1, $r2, $totalDifficulty);
+
}
else {
$err = true;
@@ -143,12 +166,12 @@ else
echo '<tr><td><label for="relation1">Relation 1 : </label></td>';
echo '<td class="inputcell"><select name="relation1">';
foreach($relations as $key=>$r)
- echo '<option value="'.$key.'">'.$r[1].'</option>';
+ echo '<option value="'.$key.'">'.$stringRelations[$r].'</option>';
echo '</select></td>';
echo '<td><label for="relation2">Relation 2 : </label></td>';
echo '<td class="inputcell"><select name="relation2">';
foreach($relations as $key=>$r)
- echo '<option value="'.$key.'">'.$r[1].'</option>';
+ echo '<option value="'.$key.'">'.$stringRelations[$r].'</option>';
echo '</select></td>';
echo '<input type="hidden" name="nbcloudwords" value="'.$nbwords.'" />';
echo '<tr><td colspan="2"><br /><label for="centralword">Mot central : </label><br /><br /></td>';
diff --git a/code/serveur/php/pticlic.php b/code/serveur/php/pticlic.php
@@ -24,6 +24,8 @@ require_once("db.php");
* normalizeProbas($row);
* setGame($user, $pgid, $gid, $answers);
* get_game_relations();
+* insertNode($node);
+* getNodeEid($node);
*/
@@ -584,17 +586,40 @@ function setGame($user, $pgid, $gid, $answers)
function get_game_relations()
{
$reqlations = array();
- $db = getDB();
- // TODO modifier la requête pour ne sélectionner que les relations pertinentes.
- $res = $db->query("SELECT num,extended_name
- FROM type_relation
- WHERE num=5 OR num=7 OR num=9
- OR num=10 OR num=13 OR num=14 OR num=22");
-
- while($r = $res->fetchArray())
- $relations[] = $r;
+ $relations[] = 5;
+ $relations[] = 7;
+ $relations[] = 9;
+ $relations[] = 10;
+ $relations[] = 14;
+ $relations[] = 22;
return $relations;
}
+
+
+/** Insère dans la base de données le noeud si il n'existe pas encore.
+* @param node : le noeud à ajouter.
+*/
+function insertNode($node) {
+ $db = getDB();
+
+ if($db->querySingle("SELECT eid FROM node WHERE name=".$node) != null) {
+ $db->exec("INSERT INTO node(name,type,weight) VALUES($node,1,50);");
+ return true;
+ }
+
+ return false;
+}
+
+
+/** retourne l'eid d'un mot.
+* @param node : le mot dont on veut obtenir l'eid.
+*/
+
+function getNodeEid($node) {
+ $db = getDB();
+
+ //return $db->querySingle("SELECT eid FROM node WHERE name='".SQLite3::escapeString($node)."';");
+}
?>