- Posts: 111
- Thank you received: 20
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How to access a plugins survey setting?
- orvil
- Topic Author
- Offline
- Premium Member
Less
More
6 years 1 month ago #164885
by orvil
Best regards/Beste Grüße,
O. Villani
How to access a plugins survey setting? was created by orvil
Hi,
some special question this time, could not find a pattern in the manual.
Background: plugins can have settings on
- a global level (valid for all surveys),
- on survey level (valid for one survey) and
- on question level (the usual way)
Meanwhile I found examples how to set and read these settings for global and question level and how to set on survey level.
But unfortuantely I cannot find an example working for LS 3.x how to read the settings for survey level.
Here is an theoretical example - you will find the missing code in function beforeQuestionRender() where $message3 is created.
Any idea how to get the corresponding code for $message3 ?
Thanks in advance
some special question this time, could not find a pattern in the manual.
Background: plugins can have settings on
- a global level (valid for all surveys),
- on survey level (valid for one survey) and
- on question level (the usual way)
Meanwhile I found examples how to set and read these settings for global and question level and how to set on survey level.
But unfortuantely I cannot find an example working for LS 3.x how to read the settings for survey level.
Here is an theoretical example - you will find the missing code in function beforeQuestionRender() where $message3 is created.
Code:
<?php class someTest extends PluginBase { // some code skipped // settings on global level protected $settings = array( 'scriptActivate' => array( 'type' => 'checkbox', 'label' => 'Activate/deactivate script execution for all surveys', 'default' => '1', ) ) // settings on survey level public function beforeSurveySettings() { $event = $this->event; $event->set("surveysettings.{$this->id}", array( 'name' => get_class($this), 'settings' => array( 'scriptsActivate'=>array( 'type'=>'boolean', 'label'=>'Activate script execution for this survey', 'help'=>'If this switch is off no script will be executed in this survey.', 'current' => 1, ) ) )); } // settings on question level public function newQuestionAttributes() { $event = $this->event; $questionAttributes = array ( 'scriptActivate' => array( 'types' => '15ABCDEFGHIKLMNOPQRSTUWXYZ!:;|*', /* all question types */ 'category' => gT('someTest'), 'sortorder' => 1, 'inputtype' => 'switch', 'caption' => 'Activate script execution', 'default' => '0', ) ) } // some code skipped /** * now use the attributes e.g. in question rendering */ public function beforeQuestionRender() { // global level $message1 = "global settings: " . $this->get('scriptActivate',null,null,$this->settings['scriptActivate']['default']) . '<br />'; // question level $aAttributes=QuestionAttribute::model()->getQuestionAttributes($this->getEvent()->get('qid')); $message2 = "question settings: " . $aAttributes["scriptActivate"] . '<br />'; // survey level ??? //$message3 = "survey settings: " . // SOME HELP REQUIRED - THANKS!!! } }
Any idea how to get the corresponding code for $message3 ?
Thanks in advance
Best regards/Beste Grüße,
O. Villani
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
6 years 1 month ago #165024
by DenisChenu
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.
Replied by DenisChenu on topic How to access a plugins survey setting?
In beforeQuestionRender (in 2.74, maybe must fix it for 3.4) : you have qid in
$this->getEvent()->get('surveyId'); : manual.limesurvey.org/BeforeQuestionRender
To get a settings for Survey model with sid:
$this->get('scriptActivate','Survey',$this->getEvent()->get('surveyId'),$this->settings);
the last option (default) is null by default, like the object and the object_id.
$this->get('scriptActivate') : are same than $this->get('scriptActivate',null,null,null);
$this->getEvent()->get('surveyId'); : manual.limesurvey.org/BeforeQuestionRender
To get a settings for Survey model with sid:
$this->get('scriptActivate','Survey',$this->getEvent()->get('surveyId'),$this->settings);
the last option (default) is null by default, like the object and the object_id.
$this->get('scriptActivate') : are same than $this->get('scriptActivate',null,null,null);
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: orvil
The topic has been locked.
- orvil
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 111
- Thank you received: 20
6 years 1 month ago - 6 years 1 month ago #165039
by orvil
Best regards/Beste Grüße,
O. Villani
Replied by orvil on topic How to access a plugins survey setting?
THX! Now I know what I will do today evening
Best regards/Beste Grüße,
O. Villani
Last edit: 6 years 1 month ago by orvil.
The topic has been locked.
- orvil
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 111
- Thank you received: 20
6 years 1 month ago - 6 years 1 month ago #165100
by orvil
Best regards/Beste Grüße,
O. Villani
Replied by orvil on topic How to access a plugins survey setting?
Hi Denis,
tried this
but as a result I always get the LS global settings, not these from the survey (simpe plugins) itself.
What I found is:
there is a model for QuestionAttribute(s) in /application/models/QuestionAttribute.php with a getter function getQuestionAttributes($iQuestionID, $sLanguage = null)
So its easy to get the attributes array for question level by
$aAttributes = QuestionAttribute::model()->getQuestionAttributes($this->getEvent()->get('qid'));
But I cannot find a similar model and getter function - this would be logical - to get attributes on survey level.
Maybe I can't find them? Maybe this is not yet implemented in a similar way?
tried this
$this->getEvent()->get('surveyId') is working fine,DenisChenu wrote:
$this->get('scriptActivate','Survey',$this->getEvent()->get('surveyId'),$this->settings);
but as a result I always get the LS global settings, not these from the survey (simpe plugins) itself.
What I found is:
there is a model for QuestionAttribute(s) in /application/models/QuestionAttribute.php with a getter function getQuestionAttributes($iQuestionID, $sLanguage = null)
So its easy to get the attributes array for question level by
$aAttributes = QuestionAttribute::model()->getQuestionAttributes($this->getEvent()->get('qid'));
But I cannot find a similar model and getter function - this would be logical - to get attributes on survey level.
Maybe I can't find them? Maybe this is not yet implemented in a similar way?
Best regards/Beste Grüße,
O. Villani
Last edit: 6 years 1 month ago by orvil.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
6 years 1 month ago #165168
by DenisChenu
Hope it's not a new LS issue
See gitlab.com/SondagesPro/extraRegisterPass...terPassword.php#L190 for example or gitlab.com/SondagesPro/getQuestionOrder/...estionOrder.php#L103
I use it a lot before 3.0, but didn't test it in 3.X
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.
Replied by DenisChenu on topic How to access a plugins survey setting?
? This is really strange ????orvil wrote: Hi Denis,
tried this
$this->getEvent()->get('surveyId') is working fine,DenisChenu wrote:
$this->get('scriptActivate','Survey',$this->getEvent()->get('surveyId'),$this->settings);
but as a result I always get the LS global settings, not these from the survey (simpe plugins) itself.
Hope it's not a new LS issue
See gitlab.com/SondagesPro/extraRegisterPass...terPassword.php#L190 for example or gitlab.com/SondagesPro/getQuestionOrder/...estionOrder.php#L103
I use it a lot before 3.0, but didn't test it in 3.X
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 topic has been locked.