|
@@ -14,6 +14,7 @@ use ChamiloSession as Session;
|
|
|
*/
|
|
|
require_once __DIR__.'/../../main/inc/global.inc.php';
|
|
|
|
|
|
+// This plugin doesn't work for anonymous users
|
|
|
if (!api_is_anonymous()) {
|
|
|
require_once 'card_game.php';
|
|
|
$cardGame = CardGame::create();
|
|
@@ -33,22 +34,28 @@ if (!api_is_anonymous()) {
|
|
|
|
|
|
$fh .= '<div id="linkcardgame" style="display:none;" >'.$pluginPath.'ajax.card.php</div>';
|
|
|
|
|
|
- $user = api_get_user_info();
|
|
|
- $userId = (int) $user['id'];
|
|
|
+ $userId = api_get_user_id();
|
|
|
|
|
|
+ // Look if the user can still try playing today
|
|
|
$cardGameSession = Session::read('cardgame');
|
|
|
if (!empty($cardGameSession)) {
|
|
|
+ // If we've already loaded the cardgame in this session, then there's
|
|
|
+ // a chance we've already played
|
|
|
if (isset($userId)) {
|
|
|
$sqlCount = "SELECT access_date FROM plugin_card_game WHERE user_id = $userId";
|
|
|
$resultCount = Database::query($sqlCount)->rowCount();
|
|
|
|
|
|
if ($resultCount === 0) {
|
|
|
+ // If there is no database entry for this user, insert one
|
|
|
+ // without the 'parts' field (because he has not played yet)
|
|
|
// @todo change date call
|
|
|
$sql = "INSERT INTO plugin_card_game (user_id, access_date, pan)
|
|
|
VALUES ($userId, DATE_ADD(CURDATE(), INTERVAL -1 DAY), 1);";
|
|
|
$resultInsert = Database::query($sql);
|
|
|
Session::write('cardgame', 'havedeck');
|
|
|
} else {
|
|
|
+ // If there is already one or more records in the database,
|
|
|
+ // get the number of records for today
|
|
|
// @todo change date call
|
|
|
$sqlDate = "SELECT access_date
|
|
|
FROM plugin_card_game
|
|
@@ -57,17 +64,22 @@ if (!api_is_anonymous()) {
|
|
|
$resultDate = Database::query($sqlDate)->rowCount();
|
|
|
|
|
|
if ($resultDate == 0) {
|
|
|
+ // If there are records, but none for today, set the
|
|
|
+ // 'cardgame' session variable and add the
|
|
|
+ // #havedeckcardgame element to the page (it will get
|
|
|
+ // picked up by JS later on)
|
|
|
Session::write('cardgame', 'havedeck');
|
|
|
$fh .= '<div id="havedeckcardgame" ></div>';
|
|
|
} else {
|
|
|
+ // If the user already played today, set the session
|
|
|
+ // 'cardgame' variable to 'done' and do not add
|
|
|
+ // an #havedeckcardgame element
|
|
|
Session::write('cardgame', 'done');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- if ($cardGameSession == 'havedeck') {
|
|
|
- $fh .= '<div id="havedeckcardgame" ></div>';
|
|
|
- }
|
|
|
+ $fh .= '<div id="havedeckcardgame" ></div>';
|
|
|
}
|
|
|
|
|
|
$parts = '';
|