Commit 8a8bda30 authored by Chenu Denis's avatar Chenu Denis

[fix] More way to update surveySession

parent 7aedc81d
<?php
/**
* This file is part of reloadAnyResponse plugin
* @version 1.0.1
* @version 1.0.2
*/
namespace reloadAnyResponse\models;
use Yii;
......@@ -75,7 +75,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 +85,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;
}
}
......@@ -146,11 +147,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;
......
......@@ -26,7 +26,7 @@ class reloadAnyResponse extends PluginBase {
static protected $dbVersion = 1;
const KeepSessionNumber = 15;
const KeepSessionNumber = 40;
/**
* @var array[] the settings
*/
......@@ -161,6 +161,7 @@ class reloadAnyResponse extends PluginBase {
/* Get the survey by srid and code */
/* Save current session */
$this->subscribe('beforeSurveyPage');
$this->subscribe('getPluginTwigPath');
/* Replace existing system if srid = new */
$this->subscribe('beforeLoadResponse');
/* Survey settings */
......@@ -489,6 +490,26 @@ class reloadAnyResponse extends PluginBase {
$this->_addUnloadScript($surveyid,$srid);
}
/** @inheritdoc
* Need to update current previousSessionId after all other action done
**/
public function getPluginTwigPath()
{
$surveyid = Yii::app()->getRequest()->getParam('sid',Yii::app()->getRequest()->getParam('surveyid'));
if(empty($surveyid)) {
return;
}
$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;
}
/**
* Delete SurveySession for this event srid
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment