Welcome to the LimeSurvey Community Forum

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

A plugin implementing a custom question type or question theme/rendering

  • tassoman
  • tassoman's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 11 months ago #228312 by tassoman
Your LimeSurvey version: 3.x
==================
Is it possible by plugin to implement a custom question type or expanding a rendering (question theme?) for an existing question type?
I'd like to create a "push button" question, saving an integer.
The question should save as answer how many times you clicked its button.
The button actually, it's a link, with bootstrap button's class.

«All your survey answers are belong to us »

Please Log in to join the conversation.

  • tassoman
  • tassoman's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 11 months ago #228315 by tassoman
I'm digging into it, by reading documentation.

Maybe I can implement a beforeQuestionRender event who is going to render the question type numeric, if some conditions are supported. For example if I have a string inside the question text.. <!-- #MYPLUGINNAME -->

Or maybe I can install a Question theme, during plugin activation ... But in this case I should write SQL queries to get things done . But this part is undocumented, and differs from 5.x and 3.x

«All your survey answers are belong to us »

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 11 months ago - 1 year 11 months ago #228386 by DenisChenu
With plugin :

1. You can add question advanced settings
2. You can update answers
3. You can add JS

A lot of sample : gitlab.com/SondagesPro/QuestionSettingsType

You need (in init)
Code:
$this->subscribe('beforeQuestionRender');
$this->subscribe('newQuestionAttributes');

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 1 year 11 months ago by DenisChenu.

Please Log in to join the conversation.

  • tassoman
  • tassoman's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 11 months ago #228461 by tassoman
Thanks for your reply! I managed to add a switch option to numeric question. Something as "MyPluginBtn" true-false flag.
Now I can't realize how to substitute numeric input widget with a push button thing. The idea is to have an hidden field pretending to be the numeric and the button doing the numeric increment by jquery.
I bet I should hook to beforeQuestionRender hook and filtering two parameters, the numeric field type "N" having MyPluginBtn attribute = 1 
 

«All your survey answers are belong to us »

Please Log in to join the conversation.

  • tassoman
  • tassoman's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 11 months ago #228464 by tassoman
I wrote this as filter for the event. But where's stored question output?
Code:
    public function beforeQuestionRender()
    {
        if ('N' == $this->event->get('type'))
        {
            $qattrs = QuestionAttribute::model()->getQuestionAttributes($this->getEvent()->get('qid'));
            if (true == $qattrs['isMyPdfBtn']) {
                $this->debug('is N and btn');
            }
        }
    }

Maybe inside the event? $this->getEvent()->get('question') ?

«All your survey answers are belong to us »

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 11 months ago #228465 by DenisChenu
Did you look at manual.limesurvey.org/BeforeQuestionRender ?
text : the question text
answers : the complete HTML answers part

And don't use $this->getEvent() , because event can update during your plugin.
$renderEvennt = $this->getEvent();
$renderEvennt->get('qid')

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: tassoman

Please Log in to join the conversation.

  • tassoman
  • tassoman's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 11 months ago #228467 by tassoman
Oh thanks, I forgot about reading event's wiki page
I've read all others events pages

Thank you as usual! So you mean I should "snapshot" the event attribute inside a scoped variable as soon the event gets fired.
I need some refactorings

«All your survey answers are belong to us »

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 10 months ago #228568 by DenisChenu

Thank you as usual! So you mean I should "snapshot" the event attribute inside a scoped variable as soon the event gets fired.

 
Not necessary, but it's better.
If (for example) you save a model : $this->getEvent is afterSave event. If you create a twig : it's another event.

And maybe : if you call a function without event today, maybe there are a new event in some month …
And remind other plugin can create (then update) event too …

Now : i always put my needed event in a var. Because i have the issue … and don't understand what happen after some hours (says ?) of research …

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: tassoman

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose