Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Restarting timer if survey taken on the same computer

  • Arthemis
  • Arthemis's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 weeks ago #151293 by Arthemis
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!
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 weeks ago #151308 by DenisChenu
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 , plugin development .
I don't answer to private message.
The topic has been locked.
  • Arthemis
  • Arthemis's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 weeks ago - 7 years 3 weeks ago #151324 by Arthemis
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: 7 years 3 weeks ago by Arthemis.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 weeks ago #151325 by DenisChenu

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 , plugin development .
I don't answer to private message.
The topic has been locked.
  • Arthemis
  • Arthemis's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 weeks ago #151327 by Arthemis
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!
The topic has been locked.
  • Arthemis
  • Arthemis's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 weeks ago #151334 by Arthemis
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
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 weeks ago #151823 by DenisChenu
: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 , plugin development .
I don't answer to private message.
The topic has been locked.
More
5 years 10 months ago #169491 by mhm1704
Do you know if there is a plug in to reset timer with beforeSurveyPage;
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose