Welcome to the LimeSurvey Community Forum

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

Change survey questions, pathway or fork it based on quota

  • bulgin
  • bulgin's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 5 months ago #190105 by bulgin
Hello, I don't know if this is possible but I'm hoping it can be achieved.

I need to change a survey so that it doesn't actually close but gives a notice to the participant (who has a survey token) once the quota has been reached.

For example:

30 participants take the survey and get a special reward code sent to them via the attribute_1 code, however, once the 31st. participant enters their token to access the survey, they receive a message saying the rewards have been depleted and asking if they would like to take the survey without receiving a reward link. Then they can proceed to take the survey and at the end they will receive not the data in attribute_1, (a reward link) but attribute_2, but only for those taking the survey after the 30th. participant.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #190106 by Joffm
Hi,
that's nearly exactly what I talked about in the other thread.
www.limesurvey.org/de/foren/german-forum...it-limesurvey#187399
It's German, but there is google translate.


Here it is the question:
"This date and time is already fully booked; if you select you will be set on a waiting list."

In your case: "There are already enough participants. But you may preóceed without the incentive."

Tomorrow I hope that I'll have time to create an example.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • bulgin
  • bulgin's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 5 months ago #190107 by bulgin
Ok, thanks Joffm - I will look forward to an example when you have the time. I understand you are busy so when it's convenient. I also happen to have a German friend visiting and will ask them to translate the example you provided - but they are a doctor and know nothing about computers or programing so it may be not a perfect translation. Thanks!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago - 4 years 5 months ago #190126 by Joffm
Hi,
so here is a very small example.
1st question "short text" queries the database and returns the count of completes.
2nd question "relevance equation: if value of 1st question >30", "Do you want to proceed without ...?"
Quota with limit "0" on "No"

That's it.
Now it's up to you to taylor the end message according to the result of this first question (<=30, >30)

And the php file just contains:
1. connection to limesurvey_database
2. capture the POST-parameter
$SID = $_POST["sid"];

3. Query:
"SELECT count(*) FROM lime_survey_".$SID." WHERE submitdate is not NULL";

4. return the result
echo $count;


File Attachment:

File Name: limesurvey...7985.lss
File Size:30 KB

Joffm

P.S. I think the relevance equation of Q0 is set to "Info>3". You have to adapt it to 30, was just for the test.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 5 months ago by Joffm.
The topic has been locked.
  • bulgin
  • bulgin's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 5 months ago #190160 by bulgin
Joffm you are a genius! This looks like it could work! I've downloaded the lss file and when I get back from my work travels in a couple of days I will test and report back.

Thanks again!!
The topic has been locked.
  • bulgin
  • bulgin's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 5 months ago - 4 years 5 months ago #190281 by bulgin
Hi Joffm.

A couple of questions on this cool code:

1) I'm assuming the script code is accessible via the question editor of the first question, and by clicking on the "source" command. Correct?

2) Does the getCountComplete.php in www.myServer.com/myPath/getCountComplete.php contain the code:

1. connection to limesurvey_database
2. capture the POST-parameter
$SID = $_POST["sid"];

3. Query:
"SELECT count(*) FROM lime_survey_".$SID." WHERE submitdate is not NULL";

4. return the result
echo $count;

and finally: connect to limesurvey database? I'm guessing the php file would contain the authentication necessary for that and is that safe?

I'm sure I'm close but not perfect here in my questions.

Thank you.
Last edit: 4 years 5 months ago by bulgin.
The topic has been locked.
  • bulgin
  • bulgin's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 5 months ago #190282 by bulgin
So I'm almost there. This is what I have in the getCountComplete.php"

$mysqli = new mysqli("localhost", "xxxx_xxxx", "xxxxxxxx", "xxxxx_xxxxx");
$SID = $_POST["sid"];
"SELECT count(*) FROM xxxxx_xxxxx_".$SID." WHERE submitdate is not NULL";
echo $count;

Now proceed to screenshots. I can proceed into survey past question 3. So I guess it's not working.




The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #190298 by Joffm
Obviously there is something wrong in your survey.
No data are stored.

Do you really have this in your php file?

"SELECT count(*) FROM xxxxx_xxxxx_".$SID." WHERE submitdate is not NULL";

I only wrote the SELECT statement itself. because anybody may use a different way to query:
mysqli procedural
mysqli OOP
PDO
meekrodb
...

So you should use the correct syntax of your query.
Something like:
$mysqli = new mysqli('host', 'user', 'pw', 'db');
$query = 'SELECT count(*) FROM xxxxx_xxxxx_".$SID." WHERE submitdate is not NULL';
$result = $mysqli->query($query);

and then something like
while ($row = $result->fetch_assoc()) {
...
}

That's up to you.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • bulgin
  • bulgin's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 5 months ago #190299 by bulgin
Hi.

I definetly have "SELECT count(*) FROM xxxxx_xxxxx_".$SID." WHERE submitdate is not NULL";

in the .php file.

What is curious is that all the rows actually show "null" in the database table. shouldn't it be at least something other than "null" regardless of the getCountComplete.php working or not working?

I mean aren't those fields filled by limesurvey separate from the getCountComplete.php working or not?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #190302 by Joffm
No, that's correct.
The info is empty because there is nothing returned from the query
Q0 is empty because this question is never displayed (info not greater than 3)
Q1 is empty by default (text display)

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • bulgin
  • bulgin's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 5 months ago #190306 by bulgin
Oh, yes, that would make sense. Thanks for clearing that up.

Now I'm struggling with the mysql commands as I'm not an expert in that field.

Thanks for all your help and suggestions.
The topic has been locked.
  • bulgin
  • bulgin's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 4 months ago #190468 by bulgin
Wouldn't a simple count of "uses left" in "lime_tokens_X" be simpler?
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose