* @version $Id: exercise.lib.php 22247 2009-07-20 15:57:25Z ivantcholakov $ * Modified by Hubert Borderiou 2011-10-21 Question Category */ /** * Code */ class ExerciseLib { /** * Shows a question * * @param int question id * @param bool if true only show the questions, no exercise title * @param bool origin i.e = learnpath * @param int current item from the list of questions * @param int number of total questions * */ public static function showQuestion( $objQuestionTmp, $only_questions = false, $origin = false, $current_item = '', $show_title = true, $freeze = false, $user_choice = array(), $show_comment = false, $exercise_feedback = null, $show_answers = false ) { // Text direction for the current language //$is_ltr_text_direction = api_get_text_direction() != 'rtl'; // Change false to true in the following line to enable answer hinting $debug_mark_answer = $show_answers; //api_is_allowed_to_edit() && false; // Reads question information if (!$objQuestionTmp) { // Question not found return false; } $html = null; $questionId = $objQuestionTmp->id; if ($exercise_feedback != EXERCISE_FEEDBACK_TYPE_END) { $show_comment = false; } $answerType = $objQuestionTmp->selectType(); $pictureName = $objQuestionTmp->selectPicture(); $s = null; // @todo use a formvalidator $form = new FormValidator('question'); $renderer = $form->defaultRenderer(); $form_template = '{content}'; $renderer->setFormTemplate($form_template); if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) { // Question is not a hotspot if (!$only_questions) { $questionDescription = $objQuestionTmp->selectDescription(); if ($show_title) { $html .= Testcategory::getCategoryNamesForQuestion($objQuestionTmp->id); $html .= Display::div($current_item.'. '.$objQuestionTmp->selectTitle(), array('class' => 'question_title')); } if (!empty($questionDescription)) { $html .= Display::div($questionDescription, array('class' => 'question_description')); } } if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) { return null; } $html .= '
'; $s .= $answer_input; $s .= ' | '; $s .= ''; $s .= $comment; $s .= ' | '; $s .= '|
'; $s .= $answer_input; $s .= ' | '; $s .= ''; $s .= $comment; $s .= ' | '; $s .='|
'; $s .= $comment; $s .= ' | '; } $s.='||
'; $s.= $answer_input; $s .= ' | '; $s .= ''; $s .= $comment; $s .= ' | '; $s.= '|
'; $s .= $comment; $s .= ' | '; } $s.='||
';
$parsed_answer = $answer;
$windowId = $questionId.'_'.$lines_count;
//left part questions
$s .= '
'.$lines_count.'. '.$parsed_answer.'
| ';
// middle part (matches selects)
$s .= ' ';
$s .= ' ';
$s .= ' | ';
$s.='';
if (isset($select_items[$lines_count])) {
$s.= '
'.$select_items[$lines_count]['letter'].'. '.$select_items[$lines_count]['answer'].'
';
} else {
$s.=' ';
}
$s .= ' | ';
$s .= '
'; $s.=''.$select_items[$lines_count]['letter'].'.'; $s .= $select_items[$lines_count]['answer']; $s.=" | ';
$parsed_answer = $answer;
$windowId = $questionId.'_'.$numAnswer; //67_293 - 67_294
//left part questions
$s .= '
'.$parsed_answer.'
';
$s .= '';
$s .= '';
if (!empty($answerCorrect) && !empty($selectedValue)) {
$s.= '';
}
if (isset($select_items[$lines_count])) {
$s.= ' ';
$matching_correct_answer++;
$s .= '
'.$select_items[$lines_count]['letter'].'. '.$select_items[$lines_count]['answer'].'
';
} else {
$s.=' ';
}
$lines_count++;
//if the left side of the "matching" has been completely
// shown but the right side still has values to show...
if (($lines_count - 1) == $num_suggestions) {
// if it remains answers to shown at the right side
while (isset($select_items[$lines_count])) {
$s.=''.$select_items[$lines_count]['letter'].'.';
$s .= $select_items[$lines_count]['answer'];
$lines_count++;
}
}
$s .= ' |
'; $html .= $questionDescription; $html .= ' | |||
|