Fixing delete question + cosmetic changes

skala
Julio Montoya 13 years ago
parent d9d4802998
commit 97aae33521
  1. 25
      main/exercice/question.class.php
  2. 10
      main/exercice/question_pool.php

@ -130,7 +130,8 @@ abstract class Question
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$sql = "SELECT question,description,ponderation,position,type,picture,level,extra FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id = $id "; $sql = "SELECT question,description,ponderation,position,type,picture,level,extra
FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id = $id ";
$result = Database::query($sql); $result = Database::query($sql);
@ -944,7 +945,7 @@ abstract class Question
* @author - Olivier Brouckaert * @author - Olivier Brouckaert
* @param - integer $deleteFromEx - exercise ID if the question is only removed from one exercise * @param - integer $deleteFromEx - exercise ID if the question is only removed from one exercise
*/ */
function delete($deleteFromEx=0) { function delete($deleteFromEx = 0) {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
@ -952,28 +953,32 @@ abstract class Question
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$id=$this->id; $id = $this->id;
// if the question must be removed from all exercises // if the question must be removed from all exercises
if(!$deleteFromEx) { if (!$deleteFromEx) {
//update the question_order of each question to avoid inconsistencies //update the question_order of each question to avoid inconsistencies
$sql = "SELECT exercice_id, question_order FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'"; $sql = "SELECT exercice_id, question_order FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
$res = Database::query($sql); $res = Database::query($sql);
if (Database::num_rows($res)>0) { if (Database::num_rows($res) > 0) {
while ($row = Database::fetch_array($res)) { while ($row = Database::fetch_array($res)) {
if (!empty($row['question_order'])) { if (!empty($row['question_order'])) {
$sql = "UPDATE $TBL_EXERCICE_QUESTION SET question_order = question_order-1 WHERE c_id = $course_id AND exercice_id='".Database::escape_string($row['exercice_id'])."' AND question_order > ".$row['question_order']; $sql = "UPDATE $TBL_EXERCICE_QUESTION
$res = Database::query($sql); SET question_order = question_order-1
WHERE c_id = $course_id AND exercice_id='".Database::escape_string($row['exercice_id'])."' AND question_order > ".$row['question_order'];
Database::query($sql);
} }
} }
} }
$sql="DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
$sql = "DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
Database::query($sql); Database::query($sql);
$sql="DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id='".Database::escape_string($id)."'"; $sql = "DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id='".Database::escape_string($id)."'";
Database::query($sql); Database::query($sql);
$sql="DELETE FROM $TBL_REPONSES WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'"; $sql = "DELETE FROM $TBL_REPONSES WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
Database::query($sql); Database::query($sql);
// remove the category of this question in the question_rel_category table // remove the category of this question in the question_rel_category table

@ -122,9 +122,10 @@ if ($is_allowedToEdit) {
} }
// deletes a question from the database and all exercises // deletes a question from the database and all exercises
if ($delete) { if ($delete) {
// construction of the Question object // Construction of the Question object
$objQuestionTmp = Question::read($delete);
// if the question exists // if the question exists
if ($objQuestionTmp = Question::read($delete)) { if ($objQuestionTmp) {
// deletes the question from all exercises // deletes the question from all exercises
$objQuestionTmp->delete(); $objQuestionTmp->delete();
} }
@ -134,7 +135,7 @@ if ($is_allowedToEdit) {
// gets an existing question and copies it into a new exercise // gets an existing question and copies it into a new exercise
$objQuestionTmp = Question :: read($recup); $objQuestionTmp = Question :: read($recup);
// if the question exists // if the question exists
if($objQuestionTmp = Question :: read($recup)) { if ($objQuestionTmp) {
// adds the exercise ID represented by $fromExercise into the list of exercises for the current question // adds the exercise ID represented by $fromExercise into the list of exercises for the current question
$objQuestionTmp->addToList($fromExercise); $objQuestionTmp->addToList($fromExercise);
} }
@ -147,8 +148,7 @@ if ($is_allowedToEdit) {
} }
// adds the question ID represented by $recup into the list of questions for the current exercise // adds the question ID represented by $recup into the list of questions for the current exercise
$objExercise->addToList($recup); $objExercise->addToList($recup);
Session::write('objExercise',$objExercise); Session::write('objExercise', $objExercise);
// header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise"); // header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
// exit(); // exit();
} }

Loading…
Cancel
Save