public function DDLinesResponse::getReportFormResponse in Quiz 8.4
Get the response part of the report form
Parameters
$showpoints:
$showfeedback:
$allow_scoring:
Return value
FAPI form array holding the response part
Overrides QuizQuestionResponse::getReportFormResponse
File
- question_types/
quiz_ddlines/ lib/ Drupal/ quiz_ddlines/ DDLinesResponse.php, line 118
Class
- DDLinesResponse
- Extension of QuizQuestionResponse
Namespace
Drupal\quiz_ddlinesCode
public function getReportFormResponse($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
// Have to do node_load, since quiz does not do this. Need the field_image...
// print_r($this->question->{'field_image'}->getValue()); exit;
//$img_field = field_get_items(node_load($this->question->id()), 'field_image');
//$img_rendered = theme('image', array('path' => image_style_url('large',$img_field[0]['uri'])));
$image_path = base_path() . drupal_get_path('module', 'quiz_ddlines') . '/theme/images/';
$html = '<h3>' . t('Your answers') . '</h3>';
$html .= '<div class="icon-descriptions"><div><img src="' . $image_path . 'icon_ok.gif">' . t('Means alternative is placed on the correct spot') . '</div>';
$html .= '<div><img src="' . $image_path . 'icon_wrong.gif">' . t('Means alternative is placed on the wrong spot, or not placed at all') . '</div></div>';
$html .= '<div class="quiz-ddlines-user-answers" id="' . $this->question
->id() . '">';
//$html .= $img_rendered;
$html .= '</div>';
$html .= '<h3>' . t('Correct answers') . '</h3>';
$html .= '<div class="quiz-ddlines-correct-answers" id="' . $this->question
->id() . '">';
//$html .= $img_rendered;
$html .= '</div>';
// No form to put things in, are therefore using the js settings instead
$settings = array();
$correct_id = "correct-{$this->question->id()}";
$settings[$correct_id] = json_decode($this->question->ddlines_elements);
$elements = $settings[$correct_id]->elements;
// Convert the user's answers to the same format as the correct answers
$answers = clone $settings[$correct_id];
// Keep everything except the elements:
$answers->elements = array();
$elements_answered = array();
foreach ($this->user_answers as $label_id => $hotspot_id) {
if (!isset($hotspot_id)) {
continue;
}
// Find correct answer:
$element = array(
'feedback_wrong' => '',
'feedback_correct' => '',
'color' => $this
->getElementColor($elements, $label_id),
);
$label = $this
->getLabel($elements, $label_id);
$hotspot = $this
->getHotspot($elements, $hotspot_id);
if (isset($hotspot)) {
$elements_answered[] = $hotspot->id;
$element['hotspot'] = $hotspot;
}
if (isset($label)) {
$elements_answered[] = $label->id;
$element['label'] = $label;
}
$element['correct'] = $this
->isAnswerCorrect($elements, $label_id, $hotspot_id);
$answers->elements[] = $element;
}
// Need to add the alternatives not answered by the user.
// Create dummy elements for these:
foreach ($elements as $el) {
if (!in_array($el->label->id, $elements_answered)) {
$element = array(
'feedback_wrong' => '',
'feedback_correct' => '',
'color' => $el->color,
'label' => $el->label,
);
$answers->elements[] = $element;
}
if (!in_array($el->hotspot->id, $elements_answered)) {
$element = array(
'feedback_wrong' => '',
'feedback_correct' => '',
'color' => $el->color,
'hotspot' => $el->hotspot,
);
$answers->elements[] = $element;
}
}
$settings["answers-{$this->question->id()}"] = $answers;
$settings['mode'] = 'result';
$settings['execution_mode'] = $this->question->execution_mode;
$settings['hotspot']['radius'] = $this->question->hotspot_radius;
// Image path:
$settings['quiz_imagepath'] = base_path() . drupal_get_path('module', 'quiz_ddlines') . '/theme/images/';
drupal_add_js(array(
'quiz_ddlines' => $settings,
), 'setting');
_quiz_ddlines_add_js_and_css();
return array(
'#markup' => $html,
);
}