Skip to content

Instantly share code, notes, and snippets.

@touol
Created April 14, 2020 19:49
Show Gist options
  • Save touol/35268897a594e526e6c5aecc1eb1914c to your computer and use it in GitHub Desktop.
Save touol/35268897a594e526e6c5aecc1eb1914c to your computer and use it in GitHub Desktop.
<div id="testuser-main" class="row">
<script>
{if !$check_ajax}
var _init = [];
{/if}
</script>
<div class="col-md-2">
{if $block_q_number}
{foreach $block_q_number as $q}
<a href="#" class="step-box__item {if $q.curStepCheck}current{/if} {if $q.ansCheck}check{/if}"
onclick="$('#next_step').val({$q.step});$('#UserTestForm').trigger('submit');return false;">
{$q.numberQ}
</a>
{/foreach}
{/if}
</div>
<div class="col-md-8">
<h1>{$test.name}</h1>
<p>{$debug}</p>
{if $curStep == "start"}
{if $test.description}
<h2>Анотация</h2>
<div class="row">{$test.description}</div>
{/if}
{if $test.appeal}
<h2>ОБРАЩЕНИЕ К ПОЛЬЗОВАТЕЛЮ</h2>
<div class="row">{$test.appeal}</div>
{/if}
{if $test.instruction}
<h2>Инструкция</h2>
<div class="row">{$test.instruction}</div>
{/if}
<form id="UserTestForm" action="{if $_modx->resource.id}{$_modx->makeUrl($_modx->resource.id,'',['test_id'=>$.get.test_id,'step'=>'start'])}{/if}" method="POST">
<input type="hidden" name="test_id" value="{$test_id}"/>
<input type="hidden" name="step" value="start"/>
<button type="submit" class="btn btn-info">Начать тестирование</button>
</form>
{elseif $curStep == "finish"}
{if $result_status == 3}
<p>Тест ожидает проверки преподователем!</p>
{else}
<p>Вы набрали {$test_point} баллов{if $test.type == 1} из {$max_point}{/if}. Время теста: {$test_time}с.</p>
{if $test.test_type == 2}
{$_modx->getChunk('tpl.UserTest.OprosSANResult',['check_ajax'=>$check_ajax,'test'=>$test,'catResults'=>$catResults,'cat_history'=>$cat_history])}
{else}
{if $var_passed}
<p>Тест сдан!</p>
{else}
<p>Тест не сдан!</p>
{/if}
<p>Ваш результат теста:</p>
<div class="row">{$var_result}</div>
{if $answer_page_url}
<p><a href="{$answer_page_url}">Просмотреть правильные ответы</a></p>
{/if}
{/if}
<script>
{if !$check_ajax}
onload_af = function() {
{/if}
$('#af_test_point').val('{$test_point}');
$('#af_var_result').val('{$var_result |preg_replace : '~\n~': ''}');
$('#af_test_name').val('{$test.name |preg_replace : '~\n~': ''}');
$('#af_result_id').val('{$result_id}');
$('#af_max_point').val('{$max_point}');
$('#af_cat_email_results').val('{$cat_email_results |preg_replace : '~\n~': ''}');
$('#sendMail').show();
{if !$check_ajax}
};
_init.push(onload_af);
{/if}
</script>
{if $test.use_category}
{$_modx->getChunk('tpl.UserTest.CatResult',['check_ajax'=>$check_ajax,'test'=>$test,'catResults'=>$catResults,'test_point'=>$test_point])}
{/if}
{/if}
{else}
{if $test_url}
<p>Если вы прервали тест, используйте для возврата ссылку: {$test_url}</p>
{/if}
{*$end_test_time} {$test_time*}
{if $end_test_time > 0}
<p>До окончания теста: <span id="getting-started"></span></p>
<script>
{if !$check_ajax}
onload_time = function() {
{/if}
time1 = {$end_test_time}*1000 + Date.now();
$('#getting-started').countdown(time1, function(event) {
$(this).html(event.strftime('%H:%M:%S'));
});
{if !$check_ajax}
};
_init.push(onload_time);
{/if}
</script>
{/if}
<div id="testuser-questions">
{*<p>Вы набрали {$test_point} баллов. Время теста: {$test_time}с.</p>*}
<form id="UserTestForm" action="{if $_modx->resource.id}{$_modx->makeUrl($_modx->resource.id,'',['test_id'=>$.get.test_id])}{/if}" method="POST">
<input type="hidden" name="test_id" value="{$test_id}"/>
{if $enable_cat_child_questions}
{foreach $cats_questions as $cat_qs}
<br>
<div class="row">
<p>Вопрос №{$cat_qs.idx} из {$cat_qs.cat.name}.</p>
<p> {$cat_qs.cat.description}</p>
{foreach $cat_qs.questions as $q}
<div class="row">
{if $q.type == 12} {* Опросник САН *}
{var $qarr = $q.question | split : '##'}
<div class="col-lg-4">
{$qarr.0}
</div>
<div class="col-lg-4 question {if $q.validate}validate{/if}" data-id="{$q.id}" data-type_id="{$q.type}">
{foreach $q.answers as $a}
<div class="opros_san">
{switch $a.type_file}
{case 1}
<img src="{$a.file}" alt="{$a.answer}">
{case 2}
<video src="{$a.file}" controls></video>
{case 3}
<audio controls>
<source src="{$a.file}" type="audio/mpeg">
</audio>
{/switch}
{if $q.answer_id == $a.id}
<label><input name="question[{$q.id}]" type="radio" value="{$a.id}" checked>{$a.answer}</label>
{else}
<label><input name="question[{$q.id}]" type="radio" value="{$a.id}">{$a.answer}</label>
{/if}
</div>
{/foreach}
</div>
<div class="col-lg-4">
{$qarr.1}
</div>
{/if}
</div>
{/foreach}
</div>
{/foreach}
{else}
{foreach $questions as $q}
<br>
<div class="row">
<p>Вопрос {$q.numberQ} из {$q.countQ}.</p>
{if $q.type == 9} {* Селекты в тексте *}
<div class="question {if $q.validate}validate{/if}" data-id="{$q.id}" data-type_id="{$q.type}">{$q.q_str}</div>
{elseif $q.type == 12} {* Опросник САН *}
{var $qarr = $q.question | split : '##'}
<div class="col-lg-4">
{$qarr.0}
</div>
<div class="col-lg-4 question {if $q.validate}validate{/if}" data-id="{$q.id}" data-type_id="{$q.type}">
{foreach $q.answers as $a}
<div class="opros_san">
{switch $a.type_file}
{case 1}
<img src="{$a.file}" alt="{$a.answer}">
{case 2}
<video src="{$a.file}" controls></video>
{case 3}
<audio controls>
<source src="{$a.file}" type="audio/mpeg">
</audio>
{/switch}
{if $q.answer_id == $a.id}
<label><input name="question[{$q.id}]" type="radio" value="{$a.id}" checked>{$a.answer}</label>
{else}
<label><input name="question[{$q.id}]" type="radio" value="{$a.id}">{$a.answer}</label>
{/if}
</div>
{/foreach}
</div>
<div class="col-lg-4">
{$qarr.1}
</div>
{else}
<div class="row">{$q.question}</div>
{switch $q.type_file}
{case 1}
<img src="{$q.file}" alt="{$q.question}">
{case 2}
<video src="{$q.file}" controls></video>
{case 3}
<audio controls>
<source src="{$q.file}" type="audio/mpeg">
</audio>
{/switch}
{*$q | print_r : true*}
{/if}
</div>
<div class="row question {if $q.validate}validate{/if}" data-id="{$q.id}" data-type_id="{$q.type}">
{switch $q.type}
{case 1} {* Одиночный выбор *}
{foreach $q.answers as $a}
<div class="col-lg-4">
{switch $a.type_file}
{case 1}
<img src="{$a.file}" alt="{$a.answer}">
{case 2}
<video src="{$a.file}" controls></video>
{case 3}
<audio controls>
<source src="{$a.file}" type="audio/mpeg">
</audio>
{/switch}
{if $q.answer_id == $a.id}
<label><input name="question[{$q.id}]" type="radio" value="{$a.id}" checked>{$a.answer}</label>
{else}
<label><input name="question[{$q.id}]" type="radio" value="{$a.id}">{$a.answer}</label>
{/if}
</div>
{/foreach}
{case 2} {* Множественный выбор *}
{foreach $q.answers as $a}
<div class="col-lg-4">
{switch $a.type_file}
{case 1}
<img src="{$a.file}" alt="{$a.answer}">
{case 2}
<video src="{$a.file}" controls></video>
{case 3}
<audio controls>
<source src="{$a.file}" type="audio/mpeg">
</audio>
{/switch}
{if $a.check}
<label><input name="question[{$q.id}][]" type="checkbox" value="{$a.id}" checked>{$a.answer}</label>
{else}
<label><input name="question[{$q.id}][]" type="checkbox" value="{$a.id}">{$a.answer}</label>
{/if}
</div>
{/foreach}
{case 3} {* Простой текст *}
<div class="form-group">
<input name="question[{$q.id}]" type="text" value="{$q.answer}" class="form-control">
</div>
{case 4} {* Открытый вопрос *}
<div class="form-group">
<input name="question[{$q.id}]" type="text" value="{$q.answer}" class="form-control">
</div>
{case 5} {* На сопоставление. Простой *}
<div style="float: left; margin-top: 15px; margin-left: 10px">
<ul style="list-style: none;" class="comparison">
{foreach $q.q as $qk => $qv}
<li data-id="{$qk}">{$qv}</li>
{/foreach}
</ul>
</div>
<div style="float: left; margin-top: 15px; margin-left: 10px">
<ul id="sortable-{$q.id}" style="list-style: none;" class="comparison">
{foreach $q.a as $ak => $av}
<li data-id="{$ak}">{$av}</li>
{/foreach}
</ul>
</div>
<input name="question[{$q.id}]" id="ans-{$q.id}" type="hidden" value="{$q.answer}">
<script>
{if !$check_ajax}
onload_sortable_{$q.id} = function() {
{/if}
var el = document.getElementById('sortable-{$q.id}');
var sortable{$q.id} = Sortable.create(el,{
onEnd: function (evt) {
var order{$q.id} = sortable{$q.id}.toArray();
//console.info(order{$q.id});
var ans{$q.id} = document.getElementById('ans-{$q.id}');
ans{$q.id}.value = order{$q.id}.join('|');
},
});
{if !$check_ajax}
};
_init.push(onload_sortable_{$q.id});
{/if}
</script>
{case 6} {* Комбинированный вариант *}
{foreach $q.answers as $a}
<div class="col-lg-4">
{switch $a.type_file}
{case 1}
<img src="{$a.file}" alt="{$a.answer}">
{case 2}
<video src="{$a.file}" controls></video>
{case 3}
<audio controls>
<source src="{$a.file}" type="audio/mpeg">
</audio>
{/switch}
{if $a.check}
<label><input name="question[{$q.id}][]" type="checkbox" value="{$a.id}" checked>{$a.answer}</label>
{else}
<label><input name="question[{$q.id}][]" type="checkbox" value="{$a.id}">{$a.answer}</label>
{/if}
</div>
{/foreach}
<div class="col-lg-4">
{if $q.answers_add.check}
<label>
<input name="question[{$q.id}][ans_add]" type="checkbox" value="" checked> Другое
<input name="question[{$q.id}][ans_add_ans]" type="text" value="{$q.answers_add.ans}" class="form-control">
</label>
{else}
<label>
<input name="question[{$q.id}][ans_add]" type="checkbox" value=""> Другое
<input name="question[{$q.id}][ans_add_ans]" type="text" value="" class="form-control">
</label>
{/if}
</div>
{case 7} {* Таблица чек-боксов *}
<table class="table">
<tbody>
<tr>
{foreach $q.header as $h}
<td>{$h}</td>
{/foreach}
</tr>
{foreach $q.q_childs as $qc}
<tr>
<td>{$qc.question}</td>
{foreach $qc.answers as $a}
<td>
{if $a.check}
<label><input name="question[{$q.id}][{$qc.id}][]" type="checkbox" value="{$a.id}" checked></label>
{else}
<label><input name="question[{$q.id}][{$qc.id}][]" type="checkbox" value="{$a.id}"></label>
{/if}
</td>
{/foreach}
</tr>
{/foreach}
</tbody>
</table>
{case 8} {* Таблица текстовых полей *}
<table class="table">
<tbody>
<tr>
{foreach $q.header as $h}
<td>{$h}</td>
{/foreach}
</tr>
{foreach $q.q_childs as $qc}
<tr>
<td>{$qc.question}</td>
{foreach $qc.answers as $a}
<td>
<div class="answer__textarea-box">
<textarea name="question[{$q.id}][{$qc.id}][{$a.id}]" class="answer__textarea">{$a.ac}</textarea>
</div>
</td>
{/foreach}
</tr>
{/foreach}
</tbody>
</table>
{case 10} {* Комбинированный одиночный выбор *}
{foreach $q.answers as $a}
<div class="col-lg-4">
{switch $a.type_file}
{case 1}
<img src="{$a.file}" alt="{$a.answer}">
{case 2}
<video src="{$a.file}" controls></video>
{case 3}
<audio controls>
<source src="{$a.file}" type="audio/mpeg">
</audio>
{/switch}
{if $a.check}
<label><input name="question[{$q.id}][ans]" type="radio" value="{$a.id}" checked>{$a.answer}</label>
{else}
<label><input name="question[{$q.id}][ans]" type="radio" value="{$a.id}">{$a.answer}</label>
{/if}
</div>
{/foreach}
<div class="col-lg-4">
{if $q.answers_add.check}
<label>
<input name="question[{$q.id}][ans]" type="radio" value="ans_add" checked> Другое
<input name="question[{$q.id}][ans_add_ans]" type="text" value="{$q.answers_add.ans}" class="form-control">
</label>
{else}
<label>
<input name="question[{$q.id}][ans]" type="radio" value="ans_add"> Другое
<input name="question[{$q.id}][ans_add_ans]" type="text" value="" class="form-control">
</label>
{/if}
</div>
{/switch}
</div>
{/foreach}
{/if}
<div class="row">
<input type="hidden" name="step" id="next_step" value="{$nextStep}">
<input type="hidden" name="answer_step" id="answer_step" value="{$curStep}">
<div class="col-lg-4">
{if $prevStep != "start"}
<button type="submit" onclick="$('#next_step').val({$prevStep});return true;" class="btn btn-info">Предудущие вопросы</button>
{/if}
</div>
<div class="col-lg-4 pull-right">
{if $nextStep != "finish"}
<button type="submit" class="btn btn-info">Следующие вопросы</button>
{else}
<button type="submit" class="btn btn-info">Финиш</button>
{/if}
</div>
</div>
</form>
</div>
{/if}
</div>
<div class="col-md-2">
{if $test.customer}
{*<h2>Инструкция</h2>*}
<div class="row">{$test.customer}</div>
{/if}
</div>
{if !$check_ajax}
<script>
window.onload = function()
{
for ( var i in _init )
{
if ( typeof( _init[i] ) == 'function' ) _init[i](); // вызываем подряд все функции из _init
}
}
</script>
{/if}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment