parent
c2352b0999
commit
34133a11a7
@ -1,10 +1,15 @@ |
||||
171,70,67,100 |
||||
221,133,61,100 |
||||
255,235,141,100 |
||||
186,206,151,100 |
||||
210,148,147,100 |
||||
114,88,144,100 |
||||
148,170,208,100 |
||||
186,206,151,100 |
||||
221,133,61,100 |
||||
65,153,176,100 |
||||
114,88,144,100 |
||||
138,166,78,100 |
||||
171,70,67,100 |
||||
69,115,168,100 |
||||
239,210,121,100 |
||||
149,203,233,100 |
||||
2,71,105,100 |
||||
175,215,117,100 |
||||
44,87,0,100 |
||||
222,157,127,100 |
||||
|
@ -0,0 +1,120 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
class ch_multiplechoiceother extends survey_question |
||||
{ |
||||
/** |
||||
* @param array $survey_data |
||||
* @param array $formData |
||||
* |
||||
* @return FormValidator |
||||
*/ |
||||
public function createForm($survey_data, $formData) |
||||
{ |
||||
parent::createForm($survey_data, $formData); |
||||
|
||||
$options = [ |
||||
'horizontal' => get_lang('Horizontal'), |
||||
'vertical' => get_lang('Vertical'), |
||||
]; |
||||
$this->getForm()->addRadio('horizontalvertical', get_lang('DisplayAnswersHorVert'), $options); |
||||
|
||||
$formData['horizontalvertical'] = isset($formData['horizontalvertical']) ? $formData['horizontalvertical'] : 'horizontal'; |
||||
$this->getForm()->setDefaults($formData); |
||||
|
||||
$config = ['ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120']; |
||||
$total = count($formData['answers']); |
||||
|
||||
if (is_array($formData['answers'])) { |
||||
foreach ($formData['answers'] as $key => $value) { |
||||
if ($value === 'other') { |
||||
continue; |
||||
} |
||||
$this->getForm()->addHtmlEditor('answers['.$key.']', null, false, false, $config); |
||||
if ($total > 2) { |
||||
$this->getForm()->addButton("delete_answer[$key]", get_lang('Delete'), 'trash', 'danger'); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (isset($formData['answersid']) && !empty($formData['answersid'])) { |
||||
$counter = 1; |
||||
$total = count($formData['answersid']); |
||||
foreach ($formData['answersid'] as $value) { |
||||
if ($counter === $total) { |
||||
break; |
||||
} |
||||
$this->getForm()->addHidden('answersid[]', $value); |
||||
$counter++; |
||||
} |
||||
} |
||||
|
||||
parent::addRemoveButtons($formData); |
||||
} |
||||
|
||||
/** |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = [], $answers = []) |
||||
{ |
||||
$question = new ch_yesno(); |
||||
$otherId = 0; |
||||
foreach ($questionData['options'] as $key => $option) { |
||||
if ('other' === $option) { |
||||
$otherId = $key; |
||||
} |
||||
} |
||||
|
||||
foreach ($questionData['options'] as &$option) { |
||||
if ($option === 'other') { |
||||
$option = '<p>'.get_lang('SurveyOtherAnswerSpecify').'</p>'; |
||||
} |
||||
} |
||||
$questionId = $questionData['question_id']; |
||||
$question->render($form, $questionData, $answers); |
||||
$form->addHtml( |
||||
'<script> |
||||
$(function() { |
||||
$("input:radio[name=\"question'.$questionId.'\"]").change(function() { |
||||
if ($(this).val() == "'.$otherId.'") { |
||||
$("#other_div_'.$questionId.'").show(); |
||||
} else { |
||||
$("#other_div_'.$questionId.'").hide(); |
||||
$("#other_question'.$questionId.'").val(""); |
||||
} |
||||
}); |
||||
}); |
||||
</script>' |
||||
); |
||||
|
||||
$display = 'display:none'; |
||||
$defaultOtherData = ''; |
||||
if (!empty($answers)) { |
||||
$answers = self::decodeOptionValue($answers); |
||||
if (isset($answers[1])) { |
||||
$display = ''; |
||||
$defaultOtherData = $answers[1]; |
||||
} |
||||
} |
||||
$form->addHtml('<div id="other_div_'.$questionId.'" class="multiple_choice_other" style="'.$display.'">'); |
||||
$element = $form->addText( |
||||
'other_question'.$questionId, |
||||
get_lang('SurveyOtherAnswer'), |
||||
false, |
||||
['id' => 'other_question'.$questionId] |
||||
); |
||||
$form->addHtml('</div>'); |
||||
|
||||
if (!empty($answers) && !empty($defaultOtherData)) { |
||||
$element->setValue($defaultOtherData); |
||||
$element->freeze(); |
||||
} |
||||
} |
||||
|
||||
public static function decodeOptionValue($value) |
||||
{ |
||||
return explode('@:@', $value); |
||||
} |
||||
} |
@ -0,0 +1,85 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
class ch_selectivedisplay extends ch_yesno |
||||
{ |
||||
/** |
||||
* @param array $questionData |
||||
* @param array $answers |
||||
*/ |
||||
public function render(FormValidator $form, $questionData = [], $answers = null) |
||||
{ |
||||
if (is_array($questionData['options'])) { |
||||
$class = 'radio-inline'; |
||||
$labelClass = 'radio-inline'; |
||||
if ($questionData['display'] === 'vertical') { |
||||
$class = 'radio-vertical'; |
||||
} |
||||
|
||||
$name = 'question'.$questionData['question_id']; |
||||
$radioAttributes = [ |
||||
'radio-class' => $class, |
||||
'label-class' => $labelClass, |
||||
'class' => 'survey_selective_input', |
||||
]; |
||||
|
||||
if (!empty($questionData['is_required'])) { |
||||
$radioAttributes['required'] = 'required'; |
||||
} |
||||
|
||||
$form->addRadio( |
||||
$name, |
||||
null, |
||||
$questionData['options'], |
||||
$radioAttributes |
||||
); |
||||
|
||||
if (!empty($answers)) { |
||||
$form->setDefaults([$name => is_array($answers) ? current($answers) : $answers]); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static function getJs() |
||||
{ |
||||
return '<script> |
||||
$(function() { |
||||
var hideQuestion = false; |
||||
$(".survey_question").each(function() { |
||||
var questionClass = $(this).attr("class").trim(); |
||||
if (hideQuestion) { |
||||
$(this).hide(); |
||||
if (questionClass === "survey_question ch_selectivedisplay") { |
||||
$(this).show(); |
||||
} |
||||
} |
||||
if (questionClass === "survey_question ch_selectivedisplay") { |
||||
hideQuestion = true; |
||||
} |
||||
}); |
||||
|
||||
$(".survey_selective_input").on("click", function() { |
||||
var parent = $(this).parent().parent().parent().parent(); |
||||
var next = parent.nextAll(); |
||||
var visible = $(this).attr("data-order") == 1; |
||||
|
||||
next.each(function() { |
||||
if ($(this).attr("class") === "survey_question ch_selectivedisplay") { |
||||
return false; |
||||
} |
||||
if ($(this).attr("class") === "start-survey") { |
||||
return false; |
||||
} |
||||
if (visible) { |
||||
$(this).show(); |
||||
} else { |
||||
$(this).hide(); |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
</script>'; |
||||
} |
||||
} |
Loading…
Reference in new issue