Created
July 16, 2016 10:21
-
-
Save Shnoulle/f959ffba582a304bf13c110094dad996 to your computer and use it in GitHub Desktop.
Adding an attribute by plugins (Solution 2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* extend admin statitics with own controller extending the LS core controller | |
* | |
* @author Denis Chenu <denis@sondages.pro> | |
* @copyright 2016 Denis Chenu <http://www.sondages.pro> | |
* @license WTFPL | |
* @version 0.0.0 | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
*/ | |
class addAnAttribute extends PluginBase | |
{ | |
protected $storage = 'DbStorage'; | |
static protected $name = 'addAnAttribute'; | |
static protected $description = 'Add an attribute for any question'; | |
public function init() | |
{ | |
$this->subscribe('newQuestionAttributes'); | |
$this->subscribe('beforeQuestionRender'); | |
} | |
public function newQuestionAttributes() | |
{ | |
$event = $this->getEvent(); | |
$questionAttributes = array( | |
'exampleOne'=>array( | |
"types"=>"L", | |
'category'=>gT('Other'), | |
'sortorder'=>1, | |
'inputtype'=>'text', | |
'default'=>'', | |
"help"=>'An example for text.', | |
"caption"=>'A text attribute' | |
), | |
'exampleTwo'=>array( | |
"types"=>"L", | |
'category'=>gT('Other'), | |
'sortorder'=>2, | |
'inputtype'=>'singleselect', | |
'options'=>array( | |
0=>gT('No'), | |
1=>gT('No'), | |
), | |
'default'=>0, | |
"help"=>'An example for singleselect.', | |
"caption"=>'A text attribute' | |
), | |
); | |
$event->append('questionAttributes', $questionAttributes); | |
} | |
public function beforeQuestionRender() | |
{ | |
$oAttributeOne=QuestionAttribute::model()->find("qid=:qid AND attribute=:attribute",array(":qid"=>$oEvent->get('qid'),":attribute"=>"exampleOne")); | |
$oAttributeTwo=QuestionAttribute::model()->find("qid=:qid AND attribute=:attribute",array(":qid"=>$oEvent->get('qid'),":attribute"=>"exampleTwo")); | |
/* OR */ | |
$aAttributes=QuestionAttribute::model()->getQuestionAttributes($oEvent->get('qid')); | |
$soAttributeOne=$aAttributes["exampleOne"]; | |
$soAttributeTwo=$aAttributes["exampleTwo"]; | |
/** | |
* Do something | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment