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