...
 
Commits (2)
<?php <?php
/** /**
* This file is part of reloadAnyResponse plugin * This file is part of reloadAnyResponse plugin
* @version 1.0.1 * @version 1.0.2
*/ */
namespace reloadAnyResponse\models; namespace reloadAnyResponse\models;
use Yii; use Yii;
...@@ -23,6 +23,8 @@ class surveySession extends CActiveRecord ...@@ -23,6 +23,8 @@ class surveySession extends CActiveRecord
/* @const integer The max time for session, if it's not set in session or by server (0 in session_time_limit) */ /* @const integer The max time for session, if it's not set in session or by server (0 in session_time_limit) */
const maxSessionTime = 30; const maxSessionTime = 30;
/* @const integer The max session id number to keep */
const KeepSessionNumber = 40;
/** @inheritdoc */ /** @inheritdoc */
public static function model($className=__CLASS__) { public static function model($className=__CLASS__) {
...@@ -75,7 +77,8 @@ class surveySession extends CActiveRecord ...@@ -75,7 +77,8 @@ class surveySession extends CActiveRecord
if(!$srid && !$token) { if(!$srid && !$token) {
return; return;
} }
if(Survey::model()->findByPk($sid)->getHasTokensTable()) { $oSurvey = Survey::model()->findByPk($sid);
if($oSurvey->getHasTokensTable()) {
if(!$token) { if(!$token) {
$token = isset($_SESSION['survey_'.$sid]['token']) ? $_SESSION['survey_'.$sid]['token'] : null; $token = isset($_SESSION['survey_'.$sid]['token']) ? $_SESSION['survey_'.$sid]['token'] : null;
} }
...@@ -84,7 +87,7 @@ class surveySession extends CActiveRecord ...@@ -84,7 +87,7 @@ class surveySession extends CActiveRecord
} }
if(!$token) { if(!$token) {
$oResponse = Response::model($sid)->findByPk($srid); $oResponse = Response::model($sid)->findByPk($srid);
if($oResponse && !empty($oResponse->token)) { if($oResponse && $oSurvey->anonymized != "N" && !empty($oResponse->token)) {
$token = $oResponse->token; $token = $oResponse->token;
} }
} }
...@@ -100,6 +103,7 @@ class surveySession extends CActiveRecord ...@@ -100,6 +103,7 @@ class surveySession extends CActiveRecord
} }
$oSessionSurvey->lastaction = date('Y-m-d H:i:s'); $oSessionSurvey->lastaction = date('Y-m-d H:i:s');
$oSessionSurvey->session = Yii::app()->getSession()->getSessionID(); $oSessionSurvey->session = Yii::app()->getSession()->getSessionID();
self::addCurrrentSessionInPrevious(Yii::app()->getSession()->getSessionID());
$oSessionSurvey->save(); $oSessionSurvey->save();
return $oSessionSurvey; return $oSessionSurvey;
} }
...@@ -135,6 +139,7 @@ class surveySession extends CActiveRecord ...@@ -135,6 +139,7 @@ class surveySession extends CActiveRecord
/* Same session : save time and quit */ /* Same session : save time and quit */
if($oSessionSurvey->session == Yii::app()->getSession()->getSessionID()) { if($oSessionSurvey->session == Yii::app()->getSession()->getSessionID()) {
$oSessionSurvey->lastaction = date('Y-m-d H:i:s'); $oSessionSurvey->lastaction = date('Y-m-d H:i:s');
self::addCurrrentSessionInPrevious(Yii::app()->getSession()->getSessionID());
$oSessionSurvey->save(); $oSessionSurvey->save();
return null; return null;
} }
...@@ -146,11 +151,6 @@ class surveySession extends CActiveRecord ...@@ -146,11 +151,6 @@ class surveySession extends CActiveRecord
$oSessionSurvey->save(); $oSessionSurvey->save();
return null; return null;
} }
tracevar([
$oSessionSurvey->session,
Yii::app()->getSession()->getSessionID(),
$previousSessionId,
]);
$lastaction = strtotime($oSessionSurvey->lastaction); $lastaction = strtotime($oSessionSurvey->lastaction);
$now = strtotime("now"); $now = strtotime("now");
$sinceTime = abs($lastaction - $now) / 60; $sinceTime = abs($lastaction - $now) / 60;
...@@ -165,4 +165,28 @@ class surveySession extends CActiveRecord ...@@ -165,4 +165,28 @@ class surveySession extends CActiveRecord
$sessionTimeLimit = intval(Yii::app()->getConfig('surveysessiontime_limit',self::maxSessionTime)); $sessionTimeLimit = intval(Yii::app()->getConfig('surveysessiontime_limit',self::maxSessionTime));
return $sessionTimeLimit; return $sessionTimeLimit;
} }
/**
* try to keep previous session in session …
* @param string $sessionId, ifb not set : current one
* @return void
*/
public static function addCurrrentSessionInPrevious($sessionId=null)
{
$previousSessionIds = Yii::app()->session['previousSessionId'];
if(empty($previousSessionIds)) {
$previousSessionIds = array();
}
if(empty($sessionId)) {
$sessionId = Yii::app()->getSession()->getSessionID();
}
if(!in_array($sessionId,$previousSessionIds)) {
$previousSessionIds[] = $sessionId;
}
$previousSessionIds = array_unique($previousSessionIds);
if(count($previousSessionIds) > self::KeepSessionNumber ) {
array_shift($previousSessionIds);
}
Yii::app()->session['previousSessionId'] = $previousSessionIds;
}
} }
...@@ -26,7 +26,6 @@ class reloadAnyResponse extends PluginBase { ...@@ -26,7 +26,6 @@ class reloadAnyResponse extends PluginBase {
static protected $dbVersion = 1; static protected $dbVersion = 1;
const KeepSessionNumber = 15;
/** /**
* @var array[] the settings * @var array[] the settings
*/ */
...@@ -404,16 +403,7 @@ class reloadAnyResponse extends PluginBase { ...@@ -404,16 +403,7 @@ class reloadAnyResponse extends PluginBase {
/* Save current session Id to allow same user to reload survey in same browser */ /* Save current session Id to allow same user to reload survey in same browser */
/* resetAllSessionVariables regenerate session id */ /* resetAllSessionVariables regenerate session id */
/* Keep previous session id, if user reload start url it reset the sessionId, need to leav access */ /* Keep previous session id, if user reload start url it reset the sessionId, need to leav access */
$previousSessionId = Yii::app()->session['previousSessionId'];
if(empty($previousSessionId)) {
$previousSessionId = array();
}
$previousSessionId[] = Yii::app()->getSession()->getSessionID();
$previousSessionId = array_unique($previousSessionId);
if(count($previousSessionId) > self::KeepSessionNumber ) {
array_shift($previousSessionId);
}
Yii::app()->session['previousSessionId'] = $previousSessionId;
$surveyid = $this->getEvent()->get('surveyId'); $surveyid = $this->getEvent()->get('surveyId');
$multiAccessTime = $this->_getCurrentSetting('multiAccessTime',$surveyid); $multiAccessTime = $this->_getCurrentSetting('multiAccessTime',$surveyid);
if($multiAccessTime !== '') { if($multiAccessTime !== '') {
......