Welcome to the LimeSurvey Community Forum

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

How can I test if a survey is submitted or completed?

  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 11 months ago #210279 by sodiumchl
How can I test if a survey is submitted or completed? I tried the following
Code:
$tComp = strip_tags(LimeExpressionManager::ProcessString('{TOKEN:COMPLETED}', $qid)); //should return "TOKEN:COMPLETED", "N" or "2020-12-22 18:50"
But it seems to return a date even if the survey is not submitted yet.
 
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 11 months ago #210287 by DenisChenu

sodiumchl wrote: How can I test if a survey is submitted or completed? I tried the following

Code:
$tComp = strip_tags(LimeExpressionManager::ProcessString('{TOKEN:COMPLETED}', $qid)); //should return "TOKEN:COMPLETED", "N" or "2020-12-22 18:50"
But it seems to return a date even if the survey is not submitted yet. 

Strange,

Did you check during Survey {TOKEN:COMPLETED} inside question text ?

And maybe better PorcessStepString ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 11 months ago #210322 by sodiumchl
I am using this in beforeQuestionRender() of a plugin. I would like to view a survey as it was filled out, but readonly after submitted. Currently I cannot detect "submitted" reliably while other aspects work.
Code:
public function beforeQuestionRender() {
$oEvent=$this->getEvent();
$qid = $oEvent->get('qid');
$tComp = strip_tags(LimeExpressionManager:ProcessStepString('{TOKEN:COMPLETED}', $qid)); 
var_dump($tComp);
...

I tried ProcessStepString. Same result.
 
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 11 months ago #210334 by DenisChenu
And put {TOKEN:COMPLETED} inside question text ?

PS : don't need strip_tags : it's a constant.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 11 months ago #210337 by sodiumchl
Yes, putting {TOKEN:COMPLETED} inside question text works: it returns Yes or No.

But then there is another issue: Anyway to refer to this question by its code, such as eComplete? Otherwise I have to put its qid in config which is inconvenient.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 11 months ago #210338 by DenisChenu
Can you upload your mini plugin ?

3.X or 4.X ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 11 months ago #210403 by sodiumchl
Thank you, Denis!
I am using version LimeSurvey 3.23.7+201006

I just made a small modification to SondagesPro/answersAsReadonly
github.com/SondagesPro/answersAsReadonly...nswersAsReadonly.php
so that only completed surveys are to be turned readonly.
Code:
public function beforeQuestionRender() { //originally setReadonly() 
    $oEvent=$this->getEvent();
    $qid = $oEvent->get('qid');
    $tComp = strip_tags(LimeExpressionManager:ProcessStepString('{TOKEN:COMPLETED}', $qid)); 
    //var_dump($tComp); //debuging only
    $isRO = (isset($tComp) && $tComp != 'TOKEN:COMPLETED' && $tComp != 'N' && (strtotime("now")-strtotime($tComp)) > 3600);
    if (!$isRO) return;
 
    //original code 
    $aAttributes=QuestionAttribute::model()->getQuestionAttributes($qid);
    if(empty($aAttributes['readonly'])) {
            return;
    }
    //...
}
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 11 months ago #210423 by DenisChenu
Did you test {TOKEN:COMPLETED == 'N' OR TOKEN:COMPLETED == "} in answer as readonly test sting ?

Else i test
Code:
        $currentReadonly = trim(LimeExpressionManager::ProcessStepString('{TOKEN:COMPLETED}',$aReplacement,3,1));
        tracevar($currentReadonly);
        if(empty($currentReadonly) || $currentReadonly == "N") {
            return;
        }
It work without issue.

can update at 1st launch, can not at 2nd one (with same token)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 11 months ago #210429 by sodiumchl
I tried the above. Still getting a date. My case is reloading/editing response multiple times with the same token. Anyway to make it working for 2nd or later load?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 11 months ago #210435 by DenisChenu
I have N when token launch for 1st time, a date after.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • sodiumchl
  • sodiumchl's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 11 months ago #210439 by sodiumchl
> I have N when token launch for 1st time, a date after.
Yes, I get this too. My question is, for later launches, how can I tell if the survey is submitted or not since it always returns a date?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 11 months ago - 3 years 11 months ago #210442 by DenisChenu
PLEASE EXPLAIN WHAT YOU WANT TO DO !

You talk for token completed … then no problem : the token is completed.

For current response : Reponse::model($sid)->getByPk($srid)->submitdate

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
Last edit: 3 years 11 months ago by DenisChenu.
The topic has been locked.
Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose