Welcome to the LimeSurvey Community Forum

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

Custom question attributes?

  • kcivey
  • kcivey's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 8 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
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
12 years 8 months ago #75092 by TMSWhite
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).
The topic has been locked.
  • kcivey
  • kcivey's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
12 years 8 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
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
12 years 8 months ago #75252 by Mazi
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.
More
12 years 3 weeks 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?
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
12 years 3 weeks ago #86557 by Mazi
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.

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.
More
12 years 3 weeks 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()
The topic has been locked.
More
9 years 5 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!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 5 months ago #120079 by tpartner
Replied by tpartner on topic Custom question attributes?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 5 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??
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 5 months ago #120108 by tpartner
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.
More
9 years 5 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.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose