Commit c7e59524 authored by Chenu Denis's avatar Chenu Denis
Browse files

[feature] Save max step

[fix] Don't update $datestamp when reload reponse
parent e23a083b
......@@ -54,8 +54,8 @@ class StartUrl
}
/**
* Validate if reload is available with current information,
* Didn't check code
* Check Permission with current information,
* Didn't check if code exist, only Permission
* @return boolean
*/
public function isAvailable()
......
......@@ -5,7 +5,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2020 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 1.1.0
* @version 1.2.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
......@@ -26,7 +26,7 @@ use Survey;
class Utilities
{
/* @var float give information for other plugin of Plugin API version */
CONST API = 3.2;
CONST API = 3.3;
/* @var array DefaultSettings : the default settings if not set by DB @see reloadAnyResponse::settings */
CONST DefaultSettings = array(
......@@ -390,8 +390,8 @@ class Utilities
if(empty($reloadAnyResponseForcedSettings[$surveyId])) {
$reloadAnyResponseForcedSettings[$surveyId] = array();
}
$reloadAnyResponseForcedSettings[$surveyId][$sSetting] = true;
App()->session['reloadAnyResponseSettings'] = $reloadAnyResponseForcedSettings;
$reloadAnyResponseForcedSettings[$surveyId][$sSetting] = true;
App()->session['reloadAnyResponseSettings'] = $reloadAnyResponseForcedSettings;
}
/**
......@@ -404,4 +404,32 @@ class Utilities
$reloadAnyResponseForcedSettings = App()->session['reloadAnyResponseSettings'];
return !empty($reloadAnyResponseForcedSettings[$surveyId][$sSetting]);
}
/**
* Get max step of a response
* @param integer survey id
* @param integer survey id
* @return boolean
*/
public static function setMaxStep($surveyId, $srid) {
if(!empty($_SESSION['survey_'.$surveyId]['maxstep'])) {
\Response::model($surveyId)->updateByPk($srid, array('reload_maxstep' => $_SESSION['survey_'.$surveyId]['maxstep']));
}
}
/**
* Create a column to save max page in DB
* @param integer survey id
* @return boolean if done with success
*/
public static function setMaxStepDb($surveyId) {
$tableName = "{{survey_{$surveyId}}}";
$table = App()->db->schema->getTable($tableName);
if(!isset($table->columns['reload_maxstep'])) {
App()->db->createCommand()->addColumn($tableName, 'reload_maxstep', "integer");
Yii::app()->db->schema->getTable($tableName, true);
}
return true;
}
}
......@@ -5,7 +5,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2018-2020 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 3.2.1
* @version 3.3.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -45,7 +45,7 @@ class reloadAnyResponse extends PluginBase {
'allowAdminUser' => array(
'type'=>'checkbox',
'htmlOptions'=>array(
'value'=>1,
'valu'=>1,
'uncheckValue'=>0,
),
'label'=>"Allow admin user to reload any survey with response id.",
......@@ -194,6 +194,15 @@ class reloadAnyResponse extends PluginBase {
'label' => "When survey is save or move for the 1st time : reset it as not submitted.",
'default' => 1,
),
'keepMaxStep'=>array(
'type'=>'checkbox',
'htmlOptions'=>array(
'value'=>1,
'uncheckValue'=>0,
),
'label' => "Keep max step during each load and save.",
'default' => 0,
),
/* surveySession settings */
'noHttpUserAgent'=>array(
'type'=>'select',
......@@ -316,7 +325,8 @@ class reloadAnyResponse extends PluginBase {
$throwErrorRightDefault = $this->get('throwErrorRight',null,null,$this->settings['throwErrorRight']['default']) ? gT('Yes') : gT('No');
$replaceDefaultSaveDefault = $this->get('replaceDefaultSave',null,null,$this->settings['replaceDefaultSave']['default']) ? gT('Yes') : gT('No');
$clearAllActionDefault = $this->get('clearAllAction',null,null,$this->settings['clearAllAction']['default']);
$reloadResetSubmittedDefault = $this->get('reloadResetSubmitted',null,null,$this->settings['reloadResetSubmitted']['default']);
$reloadResetSubmittedDefault = $this->get('reloadResetSubmitted',null,null,$this->settings['reloadResetSubmitted']['default']) ? gT('Yes') : gT('No');
$keepMaxStepDefault = $this->get('keepMaxStep',null,null,$this->settings['keepMaxStep']['default']) ? gT('Yes') : gT('No');
switch($clearAllActionDefault) {
case 'reset':
......@@ -473,7 +483,21 @@ class reloadAnyResponse extends PluginBase {
'label' => $this->_translate("Reset submitdate on the first action done."),
'help' => $this->_translate("When a submitted survey is open without action : nothing was updated, if user do an action : you can choose to reset the respnse to not submitted."),
'htmlOptions'=>array(
'empty' => CHtml::encode(sprintf($this->_translate("Use default (%s)"),$replaceDefaultSaveDefault)),
'empty' => CHtml::encode(sprintf($this->_translate("Use default (%s)"),$reloadResetSubmittedDefault)),
),
'current'=>$this->get('reloadResetSubmitted','Survey',$oEvent->get('survey'),"")
),
/* Save (abnd load) max step */
'keepMaxStep' => array(
'type'=>'select',
'options'=>array(
1 =>gT("Yes"),
0 =>gT("No"),
),
'label' => $this->_translate("Keep max page seen when load and save."),
'help' => $this->_translate("Add a column in database to keep max page seen. Reload it when load response."),
'htmlOptions'=>array(
'empty' => CHtml::encode(sprintf($this->_translate("Use default (%s)"),$keepMaxStepDefault)),
),
'current'=>$this->get('reloadResetSubmitted','Survey',$oEvent->get('survey'),"")
),
......@@ -795,6 +819,9 @@ class reloadAnyResponse extends PluginBase {
}
}
if($srid) {
if(\reloadAnyResponse\Utilities::getSetting($this->surveyId,'keepMaxStep')) {
\reloadAnyResponse\Utilities::setMaxStep($this->surveyId, $srid);
}
$ajaxUrl = Yii::app()->getController()->createUrl(
'plugins/direct',
array('plugin' => get_class($this), 'function' => 'close','sid'=>$this->surveyId,'srid'=>$srid)
......
......@@ -41,11 +41,14 @@ class reloadResponse
$language = $oSurvey->language;
}
$this->language = $language;
if(Utilities::getSetting($this->surveyId,'keepMaxStep')) {
Utilities::setMaxStepDb($this->surveyId);
}
}
/**
* Start and load a Survey
* No control is done for rights or token in this function
* @param null|true|integer $step , null : 1st page, true : get current step or response , integer : to this step
* @param null|true|integer $step , null : 1st page, true : get current step of response (1st if submitted) , integer : to this step
* @param boolean|null $resetSubmit, if null : reset according to alloweditaftercompletion
* @return void
*/
......@@ -57,9 +60,13 @@ class reloadResponse
/* Not available currently, no need */
throw new \Exception('Reponse not found.');
}
$keepMaxStep = Utilities::getSetting($this->surveyId,'keepMaxStep');
killSurveySession($surveyId);
$_SESSION['survey_'.$surveyId]['s_lang'] = $this->language;
$currentStep = $maxStep = $oResponse->lastpage;
if ($keepMaxStep && $oResponse->reload_maxstep > $currentStep) {
$maxStep = $oResponse->reload_maxstep;
}
$submitdate = $oResponse->submitdate;
LimeExpressionManager::SetSurveyId($surveyId);
buildsurveysession($surveyId);
......@@ -137,12 +144,25 @@ class reloadResponse
$currentStep = 1;
}
}
$maxStep = max($currentStep,$maxStep);
\Response::model($this->surveyId)->updateByPk($this->srid, array('submitdate' => null));
$datestamp = null;
if (Survey::model()->findByPk($surveyId)->getIsDateStamp()) {
$datestamp = $oResponse->datestamp;
}
LimeExpressionManager::JumpTo($maxStep, false, false);
if($maxStep != $currentStep) {
if($maxStep > $currentStep) {
LimeExpressionManager::JumpTo($currentStep, false, false, true);
}
\Response::model($this->surveyId)->updateByPk($this->srid, array('submitdate' => $submitdate));
if(Utilities::getSetting($this->surveyId,'keepMaxStep')) {
\Response::model($this->surveyId)->updateByPk($this->srid, array('reload_maxstep' => $maxStep));
}
if (Survey::model()->findByPk($surveyId)->getIsDateStamp() && $datestamp) {
\Response::model($this->surveyId)->updateByPk($this->srid, array('datestamp' => $datestamp));
}
if($submitdate) {
\Response::model($this->surveyId)->updateByPk($this->srid, array('submitdate' => $submitdate));
}
$_SESSION['survey_'.$surveyId]['maxstep'] = $maxStep;
$_SESSION['survey_'.$surveyId]['step'] = $currentStep;
}
......
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