Skip to content

Commit

Permalink
Fix fatal error see #8176
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed May 2, 2016
1 parent d7355d0 commit 4a3e2c0
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions main/exercice/question.class.php
Expand Up @@ -1190,7 +1190,7 @@ function removeFromList($exerciseId)
* @author Olivier Brouckaert
* @param integer $deleteFromEx - exercise ID if the question is only removed from one exercise
*/
function delete($deleteFromEx = 0)
public function delete($deleteFromEx = 0)
{
$course_id = api_get_course_int_id();

Expand All @@ -1199,7 +1199,7 @@ function delete($deleteFromEx = 0)
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);

$id = $this->id;
$id = intval($this->id);

// if the question must be removed from all exercises
if (!$deleteFromEx) {
Expand All @@ -1223,46 +1223,59 @@ function delete($deleteFromEx = 0)
}

$sql = "DELETE FROM $TBL_EXERCISE_QUESTION
WHERE c_id = $course_id AND question_id = " . intval($id) . "";
WHERE c_id = $course_id AND question_id = " . $id;
Database::query($sql);

$sql = "DELETE FROM $TBL_QUESTIONS
WHERE c_id = $course_id AND id = " . intval($id) . "";
WHERE c_id = $course_id AND id = " . $id;
Database::query($sql);

$sql = "DELETE FROM $TBL_REPONSES
WHERE c_id = $course_id AND question_id = " . intval($id) . "";
WHERE c_id = $course_id AND question_id = " . $id;
Database::query($sql);

// remove the category of this question in the question_rel_category table
$sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY
WHERE c_id = $course_id AND question_id = " . intval($id) . " AND c_id=" . api_get_course_int_id();
WHERE
c_id = $course_id AND
question_id = " . $id;
Database::query($sql);

api_item_property_update($this->course, TOOL_QUIZ, $id, 'QuizQuestionDeleted', api_get_user_id());
api_item_property_update(
$this->course,
TOOL_QUIZ,
$id,
'QuizQuestionDeleted',
api_get_user_id()
);
$this->removePicture();

// resets the object
$this->Question();
} else {
// just removes the exercise from the list
$this->removeFromList($deleteFromEx);
if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) {
// disassociate question with this exercise
$this->search_engine_edit($deleteFromEx, FALSE, TRUE);
}
api_item_property_update($this->course, TOOL_QUIZ, $id, 'QuizQuestionDeleted', api_get_user_id());

api_item_property_update(
$this->course,
TOOL_QUIZ,
$id,
'QuizQuestionDeleted',
api_get_user_id()
);
}
}

/**
* Duplicates the question
*
* @author Olivier Brouckaert
* @param array Course info of the destination course
* @param array $course_info Course info of the destination course
* @return int ID of the new question
*/
public function duplicate($course_info = null)
public function duplicate($course_info = [])
{
if (empty($course_info)) {
$course_info = $this->course;
Expand Down Expand Up @@ -1348,6 +1361,7 @@ public function duplicate($course_info = null)
public function get_question_type_name()
{
$key = self::$questionTypes[$this->type];

return get_lang($key[1]);
}

Expand Down

0 comments on commit 4a3e2c0

Please sign in to comment.