Welcome to the LimeSurvey Community Forum

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

Updating groups answered

  • Marco55
  • Marco55's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago - 3 years 6 months ago #205899 by Marco55
Updating groups answered was created by Marco55
Greetings everyone

We are deploying a survey, which contains several groups in group by group format.
Due to request, we need to allow navigation to any group from any group in the survey, show the status of each group, and allow users to close the survey and retake it later.
On the footer of the survey we placed a list of all the groups represented by their number with refs to each one, which works. The problem is, the status (answered/unanswered) its updated only for the questions between the first and the one the user is jumping to.
The array from which our twig element is getting the data Step info its returning the values up to the step on which the user is at, and filling the rest to the last groups with old data when the user already visited them.
This array is being updated in some method .
For example, user enters survey (array shows only first group data), then user jumps to 10th group, completely answers it, then jumps to 5th, (array shows data up to group 10 but data is updated up to group 5) and the 10th group remains showing "unanswered". The data is updated only when the user reaches or jumps to 10th group or superior.



You can see in image 2 that the array ends on index 13 when we are placed at question 14th, and the rest of the elements are not updated.

Video .


The ideal behavior would be that the data of every group is updated no matter the position of the user, has someone achieved this?
Last edit: 3 years 6 months ago by Marco55.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #205906 by DenisChenu
Replied by DenisChenu on topic Updating groups answered

Marco55 wrote: The ideal behavior would be that the data of every group is updated no matter the position of the user, has someone achieved this?

No, never,

I already have the idea on how to fix this, but never take time …

I have an old plugin about index ans step : framagit.org/SondagePro-LimeSurvey-plugin/fixMaxStep

Maybe you can get some inspiration

And myabe you can play with JumpTo in beforeSureyPage event ?
github.com/LimeSurvey/LimeSurvey/commit/...45a0fb16c501f8301722

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 following user(s) said Thank You: Marco55
The topic has been locked.
  • Marco55
  • Marco55's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #205929 by Marco55
Replied by Marco55 on topic Updating groups answered
Thanks, i will take a close look at your plugin and the code involved in that function, will update if i can find a workaround.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #205931 by DenisChenu
Replied by DenisChenu on topic Updating groups answered
I think (unsure) you need to move to end, and move to desired step after …

Something like

- LimeExpressionManager::JumpTo($_SESSION[$this->LEMsessid], false, true, true);
- LimeExpressionManager::JumpTo(0,false,false,true);
- LimeExpressionManager::JumpTo($_SESSION[$this->LEMsessid], false, false, true);
- LimeExpressionManager::JumpTo($_SESSION[App()->getPost('move'), false, true, true);

But your issue seems near : bugs.limesurvey.org/view.php?id=13859

Maybe bug reappear (again …) ?

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 following user(s) said Thank You: Marco55
The topic has been locked.
  • Marco55
  • Marco55's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 6 months ago #206050 by Marco55
Replied by Marco55 on topic Updating groups answered
Thank you! That solved the problem, we added a loop to jump to all unvisited groups and bring each one separately, replacing this method :
Code:
private function getIndexItemsGroups($type)
    {
        if (!$type) {
            return array();
        }
 
        $sessionLem = Yii::app()->session["survey_{$this->iSurveyId}"];
        if (empty($sessionLem['grouplist'])) {
            return array();
        }
 
        //jumps to all unvisited groups
        $maxreached = $sessionLem['maxstep'];
        for ($x = 1; $x <= $sessionLem['totalquestions']; $x++) {
            LimeExpressionManager::JumpTo($x, false, false, false, false);
        }
        //returns to current group
        LimeExpressionManager::JumpTo($sessionLem['step'], false, false, false, false);
 
 
        /* get the step info from LEM : for already seen group : give if error/show and answered ...*/
 
        //$stepInfos = LimeExpressionManager::GetStepIndexInfo();
        $stepIndex = array();
        foreach ($sessionLem['grouplist'] as $step=>$groupInfo) {
            /* EM step start at 1, we start at 0*/
            $groupInfo['step'] = $step + 1;
            //$stepInfo = isset($stepInfos[$step]) ? $stepInfos[$step] : array('show'=>true, 'anyUnanswered'=>true, 'anyErrors'=>true);
            //gets each group individually
            $stepInfo = LimeExpressionManager::GetStepIndexInfo($groupInfo['gid']);
            if (($type > 1 || $groupInfo['step'] <= $sessionLem['maxstep'] || true)
               // &amp;&amp; LimeExpressionManager::GroupIsRelevant($groupInfo['gid']) // $stepInfo['show'] is incomplete (for irrelevant group after the 'not submitted due to error group') GroupIsRelevant control it really
            ) {
                /* string to EM : leave fix (remove script , flatten other ...) to view */
                if (LimeExpressionManager::GroupIsRelevant($groupInfo['gid'])){
                    $stepIndex[$step] = array(
                        'gid'=>$groupInfo['gid'],
                        'text'=>LimeExpressionManager::ProcessString($groupInfo['group_name']),
                        'description'=>LimeExpressionManager::ProcessString($groupInfo['description']),
                        'step'=>$groupInfo['step'],
                        'url'=>Yii::app()->getController()->createUrl("survey/index", array('sid'=>$this->iSurveyId, 'move'=>$groupInfo['step'])),
                        'submit'=>ls_json_encode(array('move'=>$groupInfo['step'])),
                        'stepStatus'=>array(
                            'index-item-before' => ($groupInfo['step'] < $sessionLem['step']), /* did we need a before ? seen seems better */
                            'index-item-seen' => ($groupInfo['step'] <= $sessionLem['maxstep']),
                            'index-item-unanswered' => $stepInfo[$step]['anyUnanswered'],
                            'index-item-error' => $stepInfo[$step]['anyErrors'],
                            'index-item-current' => ($groupInfo['step'] == $sessionLem['step']),
                        ), /* order have importance for css : last on is apply */
                    );
                } else {
                    $stepIndex[$step] = array(
                        'gid'=>$groupInfo['gid'],
                        'text'=>LimeExpressionManager::ProcessString($groupInfo['group_name']),
                        'description'=>LimeExpressionManager::ProcessString($groupInfo['description']),
                        'step'=>$groupInfo['step'],
                        'url'=>Yii::app()->getController()->createUrl("survey/index", array('sid'=>$this->iSurveyId, 'move'=>$groupInfo['step'])),
                        'submit'=>ls_json_encode(array('move'=>$groupInfo['step'])),
                        'stepStatus'=>array(
                            'index-item-before' => ($groupInfo['step'] < $sessionLem['step']),
                            'index-item-seen' => ($groupInfo['step'] <= $sessionLem['maxstep']),
                            'index-item-unanswered' => $stepInfo[$step]['anyUnanswered'],
                            'index-item-deshabilitado' => true,
                            'index-item-error' => $stepInfo[$step]['anyErrors'],
                            'index-item-current' => ($groupInfo['step'] == $sessionLem['step']),
                        ),
                    );
                }
                $stepIndex[$step]['stepStatus']['index-item-error'] = $stepInfo[$step]['anyErrors'];
                $stepIndex[$step]['stepStatus']['index-item-unanswered'] = $stepInfo[$step]['anyUnanswered'];
                $aClass = array_filter($stepIndex[$step]['stepStatus']);
                $stepIndex[$step]['coreClass'] = implode(" ", array_merge(array('index-item'), array_keys($aClass)));
            }
        }
        return $stepIndex;
    }
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 6 months ago #206057 by DenisChenu
Replied by DenisChenu on topic Updating groups answered
Thansk but hard to see the difference …

I'm unsure : but in my opinion : it can be great feature or a good fix.

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.

Lime-years ahead

Online-surveys for every purse and purpose