Skip to content

Commit

Permalink
New feature: added a "user question template" selector in Question 'd…
Browse files Browse the repository at this point in the history
…isplay settings'. User will be able to upload a specific template with its own HTML views, Javascript and Css files to the directory "upload/question-template/", and select it in the question attribute.
  • Loading branch information
LouisGac committed Dec 22, 2016
1 parent 17b0e7e commit 8093ee4
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 22 deletions.
26 changes: 12 additions & 14 deletions application/controllers/admin/questions.php
Expand Up @@ -1729,27 +1729,24 @@ private function getQuestionAttribute($type, $qid=0){
public function ajaxquestionattributes()
{

$surveyid = (int) Yii::app()->request->getParam('sid',0);
$qid = (int) Yii::app()->request->getParam('qid',0);
$type = Yii::app()->request->getParam('question_type');
$thissurvey = getSurveyInfo($surveyid);
$surveyid = (int) Yii::app()->request->getParam('sid',0);
$qid = (int) Yii::app()->request->getParam('qid',0);
$type = Yii::app()->request->getParam('question_type');
$thissurvey = getSurveyInfo($surveyid);

if(!$thissurvey) die();

$aLanguages = Survey::model()->findByPk($surveyid)->getAllLanguages();
$aLanguages = Survey::model()->findByPk($surveyid)->getAllLanguages();
$aAttributesWithValues = Question::model()->getAdvancedSettingsWithValues($qid, $type, $surveyid);

uasort($aAttributesWithValues, 'categorySort');

$aAttributesPrepared = array();
foreach ($aAttributesWithValues as $iKey => $aAttribute)
{
if ($aAttribute['i18n'] == false)
foreach ($aAttributesWithValues as $iKey => $aAttribute){
if ($aAttribute['i18n'] == false){
$aAttributesPrepared[] = $aAttribute;
else
{
foreach ($aLanguages as $sLanguage)
{
}else{
foreach ($aLanguages as $sLanguage){
$aAttributeModified = $aAttribute;
$aAttributeModified['name'] = $aAttributeModified['name'] . '_' . $sLanguage;
$aAttributeModified['language'] = $sLanguage;
Expand All @@ -1765,8 +1762,9 @@ public function ajaxquestionattributes()
}
}
}
$aData['bIsActive'] = ($thissurvey['active']=='Y');
$aData['attributedata'] = $aAttributesPrepared;
$aData['bIsActive'] = ($thissurvey['active']=='Y');
$aData['attributedata'] = $aAttributesPrepared;
$aData['aQuestionTemplates'] = \QuestionTemplate::getQuestionTemplateList($type);

$this->getController()->renderPartial('/admin/survey/Question/advanced_settings_view', $aData);
}
Expand Down
10 changes: 2 additions & 8 deletions application/helpers/questionHelper.php
Expand Up @@ -1549,18 +1549,12 @@ public static function getAttributesDefinitions()
"caption"=>gT('Display type')
);

//\Yii::import('application.model.QuestionTemplate');

$aQuestionTemplates = \QuestionTemplate::getQuestionTemplateList();
//$aQuestionTemplates = new \QuestionTemplate();


self::$attributes["question_template"]=array(
"types"=>"15ABCDEFGHIKLMNOPQRSTUWXYZ!:;|",
'category'=>gT('Display'),
'sortorder'=>100,
'inputtype'=>'singleselect',
'options'=>$aQuestionTemplates,
'inputtype'=>'question_template',
'options'=>array(),
'default' => "core",
"help"=>gT('Use a customed question template for this question'),
"caption"=>gT('Question template')
Expand Down
91 changes: 91 additions & 0 deletions application/models/QuestionTemplate.php
@@ -0,0 +1,91 @@
<?php

if (!defined('BASEPATH'))
die('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/


class QuestionTemplate extends CFormModel
{

/**
* Called from admin, to generate the template list for a given question type
*/
static public function getQuestionTemplateList($type)
{
$sUserQTemplateRootDir = Yii::app()->getConfig("userquestiontemplaterootdir");
$aQuestionTemplates = array();

$aQuestionTemplates['core'] = gT('Default');

$aTypeToFolder = self::getTypeToFolder($type);
$sFolderName = $aTypeToFolder[$type];

if ($sUserQTemplateRootDir && is_dir($sUserQTemplateRootDir) ){

$handle = opendir($sUserQTemplateRootDir);
while (false !== ($file = readdir($handle))){
// Maybe $file[0] != "." to hide Linux hidden directory
if (!is_file("$sUserQTemplateRootDir/$file") && $file != "." && $file != ".." && $file!=".svn"){

if (is_dir("$sUserQTemplateRootDir/$file/survey/questions/answer/$sFolderName")){
$templateName = $file;
$aQuestionTemplates[$file] = $templateName;
}
}
}
}
return $aQuestionTemplates;
}

/**
* Correspondance between question type and the view folder name
* Rem: should be in question model. We keep it here for easy access
*/
static public function getTypeToFolder()
{
return array(
"1" => 'arrays/dualscale',
"5" => '5pointchoice',
"A" => 'arrays/5point',
"B" => 'arrays/10point',
"C" => 'arrays/yesnouncertain',
"D" => 'date',
"E" => 'arrays/increasesamedecrease',
"F" => 'arrays/array',
"G" => 'gender',
"H" => 'arrays/column',
"I" => 'language',
"K" => 'multiplenumeric',
"L" => 'listradio',
"M" => 'multiplechoice',
"N" => 'numerical',
"O" => 'list_with_comment',
"P" => 'multiplechoice_with_comments',
"Q" => 'multipleshorttext',
"R" => 'ranking',
"S" => 'shortfreetext',
"T" => 'longfreetext',
"U" => 'longfreetext',
"X" => 'boilerplate',
"Y" => 'yesno',
"!" => 'list_dropdown',
":" => 'arrays/multiflexi',
";" => 'arrays/texts',
"|" => 'file_upload',
"*" => 'equation',
);
}

}
16 changes: 16 additions & 0 deletions application/views/admin/survey/Question/advanced_settings_view.php
Expand Up @@ -131,6 +131,22 @@
<?php } ?>
<?php
break;

// Question template selector
case 'question_template':
echo "<select class='form-control' id='{$aAttribute['name']}' name='{$aAttribute['name']}'>";
foreach($aQuestionTemplates as $sOptionvalue=>$sOptiontext)
{
echo "<option value='{$sOptionvalue}' ";
if ($aAttribute['value']==$sOptionvalue)
{
echo " selected='selected' ";
}
echo ">{$sOptiontext}</option>";
}
echo "</select>";
break;

}
}?>
</div>
Expand Down

0 comments on commit 8093ee4

Please sign in to comment.