Restarting timer if survey taken on the same computer

More
1 year 5 months ago #151293 by Arthemis
Arthemis created the topic: Restarting timer if survey taken on the same computer
Hello everyone.
I have a survey with multiple questions that have a time limit. To prevent respondents returning to the same incomplete survey on the same computer, I used the newtest=Y in the URL. It does restart the survey but the timed questions appear out of time if the time elapsed on the previous attempt to answer the survey. How do I change this to have a completely new start without manually erasing cookies?
Thank you in advance!

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #151308 by DenisChenu
DenisChenu replied the topic: Restarting timer if survey taken on the same computer
Not included currently in LimeSurvey core .

Timer are in cookies
Solution : make a plugin to reset timer cookies with beforeSurveyPage

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago - 1 year 5 months ago #151324 by Arthemis
Arthemis replied the topic: Restarting timer if survey taken on the same computer
Thank you for your reply. Is it something I can change myself using the controls of the survey (and if yes - how) or is it in the setup of the LimeSurvey installation (I don't have access to this unfortunately, I'm using the survey through an organization that installed it for its researchers).
Last Edit: 1 year 5 months ago by Arthemis.

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #151325 by DenisChenu
DenisChenu replied the topic: Restarting timer if survey taken on the same computer

DenisChenu wrote: Not included currently in LimeSurvey core .
....


Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #151327 by Arthemis
Arthemis replied the topic: Restarting timer if survey taken on the same computer
Thank you. Here the plugin I wrote:
<?php
/**
* resetTimersNM Plugin for LimeSurvey
* Reset the timers for each question in a survey.
*
*
*
*/

class resetTimersNM extends \ls\pluginmanager\PluginBase {
static protected $description = 'Reset questions timers';
static protected $name = 'resetTimersNM';

public function init() {
$this->subscribe('beforeSurveyPage');
}

public function beforeSurveyPage() {
$oEvent = $this->event;
$iSurveyId=$oEvent->get('surveyId');

if (isset($_COOKIE)) {
unset($_COOKIE);
setcookie('limesurvey_timers', '', time() - 3600, '/'); // empty value and old timestamp
}

}
}

It works. Now I want to restart the timer only for new users on the same computer where a previous user did not submit. That is, I want to prevent users from reloading the page to get more time to answer the timed question. I identify unique users by login=uniquelogin in the URL where login is a hidden short-text question. Is there another event that is triggered by the start of the survey?
Thank you!

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #151334 by Arthemis
Arthemis replied the topic: Restarting timer if survey taken on the same computer
Ok, I figured it out. The plugin below resets timers only for those who just loaded the survey and passed the first question (i.e., the new comer, not someone trying to reload the page to get more time). It's also written to be survey-specific (in this case surveyID=9999) and the question id is set to 2 but can be any question at the start of the survey:
<?php
/**
* resetTimersNM Plugin for LimeSurvey
* Reset the timers for each question in a survey.
*
*
*
*/

class resetTimersNM extends \ls\pluginmanager\PluginBase {

static protected $description = 'Reset questions timers';
static protected $name = 'resetTimersNM';

public function init() {
$this->subscribe('beforeQuestionRender');
}

public function beforeQuestionRender() {

// Get Event
$oEvent = $this->event;

// Fetch Parameters
$iSurveyId = $oEvent->get('surveyId');
$qid = $oEvent->get('qid');

// Reset timers cookie for a specific survey and when the user go through
// a specific question.
if($iSurveyId==9999 && $qid==2)
{
if (isset($_COOKIE)) {
unset($_COOKIE);
setcookie('limesurvey_timers', '', time() - 3600, '/'); // empty value and old timestamp
}
}

}


}
The following user(s) said Thank You: DenisChenu

Please Log in or Create an account to join the conversation.

More
1 year 5 months ago #151823 by DenisChenu
DenisChenu replied the topic: Restarting timer if survey taken on the same computer
:cheer: Seems great start for a new plugin !

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in or Create an account to join the conversation.

More
3 months 1 week ago #169491 by mhm1704
mhm1704 replied the topic: Restarting timer if survey taken on the same computer
Do you know if there is a plug in to reset timer with beforeSurveyPage;

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!