- Posts: 30
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
public function actionIndex($surveyId) { if (!Permission::model()->hasSurveyPermission($surveyId, 'tokens', 'read')) { throw new CHttpException(403, gT("You do not have permission to access this page.")); } $surveyId = (int) $surveyId; $survey = Survey::model()->findByPk($surveyId); $tkcount = Token::model($surveyId)->count(); $tokensList = Token::model($surveyId)->summary(); $allAttributes = Survey::model()->findByPk($surveyId)->getTokenAttributes(); $tokenAttributes = array_keys($this->getTokensAttributeList($surveyId,'tokens.', true)); if ($survey->hasTokensTable) { $content = "There are ".$tkcount ." Tokens in the database for this survey".$tokenAttributes; } return $content; }
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Of course you can write your own short php script to query the "lime_tokens_[SurveyId]".Can’t I get the tokens of a survey with a short script in a plug-in or with MySQL query e. g. Select?
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Plugin or API ?Is there a way to connect to the database in the plugin-code without entering the database user and password?
Want to use something like:
$sql = 'SELECT token FROM lime_tokens_[surveyId]';
Please Log in to join the conversation.
$this->subscribe('beforeToolsMenuRender'); $this->subscribe('pTsIndex'); $this->subscribe('pTsCreate');
public function pTsIndex($surveyId) { if (!Permission::model()->hasSurveyPermission($surveyId, 'tokens', 'read')) { throw new CHttpException(403, gT("You do not have permission to access this page.")); } $surveyId = (int) $surveyId; $survey = Survey::model()->findByPk($surveyId); $tkcount = Token::model($surveyId)->count(); if (!$survey->hasTokensTable) { // If no tokens table exists $this->newtokentable($iSurveyId); } Yii::app()->loadHelper("surveytranslator"); if ($survey->hasTokensTable) { $content = "There are a lot of Tokens in the database for this survey<br/> <label for='ssid' class='control-label'>Umfrage-ID</label> <input type='text' class='form-control' id='ssid' name='ssid' placeholder='$surveyId' readonly> <label for='stitle' class='control-label'>Titel</label> <input type='text' class='form-control' id='stitle' name='stitle' readonly> <label for='count_tokens' class='control-label'>Anzahl TANs</label> <input type='text' class='form-control' id='scount_tokens' name='scount_tokens' placeholder='$tkcount' readonly> <label for='count_tokens' class='control-label'>Anfang</label> <input type='text' class='form-control' id='sstartdate' name='sstartdate' readonly> <label for='count_tokens' class='control-label'>Ende</label> <input type='text' class='form-control' id='sexpires' name='sexpires' readonly> <form id='tokenForm' action='pluginhelper?sa=printAction&surveyId=$surveyId'> <input type='text' class='form-control' id='stokencount' name='stokencount' placeholder='Anzahl'> <input type='submit' id='stokenButton' class='btn btn-primary'>Create Tokens</button> </form>"; } if( isset($_POST['button']) ) { $content = "ELSE TEST"; } return $content; }
public function pTsCreate($surveyId) { if (!Permission::model()->hasSurveyPermission($surveyId, 'tokens', 'read')) { throw new CHttpException(403, gT("You do not have permission to access this page.")); } $surveyId = (int) $surveyId; $stokencount = $_GET["stokencount"]; for ($i = 0; $i < $stokencount; $i++) { $oToken = Token::create($surveyId); $oToken->setAttributes(Yii::app()->getRequest()->getParam('tokenattribute')); //$resultToken = $oToken->save(); $oToken->generateToken(); $oToken->save(); } return "It works: $surveyId $stokencount $oToken->token"; }
Please Log in to join the conversation.
Please Log in to join the conversation.