Merge branch 'unstable' of https://github.com/jsmaniac/2011-m1s2-ter into unstable

This commit is contained in:
Yoann 2011-05-25 17:54:50 +02:00
commit f02b358af8
4 changed files with 62 additions and 27 deletions

View File

@ -128,8 +128,12 @@
</div> </div>
<div id="score" class="screen"> <div id="score" class="screen">
<h1 class="fitFont" style="width:100%; height:8%; top: 6%; position:absolute; margin:0; text-align:center;">Score total : <span class="scoreTotal"></span></h1> <h1 class="fitFont" style="width:100%; height:8%; top: 6%; position:absolute; margin:0; text-align:center;">Score total : <span class="scoreTotal"></span></h1>
<div class="scores fitFont" style="width:100%; height:62%; top:20%; position:absolute;"></div> <div class="scores fitFont" style="width:100%; height:50%; top:20%; position:absolute;"></div>
<p class="fitFont" style="text-align: center; width:90%; height:12%; top:86%; left:5%; position:absolute; margin:0; padding:0;"> <p class="fitFont" style="text-align: center; width:90%; height:12%; top:74%; left:5%; position:absolute; margin:0; padding:0;">
<a id="jaime" class="button" href="#frontpage" style="width40%; right:55%; position:absolute;">J'♥ cette partie</a>
<a id="jaimepas" class="button" href="#frontpage" style="width40%; left:55%; position:absolute;">J'♥ pas cette partie</a>
</p>
<p class="fitFont" style="clear:both; text-align: center; width:90%; height:12%; top:86%; left:5%; position:absolute; margin:0; padding:0;">
<a class="button" href="#frontpage">J'ai vu !</a> <a class="button" href="#frontpage">J'ai vu !</a>
</p> </p>
</div> </div>

View File

@ -32,6 +32,8 @@ require_once("ressources/db.inc");
* userPrefsDefaults(); * userPrefsDefaults();
* userPrefs($user); * userPrefs($user);
* setUserPref($user, $key, $value); * setUserPref($user, $key, $value);
* getJAimePgid($user, $pgid);
* setJAimePgid($user, $pgid, $value);
*/ */
@ -711,4 +713,16 @@ function setUserPref($user, $key, $value) {
} }
} }
function getJAimePgid($user, $pgid) {
getDB()->querySingle("SELECT like FROM played_game WHERE login = '".SQLite3::escapeString($user)."' and pgid = ".longStrVal($pgid).";");
}
function setJAimePgid($user, $pgid, $value) {
$value = intval($value) / abs(intval($value) || 1); // Calcule le signe de $value : -1 ou 0 ou 1
$original = getJAimePgid($user, $pgid);
getDB()->querySingle("UPDATE played_game SET like = ".$value." WHERE login = '".SQLite3::escapeString($user)."' and pgid = ".longStrVal($pgid).";");
getDB()->querySingle("UPDATE game SET nb_like = nb_like".($original == 1 ? " - 1" : "").($value == 1 ? " + 1" : "")." WHERE login = '".SQLite3::escapeString($user)."' and pgid = ".longStrVal($pgid).";");
getDB()->querySingle("UPDATE game SET nb_dislike = nb_dislike".($original == -1 ? " - 1" : "").($value == -1 ? " + 1" : "")." WHERE login = '".SQLite3::escapeString($user)."' and pgid = ".longStrVal($pgid).";");
}
?> ?>

View File

@ -4,6 +4,7 @@ function init(fn) {
} }
$.ajaj = function(url, data, dfd, retryCheck, callback) { $.ajaj = function(url, data, dfd, retryCheck, callback) {
dfd = dfd || $.Deferred();
var user = '' + UI().getPreference("user"); var user = '' + UI().getPreference("user");
var passwd = '' + UI().getPreference("passwd"); var passwd = '' + UI().getPreference("passwd");
user = runstate.user || user; user = runstate.user || user;
@ -312,6 +313,7 @@ init(function() {
if (updating) return false; if (updating) return false;
updating = true; updating = true;
if (!runstate.game || state.pgid != runstate.game.pgid) { if (!runstate.game || state.pgid != runstate.game.pgid) {
updating = false;
$('#game').trigger('goto'); $('#game').trigger('goto');
return; return;
} }
@ -363,6 +365,14 @@ runstate.scoreCache = new Cache(function getScore(k, dfd, arg) {
}, dfd, function() { return state.pgid == k; }); }, dfd, function() { return state.pgid == k; });
}); });
function jAime(aime) {
$.ajaj('server.php?callback=?', {
pgid: state.pgid,
action: 10,
value: (aime ? 1 : -1)
});
}
init(function() { init(function() {
var score = $.screen('score'); var score = $.screen('score');
score.bind('pre-enter', function() { score.bind('pre-enter', function() {
@ -386,6 +396,8 @@ init(function() {
.appendTo("#score .scores"); .appendTo("#score .scores");
}); });
}); });
$('#jaime').click(function() { jAime(true); });
$('#jaimepas').click(function() { jAime(false); });
}); });
// ==== Écran Préférences // ==== Écran Préférences

View File

@ -114,6 +114,11 @@ function main()
} elseif ($action == 9) { } elseif ($action == 9) {
session_destroy(); session_destroy();
echo '{"disconnected":true}'; echo '{"disconnected":true}';
} elseif ($action == 10) { // Set J'aime / J'aime pas
if (!isset($_GET['value']) || !isset($_GET['pgid']))
throw new Exception("La requête est incomplète", 2);
setJAimePgid($user, $_GET['pgid'], intval($_GET['value']));
echo '{"JAimePas":true}';
} else { } else {
throw new Exception("Commande inconnue", 2); throw new Exception("Commande inconnue", 2);
} }