diff --git a/main/exercise/admin.php b/main/exercise/admin.php index 67f6ec1b07..d7fa5f167c 100755 --- a/main/exercise/admin.php +++ b/main/exercise/admin.php @@ -169,7 +169,6 @@ if (!is_object($objExercise)) { // saves the object into the session Session::write('objExercise', $objExercise); } - // Exercise can be edited in their course. if ($objExercise->sessionId != $sessionId) { api_not_allowed(true); diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index c4d59ab39a..6e41f2bfba 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -1170,6 +1170,33 @@ class Exercise return $inList; } + /** + * If current exercise has a question + * + * @param int $questionId + * + * @return int + */ + public function hasQuestion($questionId) + { + $questionId = (int) $questionId; + + $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); + $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); + $sql = "SELECT q.id + FROM $TBL_EXERCICE_QUESTION e + INNER JOIN $TBL_QUESTIONS q + ON (e.question_id = q.id AND e.c_id = q.c_id) + WHERE + q.id = $questionId AND + e.c_id = {$this->course_id} AND + e.exercice_id = ".$this->id; + + $result = Database::query($sql); + + return Database::num_rows($result) > 0; + } + /** * changes the exercise title. * diff --git a/main/exercise/question_pool.php b/main/exercise/question_pool.php index 52ebffc430..3dde77ff00 100755 --- a/main/exercise/question_pool.php +++ b/main/exercise/question_pool.php @@ -48,7 +48,7 @@ $_course = api_get_course_info(); if (empty($objExercise) && !empty($fromExercise)) { $objExercise = new Exercise(); - $objExercise->read($fromExercise); + $objExercise->read($fromExercise, false); } $nameTools = get_lang('QuestionPool'); @@ -402,8 +402,6 @@ $question_list = Question::get_question_type_list(); $new_question_list = []; $new_question_list['-1'] = get_lang('All'); if (!empty($_course)) { - $objExercise = new Exercise(); - $objExercise->read($fromExercise); foreach ($question_list as $key => $item) { if ($objExercise->feedback_type == EXERCISE_FEEDBACK_TYPE_DIRECT) { if (!in_array($key, [HOT_SPOT_DELINEATION, UNIQUE_ANSWER])) { @@ -705,10 +703,9 @@ $pagination->renderer = function ($data) use ($url) { if ($data['pageCount'] > 1) { $render = '