本文整理汇总了PHP中Answer::getRealAnswerIdFromList方法的典型用法代码示例。如果您正苦于以下问题:PHP Answer::getRealAnswerIdFromList方法的具体用法?PHP Answer::getRealAnswerIdFromList怎么用?PHP Answer::getRealAnswerIdFromList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Answer
的用法示例。
在下文中一共展示了Answer::getRealAnswerIdFromList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createAnswersForm
/**
* function which redifines Question::createAnswersForm
* @param \FormValidator instance
*/
public function createAnswersForm($form)
{
$defaults = array();
$a_weightings = null;
if (!empty($this->id)) {
$objAnswer = new Answer($this->id);
// the question is encoded like this.
// [A] B [C] D [E] F::10,10,10@1
// number 1 before the "@" means that is a switchable fill in blank question
// [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
// means that is a normal fill blank question
$answer_id = $objAnswer->getRealAnswerIdFromList(1);
$pre_array = explode('::', $objAnswer->selectAnswer($answer_id));
//make sure we only take the last bit to find special marks
$sz = count($pre_array);
$is_set_switchable = explode('@', $pre_array[$sz - 1]);
if ($is_set_switchable[1]) {
$defaults['multiple_answer'] = 1;
} else {
$defaults['multiple_answer'] = 0;
}
//take the complete string except after the last '::'
$defaults['answer'] = '';
for ($i = 0; $i < $sz - 1; $i++) {
$defaults['answer'] .= $pre_array[$i];
}
$a_weightings = explode(',', $is_set_switchable[0]);
} else {
$defaults['answer'] = get_lang('DefaultTextInBlanks');
}
// javascript
echo '<script>
function processFields(answer) {
var blanks = answer.match(/\\[[^\\]]*\\]/g);
var fields = "<div class=\\"control-group\\"><label class=\\"control-label\\">' . get_lang('Weighting') . '</label><div class=\\"controls\\"><table>";
if (blanks!=null) {
for (i=0 ; i<blanks.length ; i++){
if (document.getElementById("weighting["+i+"]")) {
value = document.getElementById("weighting["+i+"]").value;
} else {
value = "10";
}
fields += "<tr><td>"+blanks[i]+"</td><td><input style=\\"margin-left: 0em;\\" size=\\"5\\" value=\\""+value+"\\" type=\\"text\\" id=\\"weighting["+i+"]\\" name=\\"weighting["+i+"]\\" /></td></tr>";
}
document.getElementById("blanks_weighting").innerHTML = fields + "</table></div></div>";
}
}
function updateBlanks() {
var answer = "";
var editor = CKEDITOR.instances["answer"];
if (editor) {
editor.on("instanceReady", function(){
answer = editor.getData();
processFields(answer);
this.document.on("keyup", function() {
answer = editor.getData();
processFields(answer);
});
});
} else {
field = document.getElementById("answer");
answer = field.value;
processFields(answer);
}
';
if (count($a_weightings) > 0) {
foreach ($a_weightings as $i => $weighting) {
echo '$("#weighting[' . $i . ']").attr("value", "' . $weighting . '");';
}
}
echo '
}
window.onload = updateBlanks;
</script>';
// answer
$form->addElement('label', null, '<br /><br />' . get_lang('TypeTextBelow') . ', ' . get_lang('And') . ' ' . get_lang('UseTagForBlank'));
$form->addElement('html_editor', 'answer', Display::return_icon('fill_field.png'), 'id="answer" cols="122" rows="6" onkeyup="javascript: updateBlanks(this);"', array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '350'));
$form->addRule('answer', get_lang('GiveText'), 'required');
$form->addRule('answer', get_lang('DefineBlanks'), 'regex', '/\\[.*\\]/');
//added multiple answers
$form->addElement('checkbox', 'multiple_answer', '', get_lang('FillInBlankSwitchable'));
$form->addElement('html', '<div id="blanks_weighting"></div>');
// setting the save button here and not in the question class.php
$form->addElement('style_submit_button', 'submitQuestion', $this->submitText, 'class="' . $this->submitClass . '"');
if (!empty($this->id)) {
$form->setDefaults($defaults);
} else {
if ($this->isContent == 1) {
$form->setDefaults($defaults);
}
}
}
示例2: createAnswersForm
/**
* function which redifines Question::createAnswersForm
* @param the formvalidator instance
* @param the answers number to display
*/
function createAnswersForm($form)
{
// getting the exercise list
$obj_ex = $this->exercise;
$editor_config = array('ToolbarSet' => 'TestProposedAnswer', 'Width' => '100%', 'Height' => '125');
//this line define how many question by default appear when creating a choice question
$nb_answers = isset($_POST['nb_answers']) ? (int) $_POST['nb_answers'] : 3;
// The previous default value was 2. See task #1759.
$nb_answers += isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0);
/*
Types of Feedback
$feedback_option[0]=get_lang('Feedback');
$feedback_option[1]=get_lang('DirectFeedback');
$feedback_option[2]=get_lang('NoFeedback');
*/
$feedback_title = '';
$comment_title = '';
if ($obj_ex->selectFeedbackType() == 0) {
$comment_title = '<th>' . get_lang('Comment') . '</th>';
} elseif ($obj_ex->selectFeedbackType() == 1) {
$editor_config['Width'] = '250';
$editor_config['Height'] = '110';
$comment_title = '<th width="500" >' . get_lang('Comment') . '</th>';
$feedback_title = '<th width="350px" >' . get_lang('Scenario') . '</th>';
}
$html = '<table class="data_table">
<tr style="text-align: center;">
<th width="10px">
' . get_lang('Number') . '
</th>
<th width="10px" >
' . get_lang('True') . '
</th>
<th width="50%">
' . get_lang('Answer') . '
</th>
' . $comment_title . '
' . $feedback_title . '
<th width="60px">
' . get_lang('Weighting') . '
</th>
</tr>';
$form->addElement('label', get_lang('Answers') . '<br />' . Display::return_icon('fill_field.png'), $html);
$defaults = array();
$correct = 0;
if (!empty($this->id)) {
$answer = new Answer($this->id);
$answer->read();
if (count($answer->nbrAnswers) > 0 && !$form->isSubmitted()) {
$nb_answers = $answer->nbrAnswers;
}
}
$temp_scenario = array();
if ($nb_answers < 1) {
$nb_answers = 1;
Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
}
if ($_GET['editQuestion']) {
//fixing $nb_answers
$new_list = array();
$count = 1;
if (isset($_POST['lessAnswers'])) {
if (!isset($_SESSION['less_answer'])) {
$_SESSION['less_answer'] = $this->id;
$nb_answers--;
}
}
for ($k = 1; $k <= $nb_answers; ++$k) {
$answer_id = $answer->getRealAnswerIdFromList($k);
if ($answer->position[$answer_id] != '666') {
$new_list[$count] = $count;
$count++;
}
}
} else {
for ($k = 1; $k <= $nb_answers; ++$k) {
$new_list[$k] = $k;
}
}
$i = 1;
//for ($k = 1 ; $k <= $real_nb_answers; $k++) {
foreach ($new_list as $key) {
$i = $key;
$form->addElement('html', '<tr>');
$answer_id = $answer->getRealAnswerIdFromList($i);
if (is_object($answer)) {
if ($answer->position[$answer_id] == 666) {
//we set nothing
} else {
if ($answer->correct[$answer_id]) {
$correct = $i;
}
$answer_result = $answer->answer[$answer_id];
$weight_result = Text::float_format($answer->weighting[$answer_id], 1);
if ($nb_answers == $i) {
//.........这里部分代码省略.........
示例3: manageAnswers
//.........这里部分代码省略.........
}
}
break;
case HOT_SPOT_ORDER:
ExerciseShowFunctions::display_hotspot_order_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment);
break;
case DRAGGABLE:
case MATCHING:
//if ($origin != 'learnpath') {
echo '<tr>';
echo '<td>' . $answer_matching[$answerId] . '</td><td>' . $user_answer . ' / <b><span style="color: #008000;">' . $answer_matching[$answerCorrect] . '</span></b></td>';
echo '</tr>';
//}
break;
}
}
}
$counter++;
}
// end for that loops over all answers of the current question
if ($debug) {
error_log('<-- end answer loop -->');
}
$final_answer = true;
foreach ($real_answers as $my_answer) {
if (!$my_answer) {
$final_answer = false;
}
}
//we add the total score after dealing with the answers
if ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
if ($final_answer) {
//getting only the first score where we save the weight of all the question
$answerWeighting = $objAnswerTmp->selectWeighting($objAnswerTmp->getRealAnswerIdFromList(1));
$questionScore += $answerWeighting;
$totalScore += $answerWeighting;
}
}
//Fixes multiple answer question in order to be exact
if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
$diff = @array_diff($answer_correct_array, $real_answers);
/*
* All good answers or nothing works like exact
$counter = 1;
$correct_answer = true;
foreach ($real_answers as $my_answer) {
if ($debug) error_log(" my_answer: $my_answer answer_correct_array[counter]: ".$answer_correct_array[$counter]);
if ($my_answer != $answer_correct_array[$counter]) {
$correct_answer = false;
break;
}
$counter++;
} */
if ($debug) {
error_log("answer_correct_array: " . print_r($answer_correct_array, 1) . "");
error_log("real_answers: " . print_r($real_answers, 1) . "");
}
// This makes the result non exact
if (!empty($diff)) {
//$questionScore = 0;
}
}
$extra_data = array('final_overlap' => $final_overlap, 'final_missing' => $final_missing, 'final_excess' => $final_excess, 'overlap_color' => $overlap_color, 'missing_color' => $missing_color, 'excess_color' => $excess_color, 'threadhold1' => $threadhold1, 'threadhold2' => $threadhold2, 'threadhold3' => $threadhold3);
if ($from == 'exercise_result') {
// if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0)
// TODO Change this, because it is wrong to show the user some results that haven't been stored in the database yet