Welcome to the LimeSurvey Community Forum

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

Getting all sequence numbers for a survey response programatically

  • rhuang
  • rhuang's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 9 months ago - 5 years 9 months ago #170667 by rhuang
I have about 20 forms that have about 900 questions total. These questions are subject to changes (new questions, delete old ones, update existing ones, change branch logic, etc). I've co-opted the print page to display a summary of all the responses. I've set the "end url" to link to the print page, so that when a user submits the survey, the user is directed to the print page to see a summary. On the print page, I've put a button to link back to my parent application.

The survey settings are:
- token table
- not anonymized responses
- user can come back and continue/edit already submitted response
- group by group


What I need to is to have links on the print page for each group section and or individual question that link to that specific group or question (since it's group by group, the question link will be the same as the group link).

I've called list_questions in the Remote Control API and it returns the question_order. I thought this was what I needed, but I realized that the sequence id is different than the question_order, I think due to group by group and branching logic.

For this, I need the sequence ids available on the print page. I am not able to programatically get them. There's no Remote Control API to do this. Does anyone have any guidance on parts of the LimeSurvey core code I need to modify to get them? It can be a new API, or somehow plumbed in through an expression manager variable that contains ALL the sequence ids, etc.

I don't want to do this via question_code.qseq since it's a monumental effort to keep this up to date with all my surveys.


Another option is to enable the question index on the print page. Maybe this is easier?


I'm an experienced Ruby/Java/JavaScript developer. I don't know anything about PHP, but I don't mind digging into the code for targeted changes.


Here's a link to a token on a test survey: forms.jdivorce.com/index.php/795464?toke...st&newtest=Y&lang=en
If you click through to the end, you will see my co-opted print/summary page.
Last edit: 5 years 9 months ago by rhuang.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #170668 by DenisChenu
Hi,

sequence, you mean step :)

I don't think there are a clean way to have the step of a specific question. You can evaluate like this : 1st group is 0, 2nd group is 1 etc …

Since you are in printView, then survey is constructed, maybe you can get it calling github.com/LimeSurvey/LimeSurvey/blob/b7...ger_helper.php#L7060 in a plugin/hacked page.
(you can easily use your own plugin for replace print page, see gitlab.com/SondagesPro/ExportAndStats/pd...r/pdfReport.php#L291 ).

Else : great job on template on this survey ;)

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: rhuang
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #170675 by DenisChenu
Yes,

And more i make an error …

manual.limesurvey.org/Expression_Manager#Access_to_Variables
Then in twig file :

{{ processString(self.gseq) }} for single question, unsure (need testing) for multiple question, can try to with {{ processString(this.gseq) }}

Else, maybe it's a good idea to see what you have in question :)

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: rhuang
The topic has been locked.
  • rhuang
  • rhuang's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 9 months ago - 5 years 9 months ago #170706 by rhuang
Thanks for the pointers, I'll check these things out.
Regarding the twig files - is that from LimeSurvey 3.x, with new templating system?
I'm on version 2.65.3. I did a bit of googling, it seems that it's not a straight forward update from 2.x to 3.x.

Is there a way to do this in 2.x?
I also saw LimeExpressionManager::GetQuestionSeq, which I *think* is what I need.
I tested it by calling it with LimeExpressionManager::GetQuestionSeq(2627), where 2627 is one of the question ids, and it returns a number that doesn't seem correct.

Basically I need generate this link dynamically for every question on the print page, where :

<a data-limesurvey-submit="{ 'move': 1 }" href="/index.php/795464?move=1">Edit Question</a>

I'm also fine with just being able to jump to a group. In template.js, I see:

if($('.linkToButton').length > 0){
$('.linkToButton').on('click', function()
{
$btnToClick = $($(this).attr('data-button-to-click'));
$btnToClick.trigger('click');
return false;
});
}

This basically triggers $('#button-123').click(...), where 123 is the group ID. This code I see is for the question index. However, I don't think this click event is generated or attached in the print page since the question index isn't generated in the print page. If there's a good way to recreate this in the print page, it would be awesome too.
Last edit: 5 years 9 months ago by rhuang.
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • Visitor
  • Visitor
5 years 9 months ago #170727 by LouisGac
LS3 would just be perfect for this.
For 2.x, it will not be easy.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #170762 by DenisChenu
For 2.X : you have to replace printview by your own controller/system.

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.
  • rhuang
  • rhuang's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 9 months ago #170823 by rhuang
This is the solution I came up with:

In the question definition, I add this:

<h2>My question title...</h2>
<div class="gseq hidden">{question_code.gseq}</div>
<div class="qseq hidden">{question_code.qseq}</div>

The "hidden" class has "display: none;".
In my JS, I add code " var gseq = $('.gseq').text();" to get the question's group sequence. Then I can modify the "Edit Section" link to go to "'/index.php/12345?move=' + gseq;", and modify the data attribute too.

I think I'm okay with this solution because it just means that adding the 2 hidden divs becomes part of defining the question, is fine, since all the question definition is in one place.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago - 5 years 9 months ago #170833 by tpartner

...it just means that adding the 2 hidden divs becomes part of defining the question, is fine, since all the question definition is in one place.

If using a custom template, you could add a data attribute for this to the question view in question.pstpl.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 9 months ago by tpartner.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • rhuang
  • rhuang's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 9 months ago - 5 years 9 months ago #170970 by rhuang

tpartner wrote:

...it just means that adding the 2 hidden divs becomes part of defining the question, is fine, since all the question definition is in one place.

If using a custom template, you could add a data attribute for this to the question view in question.pstpl.


How can I do this "add a data attribute" to question.pstpl? Do you have an example? From what I understand, I need to access the {question_code}, like {livingSituationQuestion.gseq}? How can I make question.pstpl know which question code it's on?

I just saw {QUESTION_CODE}, but for some reason it doesn't show up in my survey even when I enable "Show Both" for "Show question number and/or code:".

Is there a way to get `gseq` too? Like {QUESTION_CODE.gseq}?
Last edit: 5 years 9 months ago by rhuang.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #170985 by DenisChenu
Try with {self.gseq} but it's only for single choice question

manual.limesurvey.org/Expression_Manager#Access_to_Variables

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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago - 5 years 9 months ago #170993 by tpartner

DenisChenu wrote: Try with {self.gseq} but it's only for single choice question

manual.limesurvey.org/Expression_Manager#Access_to_Variables

Hmm...it seems to work for all question types for me (tested with array, long-text, list-radio, multi-choice, text-display).


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 9 months ago by tpartner.
The following user(s) said Thank You: DenisChenu
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose