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

More
1 week 3 days ago #210279 by sodiumchl
How can I test if a survey is submitted or completed? I tried the following
$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.
 

Please Log in to join the conversation.

LimeSurvey Partners
More
1 week 3 days ago #210287 by DenisChenu

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

$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 service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

More
1 week 2 days 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.
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.
 

Please Log in to join the conversation.

More
1 week 2 days 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 service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

More
1 week 2 days 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.

Please Log in to join the conversation.

More
1 week 2 days 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 service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

More
1 week 1 day 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.
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;
    }
    //...
}

Please Log in to join the conversation.

More
1 week 1 day ago #210423 by DenisChenu
Did you test {TOKEN:COMPLETED == 'N' OR TOKEN:COMPLETED == "} in answer as readonly test sting ?

Else i test
        $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 service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

More
1 week 1 day 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?

Please Log in to join the conversation.

More
1 week 1 day 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 service on demand , plugin development . I don't answer to private message.

Please Log in to join the conversation.

More
1 week 18 hours 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?

Please Log in to join the conversation.

More
1 week 18 hours ago - 1 week 18 hours 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 service on demand , plugin development . I don't answer to private message.
Last edit: 1 week 18 hours ago by DenisChenu.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now