- Posts: 2
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Custom question attributes?
- kcivey
- Topic Author
- Offline
- New Member
Less
More
12 years 2 months ago #75091
by kcivey
Custom question attributes? was created by kcivey
I've seen some hints in the documentation that it's possible to create custom question attributes to store metadata associated with a question, but I haven't found any details on how to do this. How can custom attributes be created?
The topic has been locked.
- TMSWhite
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 44
- Thank you received: 15
12 years 2 months ago #75092
by TMSWhite
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
Replied by TMSWhite on topic Custom question attributes?
What sort of question attributes are you wanting?
There is a question_attributes table that can store generic attributes, but it is geared to serving up data from the admin GUI screen. So, this is a convenient way to store attributes if you extend the underlying code without having to modify the data model (questions table). However, these attributes are not exposed at run-time (e.g. within the surveys).
There is also discussion of creating a more modular approach to questions to make it easier for people to add new question types (in future releases of LimeSurvey).
There is a question_attributes table that can store generic attributes, but it is geared to serving up data from the admin GUI screen. So, this is a convenient way to store attributes if you extend the underlying code without having to modify the data model (questions table). However, these attributes are not exposed at run-time (e.g. within the surveys).
There is also discussion of creating a more modular approach to questions to make it easier for people to add new question types (in future releases of LimeSurvey).
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
- Expression Manager (EM):
Documentation
|
Sample Surveys
|
How Tos
|
Show Logic File
|
Upgrading to 1.92+ - Excel Style for Survey Structure Import/Export
The topic has been locked.
- kcivey
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
12 years 2 months ago #75093
by kcivey
Replied by kcivey on topic Custom question attributes?
Yes, I figured I could store data in the question_attributes table (I'm wanting to use it for something external to LimeSurvey), and I not expecting it to be exposed in the surveys. But I'd like to have admins be able to enter it when creating questions. Is there any easy way to include a new attribute in the question editing interface?
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 1 month ago #75252
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Custom question attributes?
This way isn't "easy" because there are several files that have to be edited.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- Fred01
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 1
11 years 6 months ago #86523
by Fred01
Replied by Fred01 on topic Custom question attributes?
Hi @kcivey, don't know if you ever found the answer, but I had the same problem. If you're just looking to add some "inert" attributes that will simply be displayed in the question editor and save to the DB (like question metadata) then it's a pretty simple edit to the PHP.
There is no reference data in the DB on what the valid attributes are. It's all in the code in the QuestionAttributes() function. In 1.92 this is in common_functions.php. In 2.0 it's in application/helpers/common_helper.php.
Here is a typical block from the function, for the maximum characters attribute. It show the question types, what category to display it in on the question form, etc.
$qattributes["maximum_chars"]=array(
"types"=>"STUNQK:;",
'category'=>$clang->gT('Input'),
'sortorder'=>100,
'inputtype'=>'text',
"help"=>$clang->gT('Maximum characters allowed'),
"caption"=>$clang->gT('Maximum characters'));
I wanted to control the number of decimals to display on reports in an outside system that imports the Limesurvey data. So below is the block I added. Just putting it in the function and saving was all that it took to have it show up on the question edit form (in a separate category called Custom) and it saves and retrieve from the DB. Since all attributes are stored in an "EAV" style table there are no DB changes necessary. Again, I'm not looking for this to affect behavior anywhere else in LS, just to be available for export. Also, anytime there is an update it may overwrite the file and you'll need to edit it again.
$qattributes["decimal_display"]=array(
"types"=>"*KN",
'category'=>$clang->gT('Custom'),
'sortorder'=>80,
'inputtype'=>'singleselect',
'options'=>array(0=>$clang->gT('0'),
1=>$clang->gT('0.0'),
2=>$clang->gT('0.00')),
'default'=>0,
"help"=>$clang->gT('Decimal places to display in reports'),
"caption"=>$clang->gT('Report decimal display'));
Any opinions from the developer team on this?
There is no reference data in the DB on what the valid attributes are. It's all in the code in the QuestionAttributes() function. In 1.92 this is in common_functions.php. In 2.0 it's in application/helpers/common_helper.php.
Here is a typical block from the function, for the maximum characters attribute. It show the question types, what category to display it in on the question form, etc.
$qattributes["maximum_chars"]=array(
"types"=>"STUNQK:;",
'category'=>$clang->gT('Input'),
'sortorder'=>100,
'inputtype'=>'text',
"help"=>$clang->gT('Maximum characters allowed'),
"caption"=>$clang->gT('Maximum characters'));
I wanted to control the number of decimals to display on reports in an outside system that imports the Limesurvey data. So below is the block I added. Just putting it in the function and saving was all that it took to have it show up on the question edit form (in a separate category called Custom) and it saves and retrieve from the DB. Since all attributes are stored in an "EAV" style table there are no DB changes necessary. Again, I'm not looking for this to affect behavior anywhere else in LS, just to be available for export. Also, anytime there is an update it may overwrite the file and you'll need to edit it again.
$qattributes["decimal_display"]=array(
"types"=>"*KN",
'category'=>$clang->gT('Custom'),
'sortorder'=>80,
'inputtype'=>'singleselect',
'options'=>array(0=>$clang->gT('0'),
1=>$clang->gT('0.0'),
2=>$clang->gT('0.00')),
'default'=>0,
"help"=>$clang->gT('Decimal places to display in reports'),
"caption"=>$clang->gT('Report decimal display'));
Any opinions from the developer team on this?
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
11 years 6 months ago #86557
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Custom question attributes?
Thanks for these detailed instructions, Fred.
The approach is absolutely correct, but if you want to use a question attribute which is used within a survey, e. g. to manipulate how certain question type(s) are styled, you also need to load the question attribute data.
This is done at "qanda.php" (Limesurvey 1.92 and previous) where you can find a function for each question type, like "do_list_radio()". You have to add such attribute related code to all question types listed at the "types" setting.
The approach is absolutely correct, but if you want to use a question attribute which is used within a survey, e. g. to manipulate how certain question type(s) are styled, you also need to load the question attribute data.
This is done at "qanda.php" (Limesurvey 1.92 and previous) where you can find a function for each question type, like "do_list_radio()". You have to add such attribute related code to all question types listed at the "types" setting.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- Fred01
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 1
11 years 6 months ago #86622
by Fred01
Replied by Fred01 on topic Custom question attributes?
Thanks Marcel. In my case I'm not expecting the new attributes to affect anything in the survey presentation so I didn't add anything to qanda.php. I just want them to be available for export (and to show up in the fieldmap).
I did test that the following work correctly.
- Can add new attributes to q_attribute function in LS or LS2 and the question edit form works correctly
- Can assign existing attributes to additional question types (eg, making prefix an attribute of equations)
- Question works normally for survey taker, new attribute ignored (since I didn't change qanda.php)
- Question attributes export correctly in create_fieldmap()
I did test that the following work correctly.
- Can add new attributes to q_attribute function in LS or LS2 and the question edit form works correctly
- Can assign existing attributes to additional question types (eg, making prefix an attribute of equations)
- Question works normally for survey taker, new attribute ignored (since I didn't change qanda.php)
- Question attributes export correctly in create_fieldmap()
The topic has been locked.
- garvsaxena
- Offline
- Junior Member
Less
More
- Posts: 30
- Thank you received: 0
8 years 11 months ago #120066
by garvsaxena
Replied by garvsaxena on topic Custom question attributes?
hi all,
I want to create a new custom question type for our survey, i need a textbox, listbox both in a multiple array format just like a table. can anyone help me out its very urjent!
I want to create a new custom question type for our survey, i need a textbox, listbox both in a multiple array format just like a table. can anyone help me out its very urjent!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
8 years 11 months ago #120079
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Custom question attributes?
Have a look at this workaround -
manual.limesurvey.org/Workarounds:_Quest...stion_types_in_array
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- garvsaxena
- Offline
- Junior Member
Less
More
- Posts: 30
- Thank you received: 0
8 years 11 months ago #120086
by garvsaxena
Replied by garvsaxena on topic Custom question attributes?
It works good, thanks tpartner!!
I have one more question that if we want to Perform Sum on two numeric inputs and display the results in the 3rd input box but in the same question, then what should I do??
I have one more question that if we want to Perform Sum on two numeric inputs and display the results in the 3rd input box but in the same question, then what should I do??
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
8 years 11 months ago #120108
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Custom question attributes?
Why do you need the sum in a third input? You can use Expression Manager to pipe the sum into text.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- garvsaxena
- Offline
- Junior Member
Less
More
- Posts: 30
- Thank you received: 0
8 years 11 months ago #120113
by garvsaxena
Replied by garvsaxena on topic Custom question attributes?
Ok got it..! I think this should solve my problem. But suppose I have a question with the ID = GE-1, and has options SQ001, SQ002, SQ003 and SQ004. Now we have to do that show the sum of SQ001 + SQ002 + SQ003 will display in the SQ004.
Please guide me the Expression and Relevance equation for the thing I want to achieve.
Please guide me the Expression and Relevance equation for the thing I want to achieve.
The topic has been locked.