Thanks for this great plugin. I appreciate all the hard work done here.

I am wondering... is there a way right now to show responses within Views? I know that the responses are stored as nodes, but I need to be able to display individual answers from those responses within Views.

If this isn't currently available, where would be a good place to start in the code (if you have any suggestions)? I'd like to get that working. How many hours would you suspect it would take an average Drupal developer to get working?

Thanks!

[EDIT : ]

The v7.x-2.0 is available as an alpha.
All answers single datas are easily availables from the Views module now, and token datas to !
it comes with many improvements.
More informations here.

Comments

thedut’s picture

Hi dustinrwh,

Your are definitvely an advanced user of the LimeSurvey Sync module !
Actually, it is not possible to display individual question of one answer using views. The best you can do is to query the body, printing all answers of one (or more) response(s).

There 2 ways to show individual answers :
- The easier way : (not so easy) : declare to the views module (using hook__views_data()) the LimeSurvey tables, including there relationships.
- An harder and much powerfull way : import Limesurvey individual questions into Fields. The views display will be automatically available. This way may be a big evolution of the LimeSurvey Sync module, making this module the best 'form' module on drupal (and not simply the best 'survey' module on drupal). A good start is to explore the code from a sandbox : the LimeSurvey Importer (but I don't sugguest to use the feeds module). Anyway, for survey containing more than 50 questions, the current LimeSurvey Sync module version will be faster than a new version using Fields.

I'm sorry but I'm not able to estimate how many hours this developpment would take to get working.

Please, share your work if you start to dig on one way or another.

thedut’s picture

Priority: Major » Minor
Status: Active » Postponed
thedut’s picture

Hum, There is a third way, developpement would be very easy, it may take less than an hour of developpement !
The point is : this way may suit to you if you have only few questions to display within views for one (or few) survey(s).
I explain here how to do it for one question :

  1. On your answer content type edit page : create a field, it will store the answer for the targeted question.
  2. identify the LimeSurvey fieldname you want to match : look into the LimeSurvey database, into the 'survey_168837' structure, it must be something like '168837X19X606'.
  3. Here is the code : dig on the drupal/sites/all/modules/limesurvey_sync/ls_api/limesurvey_sync_api_answ.inc, looking for the limesurvey_sync_answ_import_answer() function : identify the loop next to the comment line '// Extract datas'; and write :
    if ($cell['fieldname'] == '168837X19X606') {
       // Save the $cell['answers'][0] value into the answer node Field, using the node_save() function.
     } 
  4. Thanks to that code, the result of the targeted question will be copy into your Field on each answer node synchronization.
    Note : You may identify the targeted question using its title instead of its fieldname, but it is not as specific, especially if you are using multilingual survey or if the question title is edited from the LimeSurvey software.

  5. Now, you can use views to show the value of this specific question.

You can feed back here, it's an interesting feature

thedut’s picture

Category: task » feature
dshields’s picture

A version of LimeSurvey Sync that uses fields would be very nice.
It would provide a lot of much-needed flexibility that simply isn't available at this time.

thedut’s picture

Yes.
I'm working on that. I pledge the LimeSurvey single questions will be available from views. It will be handled by an custom entity. It is not available yet.

dshields’s picture

It will be challenging, due to the naming convention of limesurvey's database table columns..

dshields’s picture

Issue summary: View changes

typo

drupalycious’s picture

Hello,
I tried your answer:

Here is the code : dig on the drupal/sites/all/modules/limesurvey_sync/ls_api/limesurvey_sync_api_answ.inc, looking for the limesurvey_sync_answ_import_answer() function : identify the loop next to the comment line '// Extract datas'; and write :
if ($cell['fieldname'] == '168837X19X606') {
// Save the $cell['answers'][0] value into the answer node Field, using the node_save() function.
}

but in my case the survey has expired and I would like to expose the results for each question, into fields so that I can manipulate it easily.
But when I try to synchronize again the survey, the answers to the questions do not get copied to the field where they should be.

Also when one create the field for the answer under the specific survey content type, it has only the choice between 1 to 10 values for this field so it can take into account only 10 answers.

In my case not even one answer fills the field.

I might have done something wrong, what do you think?

thanks

drupalycious’s picture

forget the number of values restriction, the unlimited option is before 1.
So my problem is only that the fields are not populated with the answers values.

Thanks

drupalycious’s picture

well something is missing between the curly brackets, i just got that your example was not complete.

could you tell me more in details what you mean by

// Save the $cell['answers'][0] value into the answer node Field, using the node_save() function

, and how to do it?

Thank you

mb7419’s picture

The sample code did work for me when I try to copy into a node field , I use the following
$node->field_xyz[$lang][0]['value']= $cell['answers'][0]

node_save was not required as $node was passed by reference and I could copy the survey values into a node this way ... not an expert but this was my experience when I was trying this example code ..

hanksterr7’s picture

Confirming the sample code worked for me too. Had to replace $lang with 'und' since that what was in my field_data_xyz table in the language column. I.e., used
$node->field_xyz['und'][0]['value']= $cell['answers'][0]

Didn't need node_save()

Just added the sample code (just the if statement with the above $node-> statement inside the if) just inside the foreach()
Way cool!

Thanks

thedut’s picture

Version: 7.x-1.1 » 7.x-1.7
Assigned: Unassigned » thedut
Priority: Minor » Normal
Issue summary: View changes
Status: Postponed » Fixed

Hello hanksterr7, mb7419, drupalycious, dshields and dustinrwh

The v7.x-2.0 is available as an alpha.
All answers single datas are easily availables from the Views module now, and token datas to !
it comes with many improvements.
More informations here.

dshields’s picture

That's a great improvement.
Thanks for following up.

hanksterr7’s picture

I installed 7.x-2.0 alpha. It is working great! I love the page in drupal where you can edit survey answer once an answer set to a survey has been completed!

I had to set the server time value to 7 hours earlier than the default settings would have done, in order to get the token time to be recognized as valid (did this instead of modifying the php code: limesurvey_sync_fixdate_drupal_to_ls() like I did in the earlier version)

I had to disable and then uninstall v7.x-1.1 limesurvey_sync in order to be able to install v7.x-2.0 alpha. Got lots of ugly errors if I just replaced the 1.1 limesurvey_sync folder with a 2.0 alpha and tried to do an update.php

Thanks!

hanksterr7’s picture

In case anyone is wondering how to make a View that shows survey answer entities, here's a quick tutorial:
-- create a new view. In the Show dropdown, find your survey answer entity (mine says "Answers 383724"). Keep the "create a page" checkbox checked and click Continue and Edit
-- On the view details page, change "Show: Calendar Entities" to "Rendered Entity", and then on the next pop-up, keep the default Row Style Options: View Mode: Full.

That's it! Your page will now show all the answers to the survey, nicely formatted.

thedut’s picture

Hello hanksterr7,

I love the page in drupal where you can edit survey answer once an answer set to a survey has been completed!

Yes, I love it to ! When the v2.x will be stable, users will be able to build survey on LimeSurvey then creating or editing answers only on Drupal. No need to use LS for creating or editing answers ! It could be a great way to manage heavy datas on Drupal.

I had to disable and then uninstall v7.x-1.1 limesurvey_sync in order to be able to install v7.x-2.0 alpha. Got lots of ugly errors if I just replaced the 1.1 limesurvey_sync folder with a 2.0 alpha and tried to do an update.php

There is no update scrip from v1.x et v2.x : in order of using the LimeSurvey Sync v7.x-2.0 alpha version, you should use a new Drupal install or back up the v1 then uninstalling it.

On the view details page, change "Show: Calendar Entities" to "Rendered Entity", and then on the next pop-up, keep the default Row Style Options: View Mode: Full.
That's it! Your page will now show all the answers to the survey, nicely formatted.

Great tip, thanks !

thedut’s picture

Issue summary: View changes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.