diff --git a/public/main/exercise/TestCategory.php b/public/main/exercise/TestCategory.php index 4ea1145aa8..7c62baebbe 100644 --- a/public/main/exercise/TestCategory.php +++ b/public/main/exercise/TestCategory.php @@ -742,7 +742,7 @@ class TestCategory true ) ); - $tempResult[$category_id] = round($category_item['score'] / $category_item['total'] * 10); + $tempResult[$category_id] = $category_item['total'] != 0 ? round($category_item['score'] / $category_item['total'] * 10) : 0; $row++; } @@ -1039,7 +1039,7 @@ class TestCategory $res = Database::query($sql); if (Database::num_rows($res) > 0) { $data = Database::fetch_array($res); - $out_res = $data['id']; + $out_res = $data['iid']; } return $out_res; @@ -1063,8 +1063,8 @@ class TestCategory $questionId > 0 && $courseId > 0 ) { - $sql = "INSERT INTO $table (c_id, question_id, category_id) - VALUES (".intval($courseId).", ".intval($questionId).", ".intval($categoryId).")"; + $sql = "INSERT INTO $table (question_id, category_id) + VALUES (".intval($questionId).", ".intval($categoryId).")"; Database::query($sql); $id = Database::insert_id(); diff --git a/public/main/exercise/answer.class.php b/public/main/exercise/answer.class.php index 87adfd0f39..7c2ec3fda2 100644 --- a/public/main/exercise/answer.class.php +++ b/public/main/exercise/answer.class.php @@ -697,7 +697,7 @@ class Answer ->setAnswer($answer) ->setCorrect($correct) ->setComment($comment) - ->setPonderation($weighting) + ->setPonderation(!is_null($weighting) ? $weighting : 0.0) ->setPosition($position) ->setHotspotCoordinates($hotspot_coordinates) ->setHotspotType($hotspot_type) diff --git a/public/main/exercise/question.class.php b/public/main/exercise/question.class.php index caa5eb6f22..2e7715dc24 100644 --- a/public/main/exercise/question.class.php +++ b/public/main/exercise/question.class.php @@ -1771,7 +1771,6 @@ abstract class Question $type = 1, $level = 1 ) { - $course_id = api_get_course_int_id(); $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION); $tbl_quiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); @@ -1785,22 +1784,20 @@ abstract class Question FROM $tbl_quiz_question q INNER JOIN $tbl_quiz_rel_question r ON - q.id = r.question_id AND - quiz_id = $quiz_id AND - q.c_id = $course_id AND - r.c_id = $course_id"; + q.iid = r.question_id AND + quiz_id = $quiz_id"; $rs_max = Database::query($sql); $row_max = Database::fetch_object($rs_max); $max_position = $row_max->max_position + 1; $params = [ - 'c_id' => $course_id, 'question' => $question_name, 'description' => $question_description, 'ponderation' => $max_score, 'position' => $max_position, 'type' => $type, 'level' => $level, + 'mandatory' => 0, ]; $question_id = Database::insert($tbl_quiz_question, $params); @@ -1808,13 +1805,13 @@ abstract class Question // Get the max question_order $sql = "SELECT max(question_order) as max_order FROM $tbl_quiz_rel_question - WHERE c_id = $course_id AND quiz_id = $quiz_id "; + WHERE quiz_id = $quiz_id "; $rs_max_order = Database::query($sql); $row_max_order = Database::fetch_object($rs_max_order); $max_order = $row_max_order->max_order + 1; // Attach questions to quiz - $sql = "INSERT INTO $tbl_quiz_rel_question (c_id, question_id, quiz_id, question_order) - VALUES($course_id, $question_id, $quiz_id, $max_order)"; + $sql = "INSERT INTO $tbl_quiz_rel_question (question_id, quiz_id, question_order) + VALUES($question_id, $quiz_id, $max_order)"; Database::query($sql); } diff --git a/public/main/exercise/upload_exercise.php b/public/main/exercise/upload_exercise.php index 9c4accb8dd..9e04267973 100644 --- a/public/main/exercise/upload_exercise.php +++ b/public/main/exercise/upload_exercise.php @@ -4,6 +4,7 @@ use ChamiloSession as Session; use Chamilo\CoreBundle\Component\Utils\ActionIcon; +use PhpOffice\PhpSpreadsheet\IOFactory; /** * Upload quiz: This script shows the upload quiz feature. @@ -147,7 +148,15 @@ function lp_upload_quiz_action_handling() $answerList = []; $quizTitle = ''; - $objPHPExcel = PHPExcel_IOFactory::load($_FILES['user_upload_quiz']['tmp_name']); + if (isset($_FILES['user_upload_quiz'])) { + try { + $objPHPExcel = IOFactory::load($_FILES['user_upload_quiz']['tmp_name']); + } catch (\Exception $e) { + return; + } + } else { + return; + } $objPHPExcel->setActiveSheetIndex(0); $worksheet = $objPHPExcel->getActiveSheet(); @@ -159,9 +168,9 @@ function lp_upload_quiz_action_handling() $useCustomScore = isset($_POST['user_custom_score']) ? true : false; for ($row = 1; $row <= $highestRow; $row++) { - $cellTitleInfo = $worksheet->getCellByColumnAndRow(0, $row); - $cellDataInfo = $worksheet->getCellByColumnAndRow(1, $row); - $cellScoreInfo = $worksheet->getCellByColumnAndRow(2, $row); + $cellTitleInfo = $worksheet->getCell("A$row"); + $cellDataInfo = $worksheet->getCell("B$row"); + $cellScoreInfo = $worksheet->getCell("C$row"); $title = $cellTitleInfo->getValue(); switch ($title) { @@ -177,13 +186,13 @@ function lp_upload_quiz_action_handling() $answerIndex = 0; while ($continue) { $answerRow++; - $answerInfoTitle = $worksheet->getCellByColumnAndRow(0, $answerRow); - $answerInfoData = $worksheet->getCellByColumnAndRow(1, $answerRow); - $answerInfoExtra = $worksheet->getCellByColumnAndRow(2, $answerRow); - $answerInfoTitle = $answerInfoTitle->getValue(); + $answerInfoTitle = $worksheet->getCell("A$answerRow")->getValue(); + $answerInfoData = $worksheet->getCell("B$answerRow")->getValue(); + $answerInfoExtra = $worksheet->getCell("C$answerRow")->getValue(); + if (false !== strpos($answerInfoTitle, 'Answer')) { - $answerList[$numberQuestions][$answerIndex]['data'] = $answerInfoData->getValue(); - $answerList[$numberQuestions][$answerIndex]['extra'] = $answerInfoExtra->getValue(); + $answerList[$numberQuestions][$answerIndex]['data'] = $answerInfoData; + $answerList[$numberQuestions][$answerIndex]['extra'] = $answerInfoExtra; } else { $continue = false; } @@ -201,14 +210,14 @@ function lp_upload_quiz_action_handling() $questionTypeIndex = 0; while ($continue) { $answerRow++; - $questionTypeTitle = $worksheet->getCellByColumnAndRow(0, $answerRow); - $questionTypeExtra = $worksheet->getCellByColumnAndRow(2, $answerRow); - $title = $questionTypeTitle->getValue(); - if ('QuestionType' == $title) { - $questionTypeList[$numberQuestions] = $questionTypeExtra->getValue(); + $questionTypeTitle = $worksheet->getCell("A$answerRow")->getValue(); + $questionTypeExtra = $worksheet->getCell("C$answerRow")->getValue(); + + if ('QuestionType' == $questionTypeTitle) { + $questionTypeList[$numberQuestions] = $questionTypeExtra; $continue = false; } - if ('Question' == $title) { + if ('Question' == $questionTypeTitle) { $continue = false; } // To avoid loops diff --git a/src/CourseBundle/Entity/CQuizQuestion.php b/src/CourseBundle/Entity/CQuizQuestion.php index 19a57df8e9..e2ce7ddc4e 100644 --- a/src/CourseBundle/Entity/CQuizQuestion.php +++ b/src/CourseBundle/Entity/CQuizQuestion.php @@ -254,7 +254,7 @@ class CQuizQuestion extends AbstractResource implements ResourceInterface, Strin return $this->level; } - public function setExtra(string $extra): self + public function setExtra(?string $extra): self { $this->extra = $extra;