diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index fba2cc6b63..2064dcb363 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -5974,88 +5974,6 @@ class Exercise return $html; } - /** - * Create a quiz from quiz data. - * - * @param string Title - * @param int Time before it expires (in minutes) - * @param int Type of exercise - * @param int Whether it's randomly picked questions (1) or not (0) - * @param int Whether the exercise is visible to the user (1) or not (0) - * @param int Whether the results are show to the user (0) or not (1) - * @param int Maximum number of attempts (0 if no limit) - * @param int Feedback type - * @param int $propagateNegative - * - * @todo this was function was added due the import exercise via CSV - * - * @return int New exercise ID - */ - public function createExercise( - $title, - $expired_time = 0, - $type = 2, - $random = 0, - $active = 1, - $results_disabled = 0, - $max_attempt = 0, - $feedback = 3, - $propagateNegative = 0 - ) { - $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST); - $type = intval($type); - $random = intval($random); - $active = intval($active); - $results_disabled = intval($results_disabled); - $max_attempt = intval($max_attempt); - $feedback = intval($feedback); - $expired_time = intval($expired_time); - $title = Database::escape_string($title); - $propagateNegative = intval($propagateNegative); - $sessionId = api_get_session_id(); - $course_id = api_get_course_int_id(); - // Save a new quiz - $sql = "INSERT INTO $tbl_quiz ( - c_id, - title, - type, - random, - active, - results_disabled, - max_attempt, - start_time, - end_time, - feedback_type, - expired_time, - session_id, - propagate_neg - ) - VALUES ( - '$course_id', - '$title', - $type, - $random, - $active, - $results_disabled, - $max_attempt, - '', - '', - $feedback, - $expired_time, - $sessionId, - $propagateNegative - )"; - Database::query($sql); - $quiz_id = Database::insert_id(); - - if ($quiz_id) { - $sql = "UPDATE $tbl_quiz SET id = iid WHERE iid = {$quiz_id} "; - Database::query($sql); - } - - return $quiz_id; - } - /** * Returns the exercise result. * diff --git a/main/exercise/upload_exercise.php b/main/exercise/upload_exercise.php index 32d9aa8010..ada84bf2da 100755 --- a/main/exercise/upload_exercise.php +++ b/main/exercise/upload_exercise.php @@ -266,17 +266,16 @@ function lp_upload_quiz_action_handling() // Quiz object $exercise = new Exercise(); - $quiz_id = $exercise->createExercise( - $quizTitle, - $expired_time, - $type, - $random, - $active, - $results, - $max_attempt, - $feedback, - $propagateNegative - ); + $exercise->updateTitle($quizTitle); + $exercise->updateExpiredTime($expired_time); + $exercise->updateType($type); + $exercise->setRandom($random); + $exercise->active = $active; + $exercise->updateResultsDisabled($results); + $exercise->updateAttempts($max_attempt); + $exercise->updateFeedbackType($feedback); + $exercise->updatePropagateNegative($propagateNegative); + $quiz_id = $exercise->save(); if ($quiz_id) { // insert into the item_property table @@ -387,7 +386,7 @@ function lp_upload_quiz_action_handling() $score = 0; if (strtolower($answer_data['extra']) == 'x') { $correct = 1; - $score = isset($scoreList[$i]) ? $scoreList[$i] : null; + $score = isset($scoreList[$i]) ? $scoreList[$i] : 0; $comment = isset($feedbackTrueList[$i]) ? $feedbackTrueList[$i] : ''; } else { $comment = isset($feedbackFalseList[$i]) ? $feedbackFalseList[$i] : ''; @@ -439,7 +438,7 @@ function lp_upload_quiz_action_handling() $id ); - $total += $score; + $total += (float) $score; $id++; } @@ -461,7 +460,7 @@ function lp_upload_quiz_action_handling() $questionObj->updateWeighting($total); break; } - $questionObj->save(); + $questionObj->save($exercise); } } break; @@ -470,7 +469,7 @@ function lp_upload_quiz_action_handling() $questionObj = Question::read($question_id, $courseId); if ($questionObj) { $questionObj->updateWeighting($globalScore); - $questionObj->save(); + $questionObj->save($exercise); } break; case FILL_IN_BLANKS: @@ -503,7 +502,7 @@ function lp_upload_quiz_action_handling() $questionObj = Question::read($question_id, $courseId); if ($questionObj) { $questionObj->updateWeighting($globalScore); - $questionObj->save(); + $questionObj->save($exercise); } break; case MATCHING: @@ -534,7 +533,7 @@ function lp_upload_quiz_action_handling() $questionObj = Question::read($question_id, $courseId); if ($questionObj) { $questionObj->updateWeighting($globalScore); - $questionObj->save(); + $questionObj->save($exercise); } break; } diff --git a/tests/behat/features/toolExercise.feature b/tests/behat/features/toolExercise.feature index a825386d17..a8372b4c9a 100644 --- a/tests/behat/features/toolExercise.feature +++ b/tests/behat/features/toolExercise.feature @@ -312,4 +312,12 @@ Feature: Exercise tool Scenario: Delete an exercise category Given I am on "/main/exercise/tests_category.php?cidReq=TEMP" And I follow "Delete" - Then I should see "Category deleted" \ No newline at end of file + Then I should see "Category deleted" + + Scenario: Import exercise from excel + Given I am on "/main/exercise/upload_exercise.php?cidReq=TEMP" + Then I should see "Import quiz from Excel" + Then I attach the file "/main/exercise/quiz_template.xls" to "user_upload_quiz" + And I press "Upload" + And wait for the page to be loaded + Then I should see "Definition of oligarchy"