Преглед изворни кода

Use ChamiloSession instead of $_SESSION

https://github.com/chamilo/chamilo-lms/commit/f9eda9b23bc7dd03057578ef37bb8cd267a0892e
Julio Montoya пре 6 година
родитељ
комит
a874bdd52e

+ 4 - 0
plugin/card_game/card_game.php

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

+ 9 - 8
plugin/card_game/index.php

@@ -1,5 +1,8 @@
 <?php
 /* For license terms, see /license.txt */
+
+use ChamiloSession as Session;
+
 /**
  * This is the main script of the Card Game plugin.
  * 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';
     $interface = 'localhost';
-
     $parsedUrl = parse_url($_SERVER['REQUEST_URI']);
-
     $parsedUrlpath = $parsedUrl['path'];
-
     $pluginPath = api_get_path(WEB_PLUGIN_PATH).'card_game/resources/';
 
     $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();
     $userId = (int) $user['id'];
 
-    if (!isset($_SESSION['cardgame'])) {
+    $cardGameSession = Session::read('cardgame');
+    if (!empty($cardGameSession)) {
         if (isset($userId)) {
             $sqlCount = "SELECT access_date FROM plugin_card_game WHERE user_id = $userId";
             $resultCount = Database::query($sqlCount)->rowCount();
@@ -46,7 +47,7 @@ if (!api_is_anonymous()) {
                 $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['cardgame'] = 'havedeck';
+                Session::write('cardgame', 'havedeck');
             } else {
                 // @todo change date call
                 $sqlDate = "SELECT access_date 
@@ -56,15 +57,15 @@ if (!api_is_anonymous()) {
                 $resultDate = Database::query($sqlDate)->rowCount();
 
                 if ($resultDate == 0) {
-                    $_SESSION['cardgame'] = 'havedeck';
+                    Session::write('cardgame', 'havedeck');
                     $fh .= '<div id="havedeckcardgame" ></div>';
                 } else {
-                    $_SESSION['cardgame'] = 'done';
+                    Session::write('cardgame', 'done');
                 }
             }
         }
     } else {
-        if ($_SESSION['cardgame'] == 'havedeck') {
+        if ($cardGameSession == 'havedeck') {
             $fh .= '<div id="havedeckcardgame" ></div>';
         }
     }

+ 8 - 3
plugin/card_game/resources/ajax.card.php

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