Use ChamiloSession instead of $_SESSION

f9eda9b23b
pull/2697/head
Julio Montoya 7 years ago
parent d2f2def3b8
commit a874bdd52e
  1. 4
      plugin/card_game/card_game.php
  2. 17
      plugin/card_game/index.php
  3. 11
      plugin/card_game/resources/ajax.card.php

@ -1,5 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Define the CardGame class as an extension of Plugin to * Define the CardGame class as an extension of Plugin to
* install/uninstall the plugin. * install/uninstall the plugin.
@ -10,6 +11,9 @@
*/ */
class CardGame extends Plugin class CardGame extends Plugin
{ {
/**
* CardGame constructor.
*/
protected function __construct() protected function __construct()
{ {
parent::__construct( parent::__construct(

@ -1,5 +1,8 @@
<?php <?php
/* For license terms, see /license.txt */ /* For license terms, see /license.txt */
use ChamiloSession as Session;
/** /**
* This is the main script of the Card Game plugin. * This is the main script of the Card Game plugin.
* It is loaded on every page through the inclusion of the plugin in the * It is loaded on every page through the inclusion of the plugin in the
@ -17,11 +20,8 @@ if (!api_is_anonymous()) {
$version = '?v=041'; $version = '?v=041';
$interface = 'localhost'; $interface = 'localhost';
$parsedUrl = parse_url($_SERVER['REQUEST_URI']); $parsedUrl = parse_url($_SERVER['REQUEST_URI']);
$parsedUrlpath = $parsedUrl['path']; $parsedUrlpath = $parsedUrl['path'];
$pluginPath = api_get_path(WEB_PLUGIN_PATH).'card_game/resources/'; $pluginPath = api_get_path(WEB_PLUGIN_PATH).'card_game/resources/';
$fh = '<script type="text/javascript" src="'.$pluginPath.'js/cardgame.js'.$version.'" ></script>'; $fh = '<script type="text/javascript" src="'.$pluginPath.'js/cardgame.js'.$version.'" ></script>';
@ -36,7 +36,8 @@ if (!api_is_anonymous()) {
$user = api_get_user_info(); $user = api_get_user_info();
$userId = (int) $user['id']; $userId = (int) $user['id'];
if (!isset($_SESSION['cardgame'])) { $cardGameSession = Session::read('cardgame');
if (!empty($cardGameSession)) {
if (isset($userId)) { if (isset($userId)) {
$sqlCount = "SELECT access_date FROM plugin_card_game WHERE user_id = $userId"; $sqlCount = "SELECT access_date FROM plugin_card_game WHERE user_id = $userId";
$resultCount = Database::query($sqlCount)->rowCount(); $resultCount = Database::query($sqlCount)->rowCount();
@ -46,7 +47,7 @@ if (!api_is_anonymous()) {
$sql = "INSERT INTO plugin_card_game (user_id, access_date, pan) $sql = "INSERT INTO plugin_card_game (user_id, access_date, pan)
VALUES ($userId, DATE_ADD(CURDATE(), INTERVAL -1 DAY), 1);"; VALUES ($userId, DATE_ADD(CURDATE(), INTERVAL -1 DAY), 1);";
$resultInsert = Database::query($sql); $resultInsert = Database::query($sql);
$_SESSION['cardgame'] = 'havedeck'; Session::write('cardgame', 'havedeck');
} else { } else {
// @todo change date call // @todo change date call
$sqlDate = "SELECT access_date $sqlDate = "SELECT access_date
@ -56,15 +57,15 @@ if (!api_is_anonymous()) {
$resultDate = Database::query($sqlDate)->rowCount(); $resultDate = Database::query($sqlDate)->rowCount();
if ($resultDate == 0) { if ($resultDate == 0) {
$_SESSION['cardgame'] = 'havedeck'; Session::write('cardgame', 'havedeck');
$fh .= '<div id="havedeckcardgame" ></div>'; $fh .= '<div id="havedeckcardgame" ></div>';
} else { } else {
$_SESSION['cardgame'] = 'done'; Session::write('cardgame', 'done');
} }
} }
} }
} else { } else {
if ($_SESSION['cardgame'] == 'havedeck') { if ($cardGameSession == 'havedeck') {
$fh .= '<div id="havedeckcardgame" ></div>'; $fh .= '<div id="havedeckcardgame" ></div>';
} }
} }

@ -1,5 +1,8 @@
<?php <?php
/* For license terms, see /license.txt */ /* For license terms, see /license.txt */
use ChamiloSession as Session;
/** /**
* This script answers to AJAX calls to store a new piece as revealed * This script answers to AJAX calls to store a new piece as revealed
* in the plugin_card_game table. * in the plugin_card_game table.
@ -10,8 +13,10 @@
*/ */
require_once __DIR__.'/../../../main/inc/global.inc.php'; require_once __DIR__.'/../../../main/inc/global.inc.php';
if (isset($_SESSION['cardgame'])) { $cardGameSession = Session::read('cardgame');
if ($_SESSION['cardgame'] = 'havedeck') {
if (!empty($cardGameSession)) {
if ($cardGameSession = 'havedeck') {
$part = '1'; $part = '1';
if (isset($_GET['part'])) { if (isset($_GET['part'])) {
$part = (int) $_GET['part']; $part = (int) $_GET['part'];
@ -24,7 +29,7 @@ if (isset($_SESSION['cardgame'])) {
SET access_date = CURDATE() , parts = CONCAT(parts,'!!$part;!') SET access_date = CURDATE() , parts = CONCAT(parts,'!!$part;!')
WHERE user_id = $userId"; WHERE user_id = $userId";
Database::query($sql); Database::query($sql);
$_SESSION['cardgame'] = 'done'; Session::write('cardgame', 'done');
$sql = "UPDATE plugin_card_game $sql = "UPDATE plugin_card_game
SET pan = pan + 1 , parts = '' SET pan = pan + 1 , parts = ''

Loading…
Cancel
Save