From 3932254d2e71a00bd03e327ae87b25887cbfc12c Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 23 Mar 2017 17:25:03 -0500 Subject: [PATCH] Remove unused function around exercise.class.php - refs BT#10892 --- main/exercise/exercise.class.php | 879 ------------------------------- 1 file changed, 879 deletions(-) diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index 4e61021174..ad02b271ce 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -6921,885 +6921,6 @@ class Exercise } } - /** - * Shows a question - * @param Question $objQuestionTmp - * @param bool $only_questions if true only show the questions, no exercise title - * @param bool $origin origin i.e = learnpath - * @param string $current_item current item from the list of questions - * @param bool $show_title - * @param bool $freeze - * @param array $user_choice - * @param bool $show_comment - * @param null $exercise_feedback - * @param bool $show_answers - * @param null $modelType - * @param bool $categoryMinusOne - * @return bool|null|string - */ - public function showQuestion( - Question $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, - $modelType = null, - $categoryMinusOne = true - ) { - // Text direction for the current language - // 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; - $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) { - $categoryName = TestCategory::getCategoryNamesForQuestion($objQuestionTmp->id, null, true, $categoryMinusOne); - $html .= $categoryName; - $html .= Display::div($current_item.'. '.$objQuestionTmp->selectTitle(), array('class' => 'question_title')); - if (!empty($questionDescription)) { - $html .= Display::div($questionDescription, array('class' => 'question_description')); - } - } else { - $html .= '
'; - $html .= '
'; - $html .= '
'; - $html .= Display::div($current_item, array('class' => 'question_no_title')); - $html .= '
'; - $html .= '
'; - $html .= '
'; - if (!empty($questionDescription)) { - $html .= Display::div($questionDescription, array('class' => 'question_description')); - } - $html .= '
'; - $html .= '
'; - } - } - - if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION)) && $freeze) { - return null; - } - - $html .= '
'; - // construction of the Answer object (also gets all answers details) - $objAnswerTmp = new Answer($questionId, null, $this); - - $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); - $course_id = api_get_course_int_id(); - $sessionId = api_get_session_id(); - $quiz_question_options = Question::readQuestionOption($questionId, $course_id); - - // For "matching" type here, we need something a little bit special - // because the match between the suggestions and the answers cannot be - // done easily (suggestions and answers are in the same table), so we - // have to go through answers first (elems with "correct" value to 0). - $select_items = array(); - //This will contain the number of answers on the left side. We call them - // suggestions here, for the sake of comprehensions, while the ones - // on the right side are called answers - $num_suggestions = 0; - if ($answerType == MATCHING || $answerType == DRAGGABLE) { - if ($answerType == DRAGGABLE) { - $s .= '
-
    '; - } else { - $s .= '
    '; - $s .= ''; - } - - $j = 1; //iterate through answers - $letter = 'A'; //mark letters for each answer - $answer_matching = array(); - $capital_letter = array(); - foreach ($objAnswerTmp->answer as $answerId => $answer_item) { - $answerCorrect = $objAnswerTmp->isCorrect($answerId); - $answer = $objAnswerTmp->selectAnswer($answerId); - if ($answerCorrect == 0) { - // options (A, B, C, ...) that will be put into the list-box - // have the "correct" field set to 0 because they are answer - $capital_letter[$j] = $letter; - $answer_matching[$j] = array('id' => $answerId, 'answer' => $answer); - $j++; - $letter++; - } - } - - $i = 1; - $select_items[0]['id'] = 0; - $select_items[0]['letter'] = '--'; - $select_items[0]['answer'] = ''; - foreach ($answer_matching as $id => $value) { - $select_items[$i]['id'] = $value['id']; - $select_items[$i]['letter'] = $capital_letter[$id]; - $select_items[$i]['answer'] = $value['answer']; - $i++; - } - $num_suggestions = ($nbrAnswers - $j) + 1; - } elseif ($answerType == FREE_ANSWER) { - $content = isset($user_choice[0]) && !empty($user_choice[0]['answer']) ? $user_choice[0]['answer'] : null; - $toolBar = 'TestFreeAnswer'; - if ($modelType == EXERCISE_MODEL_TYPE_COMMITTEE) { - $toolBar = 'TestFreeAnswerStrict'; - } - $form->addElement( - 'html_editor', - "choice[".$questionId."]", - null, - array('id' => "choice[".$questionId."]"), - array('ToolbarSet' => $toolBar) - ); - $form->setDefaults(array("choice[".$questionId."]" => $content)); - $s .= $form->returnForm(); - } elseif ($answerType == ORAL_EXPRESSION) { - // Add nanogong - if (api_get_setting('enable_record_audio') === 'true') { - //@todo pass this as a parameter - global $exercise_stat_info, $exerciseId; - if (!empty($exercise_stat_info)) { - $objQuestionTmp->initFile( - $sessionId, - api_get_user_id(), - $exercise_stat_info['exe_exo_id'], - $exercise_stat_info['exe_id'] - ); - } else { - $objQuestionTmp->initFile( - $sessionId, - api_get_user_id(), - $exerciseId, - 'temp_exe' - ); - } - - $s .= $objQuestionTmp->returnRecorder(); - } - - $form->addElement( - 'html_editor', - "choice[".$questionId."]", - null, - array('id' => "choice[".$questionId."]"), - array('ToolbarSet' => 'TestFreeAnswer') - ); - //$form->setDefaults(array("choice[".$questionId."]" => $content)); - $s .= $form->returnForm(); - } - - // Now navigate through the possible answers, using the max number of - // answers for the question as a limiter - $lines_count = 1; // a counter for matching-type answers - if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { - $header = Display::tag('th', get_lang('Options')); - foreach ($objQuestionTmp->options as $item) { - $header .= Display::tag('th', $item); - } - if ($show_comment) { - $header .= Display::tag('th', get_lang('Feedback')); - } - $s .= '
    '; - $s .= Display::tag('tr', $header, array('style' => 'text-align:left;')); - } - - if ($show_comment) { - if (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION, UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION, GLOBAL_MULTIPLE_ANSWER))) { - $header = Display::tag('th', get_lang('Options')); - if ($exercise_feedback == EXERCISE_FEEDBACK_TYPE_END) { - $header .= Display::tag('th', get_lang('Feedback')); - } - $s .= '
    '; - $s.= Display::tag('tr', $header, array('style' => 'text-align:left;')); - } - } - - $matching_correct_answer = 0; - $user_choice_array = array(); - if (!empty($user_choice)) { - foreach ($user_choice as $item) { - $user_choice_array[] = $item['answer']; - } - } - - foreach ($objAnswerTmp->answer as $answerId => $answer_item) { - $answer = $objAnswerTmp->selectAnswer($answerId); - $answerCorrect = $objAnswerTmp->isCorrect($answerId); - $comment = $objAnswerTmp->selectComment($answerId); - $numAnswer = $answerId; - - $attributes = array(); - // Unique answer - if (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION))) { - $input_id = 'choice-'.$questionId.'-'.$answerId; - if (isset($user_choice[0]['answer']) && $user_choice[0]['answer'] == $numAnswer) { - $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1); - } else { - $attributes = array('id' => $input_id); - } - - if ($debug_mark_answer) { - if ($answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - - $answer = Security::remove_XSS($answer); - $s .= Display::input('hidden', 'choice2['.$questionId.']', '0'); - - $answer_input = null; - if ($answerType == UNIQUE_ANSWER_IMAGE) { - $attributes['style'] = 'display:none'; - $answer_input .= '
    '; - } - - $answer_input .= ''; - - if ($answerType == UNIQUE_ANSWER_IMAGE) { - $answer_input .= "
    "; - } - - if ($show_comment) { - $s .= ''; - $s .= ''; - $s .= ''; - } else { - $s .= $answer_input; - } - } elseif (in_array($answerType, array(MULTIPLE_ANSWER, MULTIPLE_ANSWER_TRUE_FALSE, GLOBAL_MULTIPLE_ANSWER))) { - $input_id = 'choice-'.$questionId.'-'.$answerId; - $answer = Security::remove_XSS($answer); - - if (in_array($numAnswer, $user_choice_array)) { - $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1); - } else { - $attributes = array('id' => $input_id); - } - - if ($debug_mark_answer) { - if ($answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - - if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { - $s .= ''; - $answer_input = ''; - - if ($show_comment) { - $s .= ''; - $s .= ''; - $s .=''; - } else { - $s .= $answer_input; - } - } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { - $my_choice = array(); - if (!empty($user_choice_array)) { - foreach ($user_choice_array as $item) { - $item = explode(':', $item); - $my_choice[$item[0]] = $item[1]; - } - } - - $s .=''; - $s .= Display::tag('td', $answer); - - if (!empty($quiz_question_options)) { - foreach ($quiz_question_options as $id => $item) { - $id = $item['iid']; - if (isset($my_choice[$numAnswer]) && $id == $my_choice[$numAnswer]) { - $attributes = array('checked' => 1, 'selected' => 1); - } else { - $attributes = array(); - } - - if ($debug_mark_answer) { - if ($id == $answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - $s .= Display::tag('td', Display::input('radio', 'choice['.$questionId.']['.$numAnswer.']', $id, $attributes), array('style' => '')); - } - } - - if ($show_comment) { - $s .= ''; - } - $s.=''; - } - } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) { - // multiple answers - $input_id = 'choice-'.$questionId.'-'.$answerId; - - if (in_array($numAnswer, $user_choice_array)) { - $attributes = array('id' => $input_id, 'checked' => 1, 'selected' => 1); - } else { - $attributes = array('id' => $input_id); - } - - if ($debug_mark_answer) { - if ($answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - - $answer = Security::remove_XSS($answer); - $answer_input = ''; - $answer_input .= ''; - - if ($show_comment) { - $s.= ''; - $s .= ''; - $s .= ''; - $s.= ''; - } else { - $s.= $answer_input; - } - } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { - $s .= ''; - - $my_choice = array(); - if (!empty($user_choice_array)) { - foreach ($user_choice_array as $item) { - $item = explode(':', $item); - $my_choice[$item[0]] = $item[1]; - } - } - $answer = Security::remove_XSS($answer); - $s .=''; - $s .= Display::tag('td', $answer); - - foreach ($objQuestionTmp->options as $key => $item) { - if (isset($my_choice[$numAnswer]) && $key == $my_choice[$numAnswer]) { - $attributes = array('checked' => 1, 'selected' => 1); - } else { - $attributes = array(); - } - - if ($debug_mark_answer) { - if ($key == $answerCorrect) { - $attributes['checked'] = 1; - $attributes['selected'] = 1; - } - } - $s .= Display::tag('td', Display::input('radio', 'choice['.$questionId.']['.$numAnswer.']', $key, $attributes)); - } - - if ($show_comment) { - $s .= ''; - } - $s.=''; - } elseif ($answerType == FILL_IN_BLANKS) { - list($answer) = explode('::', $answer); - // Correct answer - api_preg_match_all('/\[[^]]+\]/', $answer, $correct_answer_list); - - // Student's answer - if (isset($user_choice[0]['answer'])) { - api_preg_match_all('/\[[^]]+\]/', $user_choice[0]['answer'], $student_answer_list); - $student_answer_list = $student_answer_list[0]; - } - - // If debug - if ($debug_mark_answer) { - $student_answer_list = $correct_answer_list[0]; - } - - if (!empty($correct_answer_list) && !empty($student_answer_list)) { - $correct_answer_list = $correct_answer_list[0]; - $i = 0; - foreach ($correct_answer_list as $correct_item) { - $value = null; - if (isset($student_answer_list[$i]) && !empty($student_answer_list[$i])) { - - //Cleaning student answer list - $value = strip_tags($student_answer_list[$i]); - $value = api_substr($value, 1, api_strlen($value) - 2); - $value = explode('/', $value); - - if (!empty($value[0])) { - $value = str_replace(' ', '', trim($value[0])); - } - $correct_item = preg_quote($correct_item); - $correct_item = api_preg_replace('|/|', '\/', $correct_item); // to prevent error if there is a / in the text to find - $answer = api_preg_replace('/'.$correct_item.'/', Display::input('text', "choice[$questionId][]", $value), $answer, 1); - } - $i++; - } - } else { - $answer = api_preg_replace('/\[[^]]+\]/', Display::input('text', "choice[$questionId][]", '', $attributes), $answer); - } - $s .= $answer; - } elseif ($answerType == MATCHING) { - // matching type, showing suggestions and answers - // TODO: replace $answerId by $numAnswer - - if ($lines_count == 1) { - $s .= $objAnswerTmp->getJs(); - } - if ($answerCorrect != 0) { - // only show elements to be answered (not the contents of - // the select boxes, who are correct = 0) - $s .= ''; - // Middle part (matches selects) - $s .= ''; - $s.=''; - $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 .= ' - - - "; - $lines_count++; - } // end while() - } // end if() - $matching_correct_answer++; - } - } elseif ($answerType == DRAGGABLE) { - // matching type, showing suggestions and answers - // TODO: replace $answerId by $numAnswer - if ($answerCorrect != 0) { - // only show elements to be answered (not the contents of - // the select boxes, who are correct = 0) - $s .= '
    '; - $s .= $answer_input; - $s .= ''; - $s .= $comment; - $s .= '
    '; - $s .= $answer_input; - $s .= ''; - $s .= $comment; - $s .= '
    '; - $s .= $comment; - $s .= '
    '; - $s.= $answer_input; - $s .= ''; - $s .= $comment; - $s .= '
    '; - $s .= $comment; - $s .= '
    '; - $parsed_answer = $answer; - $windowId = $questionId.'_'.$lines_count; - // Left part questions - $s .= '
    - '.$lines_count.'. '.$parsed_answer.' -
    -
      '; - $s .= '
    '; - $s .= '
    '; - if (isset($select_items[$lines_count])) { - $s.= '
    - '.$select_items[$lines_count]['letter'].'. '.$select_items[$lines_count]['answer'].' -
    '; - } else { - $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 .= '
  • '; - $s .= '
    - '.$parsed_answer.' -
    '; - - $s .= '
    '; - $s .= ''; - - if (!empty($answerCorrect) && !empty($selectedValue)) { - $s.= ''; - } - - if (isset($select_items[$lines_count])) { - $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 .= '
    '; - $matching_correct_answer++; - $s .= '
  • '; - } - } - } // end for() - - if ($show_comment) { - $s .= '
    '; - } else { - if ($answerType == MATCHING || $answerType == UNIQUE_ANSWER_NO_OPTION || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || - $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { - $s .= ''; - } - } - - if ($answerType == DRAGGABLE) { - $s .= '
'; - $counterAnswer = 1; - foreach ($objAnswerTmp->answer as $answerId => $answer_item) { - $answerCorrect = $objAnswerTmp->isCorrect($answerId); - $windowId = $questionId.'_'.$counterAnswer; - if ($answerCorrect == 0) { - $s .= '
'.$counterAnswer.'
'; - $counterAnswer++; - } - } - } - - if ($answerType == MATCHING) { - $s .= '
'; - } - - $s .= '
'; - - // destruction of the Answer object - unset($objAnswerTmp); - // destruction of the Question object - unset($objQuestionTmp); - $html .= $s; - return $html; - } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) { - // Question is a HOT_SPOT - //checking document/images visibility - if (api_is_platform_admin() || api_is_course_admin()) { - $course = api_get_course_info(); - $doc_id = DocumentManager::get_document_id($course, '/images/'.$pictureName); - if (is_numeric($doc_id)) { - $images_folder_visibility = api_get_item_visibility($course, 'document', $doc_id, api_get_session_id()); - if (!$images_folder_visibility) { - //This message is shown only to the course/platform admin if the image is set to visibility = false - Display::display_warning_message(get_lang('ChangeTheVisibilityOfTheCurrentImage')); - } - } - } - $questionName = $objQuestionTmp->selectTitle(); - $questionDescription = $objQuestionTmp->selectDescription(); - - if ($freeze) { - $s .= Display::img($objQuestionTmp->selectPicturePath()); - $html .= $s; - return $html; - } - - // Get the answers, make a list - $objAnswerTmp = new Answer($questionId); - - // get answers of hotpost - $answers_hotspot = array(); - foreach ($objAnswerTmp->answer as $answerId => $answer_item) { - //$answers = $objAnswerTmp->selectAnswerByAutoId($objAnswerTmp->selectAutoId($answerId)); - $answers_hotspot[$answerId] = $objAnswerTmp->selectAnswer($answerId); - } - - // display answers of hotpost order by id - $answer_list = '
'.get_lang('HotspotZones').'
'; - if (!empty($answers_hotspot)) { - ksort($answers_hotspot); - foreach ($answers_hotspot as $key => $value) { - $answer_list .= '
'.$key.'.- '.$value.'

'; - } - } - $answer_list .= '
'; - - if ($answerType == HOT_SPOT_DELINEATION) { - $answer_list = ''; - $swf_file = 'hotspot_delineation_user'; - $swf_height = 405; - } else { - $swf_file = 'hotspot_user'; - $swf_height = 436; - } - - if (!$only_questions) { - if ($show_title) { - $html .= TestCategory::getCategoryNamesForQuestion($objQuestionTmp->id); - $html .= '
'.$current_item.'. '.$questionName.'
'; - $html .= $questionDescription; - } else { - $html .= '
'; - $html .= '
'; - $html .= '
'; - $html .= Display::div($current_item.'. ', array('class' => 'question_no_title')); - $html .= '
'; - $html .= '
'; - $html .= '
'; - if (!empty($questionDescription)) { - $html .= Display::div($questionDescription, array('class' => 'question_description')); - } - $html .= '
'; - $html .= '
'; - } - //@todo I need to the get the feedback type - $html .= ''; - $html .= ' - - '; - } - - $canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1'); - - $s .= ' - - - - - '; - $s .= ''; - $html .= $s; - $html .= '
'; - $html .= '
- -
- - '.$answer_list.'
-
'; - return $html; - } - return $nbrAnswers; - } - /** * @param int $exeId * @return array