$(document).ready( function(){ $('#user_custom_score').click(function() { $('#options').toggle(); }); }); "; // Action handling lp_upload_quiz_action_handling(); $interbreadcrumb[] = array( "url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises') ); // Display the header Display :: display_header(get_lang('ImportExcelQuiz'), 'Exercises'); // display the actions echo '
$description
"; } // Unique answers are the only question types available for now // through xls-format import $question_id = null; if (isset($questionTypeList[$i]) && $questionTypeList[$i] != '') { $detectQuestionType = (int) $questionTypeList[$i]; } else { $detectQuestionType = detectQuestionType($myAnswerList); } /** @var Question $answer */ switch ($detectQuestionType) { case FREE_ANSWER: $answer = new FreeAnswer(); break; case GLOBAL_MULTIPLE_ANSWER: $answer = new GlobalMultipleAnswer(); break; case MULTIPLE_ANSWER: $answer = new MultipleAnswer(); break; case FILL_IN_BLANKS: $answer = new FillBlanks(); $question_description_text = ''; break; case MATCHING: $answer = new Matching(); break; case UNIQUE_ANSWER: default: $answer = new UniqueAnswer(); break; } if ($questionTitle != '') { $question_id = $answer->create_question( $quiz_id, $questionTitle, $question_description_text, 0, // max score $answer->type ); if (!empty($categoryId)) { TestCategory::addCategoryToQuestion( $categoryId, $question_id, $courseId ); } } switch ($detectQuestionType) { case GLOBAL_MULTIPLE_ANSWER: case MULTIPLE_ANSWER: case UNIQUE_ANSWER: $total = 0; if (is_array($myAnswerList) && !empty($myAnswerList) && !empty($question_id)) { $id = 1; $objAnswer = new Answer($question_id, $courseId); $globalScore = isset($scoreList[$i]) ? $scoreList[$i] : null; // Calculate the number of correct answers to divide the // score between them when importing from CSV $numberRightAnswers = 0; foreach ($myAnswerList as $answer_data) { if (strtolower($answer_data['extra']) == 'x') { $numberRightAnswers++; } } foreach ($myAnswerList as $answer_data) { $answerValue = $answer_data['data']; $correct = 0; $score = 0; if (strtolower($answer_data['extra']) == 'x') { $correct = 1; $score = isset($scoreList[$i]) ? $scoreList[$i] : null; $comment = isset($feedbackTrueList[$i]) ? $feedbackTrueList[$i] : ''; } else { $comment = isset($feedbackFalseList[$i]) ? $feedbackFalseList[$i] : ''; $floatVal = (float) $answer_data['extra']; if (is_numeric($floatVal)) { $score = $answer_data['extra']; } } if ($useCustomScore) { if ($correct) { $score = $correctScore; } else { $score = $incorrectScore; } } // Fixing scores: switch ($detectQuestionType) { case GLOBAL_MULTIPLE_ANSWER: if (!$correct) { if (isset($noNegativeScoreList[$i])) { if (strtolower($noNegativeScoreList[$i]) == 'x') { $score = 0; } else { $score = $scoreList[$i] * -1; } } } else { $score = $scoreList[$i]; } $score /= $numberRightAnswers; break; case UNIQUE_ANSWER: break; case MULTIPLE_ANSWER: if (!$correct) { //$total = $total - $score; } break; } $objAnswer->createAnswer( $answerValue, $correct, $comment, $score, $id ); $total += $score; $id++; } $objAnswer->save(); $questionObj = Question::read( $question_id, $courseId ); if ($questionObj) { switch ($detectQuestionType) { case GLOBAL_MULTIPLE_ANSWER: $questionObj->updateWeighting($globalScore); break; case UNIQUE_ANSWER: case MULTIPLE_ANSWER: default: $questionObj->updateWeighting($total); break; } $questionObj->save(); } } break; case FREE_ANSWER: $globalScore = isset($scoreList[$i]) ? $scoreList[$i] : null; $questionObj = Question::read($question_id, $courseId); if ($questionObj) { $questionObj->updateWeighting($globalScore); $questionObj->save(); } break; case FILL_IN_BLANKS: $fillInScoreList = []; $size = []; $globalScore = 0; foreach ($myAnswerList as $data) { $score = isset($data['extra']) ? $data['extra'] : 0; $globalScore += $score; $fillInScoreList[] = $score; $size[] = 200; } $scoreToString = implode(',', $fillInScoreList); $sizeToString = implode(',', $size); //Texte long avec les [mots] à [remplir] mis entre [crochets]
::10,10,10:200.36363999999998,200,200:0@' $answerValue = $description.'::'.$scoreToString.':'.$sizeToString.':0@'; $objAnswer = new Answer($question_id, $courseId); $objAnswer->createAnswer( $answerValue, '', //$correct, '', //$comment, $globalScore, 1 ); $objAnswer->save(); $questionObj = Question::read($question_id, $courseId); if ($questionObj) { $questionObj->updateWeighting($globalScore); $questionObj->save(); } break; case MATCHING: $globalScore = isset($scoreList[$i]) ? $scoreList[$i] : null; $position = 1; $objAnswer = new Answer($question_id, $courseId); foreach ($myAnswerList as $data) { $option = isset($data['extra']) ? $data['extra'] : ''; $objAnswer->createAnswer($option, 0, '', 0, $position); $position++; } $counter = 1; foreach ($myAnswerList as $data) { $value = isset($data['data']) ? $data['data'] : ''; $position++; $objAnswer->createAnswer( $value, $counter, ' ', $globalScore, $position ); $counter++; } $objAnswer->save(); $questionObj = Question::read($question_id, $courseId); if ($questionObj) { $questionObj->updateWeighting($globalScore); $questionObj->save(); } break; } } } if (isset($_SESSION['lpobject'])) { if ($debug > 0) { error_log('New LP - SESSION[lpobject] is defined', 0); } $oLP = unserialize($_SESSION['lpobject']); if (is_object($oLP)) { if ($debug > 0) { error_log('New LP - oLP is object', 0); } if ((empty($oLP->cc)) || $oLP->cc != api_get_course_id()) { if ($debug > 0) { error_log('New LP - Course has changed, discard lp object', 0); } $oLP = null; Session::erase('oLP'); Session::erase('lpobject'); } else { $_SESSION['oLP'] = $oLP; } } } if (isset($_SESSION['oLP']) && isset($_GET['lp_id'])) { $previous = $_SESSION['oLP']->select_previous_item_id(); $parent = 0; // Add a Quiz as Lp Item $_SESSION['oLP']->add_item($parent, $previous, TOOL_QUIZ, $quiz_id, $quizTitle, ''); // Redirect to home page for add more content header('location: ../lp/lp_controller.php?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.intval($_GET['lp_id'])); exit; } else { // header('location: exercise.php?' . api_get_cidreq()); echo ''; } } } /** * @param array $answers_data * @return int */ function detectQuestionType($answers_data) { $correct = 0; $isNumeric = false; if (empty($answers_data)) { return FREE_ANSWER; } foreach ($answers_data as $answer_data) { if (strtolower($answer_data['extra']) == 'x') { $correct++; } else { if (is_numeric($answer_data['extra'])) { $isNumeric = true; } } } if ($correct == 1) { $type = UNIQUE_ANSWER; } else { if ($correct > 1) { $type = MULTIPLE_ANSWER; } else { $type = FREE_ANSWER; } } if ($type == MULTIPLE_ANSWER) { if ($isNumeric) { $type = MULTIPLE_ANSWER; } else { $type = GLOBAL_MULTIPLE_ANSWER; } } return $type; } if ($origin != 'learnpath') { //so we are not in learnpath tool Display :: display_footer(); }