First of all, thanks for this module - I am a big fan of LimeSurvey, and I think solid Drupal integration is a big win for both projects.
We are working on a site where we don't need the ls_answ functionality. Whilst ls_survey does not explicitly depend on ls_answ, it does implicitly depend on it, as it is impossible to create survey nodes with ls_answ disabled (due to form validation errors).
The attached patch adds module_exists checks around the areas that seemed to be causing the most trouble - there may be a few others I didn't find, of course. I think the best approach would be to add the code that expects or interacts with ls_answ into the ls_answ module itself, as this would be a better abstraction - this might be best as a separate issue though, as it may take quite a bit of refactoring.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | drush-iq-make-ls_survey-not-depend-on-ls_answ-1863108-1.patch | 6.44 KB | owen barton |
Comments
Comment #1
owen barton commentedComment #2
thedut commentedHi Owen Barton !
Thank you for sharing your experience and custom code on the LimeSurvey Sync module.
I may think on your idea, but, at the first sight, I may not implement such feature.
The point is : when a survey node is created, it creates in the meanwhile the associated answers content type. The answer content types are declared into the ls_answ_info() function. That why the ls_answ module is needed when creating a new survey node. And it would be an error to declare it somewhere else [EDIT : That's not true on Drupal 7, see #4].
If I would implement your idea, I would need to add a checkboxe when the node survey is created asking if the answers content type has to be created or not but it would make no sense : answer content type is needed even if you don't use tokens or if you don't import answers because you need it to provide the limesurvey answer url : node/add/your_answer_content_type.
Furthermore, I don't understand why someone may want to enable the ls_survey module but not the ls_answ module... The ls_answ module can be enabled it won't change anything (even regarding performances). If you want to disallow to import answers you just need to disable the permission to view the correponding survey node.
The abstraction seems quite good to me, at least on that point.
Could you explain the interest to use the LimeSurvey Sync module without the ls_answ module ?
Comment #3
owen barton commentedWe are working on a separate module (which we will contribute, of course) to sync actual survey response data into tables to allow it to be efficiently analysed and charted with views (it would be possible to write views integration against the LimeSurvey tables directly, but they are structured in a way that would make many queries complex and slow).
We can't use ls_answ because it does not make the actual data columns available, and even if it did, storing it in node fields would get complex and slow very soon with large datasets.
We have no need to ever display single survey responses on the site. I do understand that you can enable ls_answ without actually running any sync - nevertheless it requires creating a new content type (that will never be used) for every survey, and also adds a lot of configuration and user interface clutter, and leads to a much more confusing user experience than necessary.
It is also confusing that ls_sync currently exists in a "semi-required" state. There is already a number of places where ls_survey does "if module_exists('ls_answ')" and ls_answ does not explicitly depend on ls_survey. Yet it is currently impossible to use even basic ls_survey functionality with ls_answ disabled.
From an abstraction point of view - if both modules really need to depend on each other, and ls_survey contains code that is really for ls_answ, then I don't see any purpose in actually making them separate modules at all - the code might as well just live in separate .inc files in a single module. I see no architectural requirement for ls_survey to include any ls_answ code whatsoever - ls_answ can simply implement standard Drupal hooks and add in it's own fields/functionality. If in any case it is unable to do this, then the standard pattern would be for ls_survey to provide it's own hook at the integration point, and have ls_answ implement that. Using "if module_exists" is also a possibility, but is really best kept for exceptional and simple cases.
Comment #4
thedut commentedOk, I understand your point of view now.
Disabling the ls_answ module makes more sense. However, you don't need it because you are developing a separate module replacing it : it is not an usual case.
That an interesting feature ! I'm very curious about it.
I totally agree.
I said that the answer content type has to be declared into the ls_answ module but I was wrong concerning Drupal 7 : I explain why here :
The LimeSurvey Sync module was designed first for Drupal6. On Drupal 6, the only way to distinguish the Survey content type and the Answers content type was to set them into disctinct modules, using the $type->module value to detect which content type it was. On Drupal 7, thanks to the new 'base' colomn into the {node_type} table, we could declare both content types into the same module, distinguish them using the $type->base value.
The LimeSurvey Sync includes 3 modules :
- limesurvey_sync (handle the synchronization setting page)
- ls_survey (handle survey content types)
- ls_answ (handle answers).
I have created 3 modules in order to make the code more clear (disctinct features into disctinct folders and modules). but I may keep them into distinct folders without creating distinct modules. It would be a better abstraction.
I may succeed in declaring the Answers content type into the Ls_survey module intead of the ls_answ module (only on the Drupal 7 version).
Your thread happens at the right time : I'm working on a new major version of the LimeSurvey Sync module (7.x-2.0).
For your information, this new version will :
I may include the new module hierarchy into this new major version.
I have not decided yet :
Comment #5
thedut commentedComment #6
thedut commentedComment #7
thedut commentedThe update script from 7.x-1.x to 7.x-2.x will be quite difficult to create, regarding new changes :
- one module instead of 3
- one content type per survey.
I hope I will have time for this on march.
Comment #8
thedut commentedComment #9
thedut commentedHello Owen,
The v7.x-2.0 is available as an alpha.
There is only one module now.
it comes with many improvements.
More informations here.