Check out the LimeSurvey source code on GitHub!

Sending JSON when insert query !

More
5 years 3 weeks ago - 5 years 3 weeks ago #73546 by rodeo_fly
Hi,

first of all bravo for limesurvey...it is simply the best opensource survey application.

I'd like to send, via ajax, the survey once completed as a json object to a rest service (to add it as an object into a rails application) when clicking on submit button.

It would be very kind if you could tell me where is the best place to insert that code and may be a hint on how you would do this.

I'm not a php programmer but I'll probably have to use json_encode, won't have ?

tks in advance
Last Edit: 5 years 3 weeks ago by rodeo_fly.

Please Log in to join the conversation.

More
5 years 3 weeks ago #73560 by Mazi
What data do you want to send by json?

If you are not a programmer, it will be hardly impossible to set this up. One alternative solution might be to automatically redirect the user to a to be coded PHP script which gets passed some parameters and then does what you need and forwards data to the Rails system.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 3 weeks ago - 5 years 3 weeks ago #73582 by rodeo_fly
Hi, thanks for answer !
Actually I am a programmer and I want to do what you've just described.
There's this csv export function in limesurvey. Basically I want the same result but json formatted. If I get this json then sending it to rails is a piece of cake.

since your answer I've found this :
www.cparker15.com/code/utilities/csv-to-json/

so Json equivalent of this :
"id","Complété","Dernière page vue","Langue de départ","Code","date du prelevement","nom ou numero","sexe","Age","AgHBs","AgHBc","AcHBs","AcBHs valeur"
"1","2012-01-29 09:17:07","2","fr","","2012-01-29","12456","Masculin","25","positif","positif","positif","999"

would be this

[
{
"id": "1",
"Complété": "2012-01-29 09:17:07",
"Dernière page vue": "2",
"Langue de départ": "fr",
"Code": "",
"date du prelevement": "2012-01-29",
"nom ou numero": "12456",
"sexe": "Masculin",
"Age": "25",
"AgHBs": "positif",
"AgHBc": "positif",
"AcHBs": "positif",
"AcBHs valeur": "999"
}
]
then I send via ajax to my rails app and it stores it automatically as an openstruct attribute of any model !

Would be great !
Last Edit: 5 years 3 weeks ago by rodeo_fly.

Please Log in to join the conversation.

More
5 years 3 weeks ago #73594 by Mazi
You can place such an Ajax call at the source of the end message using teh source code mode of the editor.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
The following user(s) said Thank You: rodeo_fly

Please Log in to join the conversation.

More
5 years 2 weeks ago - 5 years 2 weeks ago #73649 by rodeo_fly
But the main probleme remian how to get a json or cvs file in one click at the end of the survey ?
May be I can call the script directly with some pre-configured parameters (like in the screenshot) to get a cvs file with not too much pain ?


screenshot
Last Edit: 5 years 2 weeks ago by rodeo_fly.

Please Log in to join the conversation.

More
5 years 2 weeks ago #73653 by DenisChenu
Hello,

You want json with code only or with all sentence ?

The easiest way can be code only : only one table.

You can put an ajax request at the endpage.pstpl, call a personnal php file with a sql request and a json_encode instruction.

For all sentence : look at the export php function (export_data_functions.php) to get some inspiration :).

There a lot of way to do some json with php :)

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
The following user(s) said Thank You: rodeo_fly

Please Log in to join the conversation.

More
5 years 2 weeks ago #73656 by rodeo_fly
Thank you Shnoulle, but I'm sure you understand that json is not really a problem ; the actual problem is the sql query to get the individual survey with headcode instead of 57338X1X3 and qcode as well.

So I'm going to digg export_data_functions.php to get some inspiration :)

Please Log in to join the conversation.

More
5 years 2 weeks ago #73661 by Mazi
Also have a look at the createfieldmap() function, it might make your life easier.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 2 weeks ago #73721 by rodeo_fly
Well after have been diving into this complex code to get The query you can get with 8 clics through limesurvey to get a csv file...I'll choose the manual way for now. I saw that this is not the first time that people ask for that function and as an evidence it is not straight forward (multiple dozens of LOC) !

May be ver 2.0 will be clearer. Anyway thanks for your help guys and may the force be with u ^_^

ps: I've jsut notice that my topic subject was incredibly badly written : should have been "get Json or CSV when submit Survey !". froggies are useless anyway ;)

Please Log in to join the conversation.

More
5 years 2 weeks ago #73747 by Mazi
Once you have found a running solution, please post it here for others. Thanks!


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 2 weeks ago - 5 years 2 weeks ago #73787 by rodeo_fly
Well I am not even near to it
And this is not very conforting :
www.limesurvey.org/fr/forum/can-i-do-thi...limesurvey-responses
:D

all rite it's not that funny but it means that this is wanted for years !
Serioulsly where is the guy who wrote this huge exportsresult.php ?
Don't you think it would take so many time for this guru to provide a simple script to get csv ?

Let's be constructive maybe some others will have the will and with the will we can everythings...yes we can !

foreach($_POST as $key=>$value)
{
echo $key."=".$value."&";
}
gives us
export_from=1&export_to=3&filterinc=show&exportstyle=headcodes&answers=short&convertyto=1&convertnto=2&type=csv&sid=63226&answerid=3&colselect=Array&checksessionbypost=vutv73gwdq

so wee need all those parameters to get our csv but we can't run the script from outside the admin.php or else we get a warning on csrf token violation

If I just take the script outside and comment the line...ahem ^_^

When I look again to that function my arms are falling down on the floor...How come this two csv lines are so complex to produce ???
Last Edit: 5 years 2 weeks ago by rodeo_fly.

Please Log in to join the conversation.

More
5 years 2 weeks ago #73810 by Mazi
For Limesurvey 2.0 we are porting all code to the MVC framework "Yii". I'm not sure if thise file was already properly restructured but you can check out the "limesurvey_yii" branch to have a look and test.
For the upcoming Google Summer of Code (if we will be accepted again by Google this year), there might be a task to create an API for such cases, see docs.limesurvey.org/Project+Ideas+for+GSoC+2012


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form