|
|
|
|
@ -77,7 +77,6 @@ abstract class Question |
|
|
|
|
*/ |
|
|
|
|
public function __construct() |
|
|
|
|
{ |
|
|
|
|
$this->id = 0; |
|
|
|
|
$this->iid = 0; |
|
|
|
|
$this->question = ''; |
|
|
|
|
$this->description = ''; |
|
|
|
|
@ -148,14 +147,13 @@ abstract class Question |
|
|
|
|
|
|
|
|
|
$sql = "SELECT * |
|
|
|
|
FROM $TBL_QUESTIONS |
|
|
|
|
WHERE c_id = $course_id AND id = $id "; |
|
|
|
|
WHERE iid = $id "; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
// if the question has been found |
|
|
|
|
if ($object = Database::fetch_object($result)) { |
|
|
|
|
$objQuestion = self::getInstance($object->type); |
|
|
|
|
if (!empty($objQuestion)) { |
|
|
|
|
$objQuestion->id = (int) $id; |
|
|
|
|
$objQuestion->iid = (int) $object->iid; |
|
|
|
|
$objQuestion->question = $object->question; |
|
|
|
|
$objQuestion->description = $object->description; |
|
|
|
|
@ -187,7 +185,7 @@ abstract class Question |
|
|
|
|
$sql = "SELECT DISTINCT q.exercice_id |
|
|
|
|
FROM $TBL_EXERCISE_QUESTION q |
|
|
|
|
INNER JOIN $tblQuiz e |
|
|
|
|
ON e.c_id = q.c_id AND e.id = q.exercice_id |
|
|
|
|
ON e.iid = q.exercice_id |
|
|
|
|
WHERE |
|
|
|
|
q.c_id = $course_id AND |
|
|
|
|
q.question_id = $id AND |
|
|
|
|
@ -220,7 +218,7 @@ abstract class Question |
|
|
|
|
*/ |
|
|
|
|
public function selectId() |
|
|
|
|
{ |
|
|
|
|
return $this->id; |
|
|
|
|
return $this->iid; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -291,8 +289,8 @@ abstract class Question |
|
|
|
|
q.hide_question_number AS hide_num |
|
|
|
|
FROM |
|
|
|
|
$tblQuiz as q |
|
|
|
|
INNER JOIN $tblQuizRelQuestion AS qrq ON qrq.exercice_id = q.id |
|
|
|
|
WHERE qrq.question_id = ".$this->id; |
|
|
|
|
INNER JOIN $tblQuizRelQuestion AS qrq ON qrq.exercice_id = q.iid |
|
|
|
|
WHERE qrq.question_id = ".$this->iid; |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
$result = Database::store_result($res); |
|
|
|
|
if (is_array($result) && |
|
|
|
|
@ -570,7 +568,7 @@ abstract class Question |
|
|
|
|
// update or add category for a question |
|
|
|
|
foreach ($category_list as $category_id) { |
|
|
|
|
$category_id = (int) $category_id; |
|
|
|
|
$question_id = (int) $this->id; |
|
|
|
|
$question_id = (int) $this->iid; |
|
|
|
|
$sql = "SELECT count(*) AS nb |
|
|
|
|
FROM $table |
|
|
|
|
WHERE |
|
|
|
|
@ -615,11 +613,11 @@ abstract class Question |
|
|
|
|
// update or add category for a question |
|
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
|
|
|
$categoryId = (int) $categoryId; |
|
|
|
|
$question_id = (int) $this->id; |
|
|
|
|
$question_id = (int) $this->iid; |
|
|
|
|
$sql = "SELECT count(*) AS nb FROM $table |
|
|
|
|
WHERE |
|
|
|
|
question_id = $question_id AND |
|
|
|
|
c_id = ".$courseId; |
|
|
|
|
c_id = $courseId"; |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
$row = Database::fetch_array($res); |
|
|
|
|
$allowMandatory = api_get_configuration_value('allow_mandatory_question_in_category'); |
|
|
|
|
@ -633,11 +631,11 @@ abstract class Question |
|
|
|
|
$extraMandatoryCondition |
|
|
|
|
WHERE |
|
|
|
|
question_id = $question_id AND |
|
|
|
|
c_id = ".$courseId; |
|
|
|
|
c_id = $courseId"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} else { |
|
|
|
|
$sql = "INSERT INTO $table (c_id, question_id, category_id) |
|
|
|
|
VALUES (".$courseId.", $question_id, $categoryId)"; |
|
|
|
|
VALUES ($courseId, $question_id, $categoryId)"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
if ($allowMandatory) { |
|
|
|
|
@ -667,14 +665,14 @@ abstract class Question |
|
|
|
|
{ |
|
|
|
|
$courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId; |
|
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
|
|
|
$questionId = (int) $this->id; |
|
|
|
|
$questionId = (int) $this->iid; |
|
|
|
|
if (empty($courseId) || empty($questionId)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
$sql = "DELETE FROM $table |
|
|
|
|
WHERE |
|
|
|
|
question_id = $questionId AND |
|
|
|
|
c_id = ".$courseId; |
|
|
|
|
c_id = $courseId"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
@ -728,7 +726,7 @@ abstract class Question |
|
|
|
|
) { |
|
|
|
|
// removes old answers |
|
|
|
|
$sql = "DELETE FROM $table |
|
|
|
|
WHERE c_id = $course_id AND question_id = ".intval($this->id); |
|
|
|
|
WHERE c_id = $course_id AND question_id = ".intval($this->iid); |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -788,7 +786,7 @@ abstract class Question |
|
|
|
|
$picturePath = $this->getHotSpotFolderInCourse(); |
|
|
|
|
|
|
|
|
|
// if the question has got an ID |
|
|
|
|
if ($this->id) { |
|
|
|
|
if ($this->iid) { |
|
|
|
|
$pictureFilename = self::generatePictureName(); |
|
|
|
|
$img = new Image($picture); |
|
|
|
|
$img->send_image($picturePath.'/'.$pictureFilename, -1, 'jpg'); |
|
|
|
|
@ -853,7 +851,7 @@ abstract class Question |
|
|
|
|
$picturePath = $this->getHotSpotFolderInCourse(); |
|
|
|
|
|
|
|
|
|
// if the question has got an ID and if the picture exists |
|
|
|
|
if ($this->id) { |
|
|
|
|
if ($this->iid) { |
|
|
|
|
$picture = $this->picture; |
|
|
|
|
$this->picture = ''; |
|
|
|
|
|
|
|
|
|
@ -889,7 +887,7 @@ abstract class Question |
|
|
|
|
$source_path = $this->getHotSpotFolderInCourse(); |
|
|
|
|
|
|
|
|
|
// if the question has got an ID and if the picture exists |
|
|
|
|
if (!$this->id || empty($this->picture)) { |
|
|
|
|
if (!$this->iid || empty($this->picture)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -923,7 +921,7 @@ abstract class Question |
|
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
|
|
|
$sql = "UPDATE $table SET |
|
|
|
|
picture = '".Database::escape_string($picture)."' |
|
|
|
|
WHERE c_id = $course_id AND id='".intval($questionId)."'"; |
|
|
|
|
WHERE c_id = $course_id AND iid = ".intval($questionId); |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
$documentId = add_document( |
|
|
|
|
@ -1000,9 +998,9 @@ abstract class Question |
|
|
|
|
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
|
|
|
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$exerciseId = $exercise->id; |
|
|
|
|
$exerciseId = $exercise->iid; |
|
|
|
|
|
|
|
|
|
$id = $this->id; |
|
|
|
|
$id = $this->iid; |
|
|
|
|
$question = $this->question; |
|
|
|
|
$description = $this->description; |
|
|
|
|
$weighting = $this->weighting; |
|
|
|
|
@ -1033,7 +1031,7 @@ abstract class Question |
|
|
|
|
Database::update( |
|
|
|
|
$TBL_QUESTIONS, |
|
|
|
|
$params, |
|
|
|
|
['c_id = ? AND id = ?' => [$c_id, $id]] |
|
|
|
|
['c_id = ? AND iid = ?' => [$c_id, $id]] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
Event::addEvent( |
|
|
|
|
@ -1061,7 +1059,7 @@ abstract class Question |
|
|
|
|
FROM $TBL_QUESTIONS as question, |
|
|
|
|
$TBL_EXERCISE_QUESTION as test_question |
|
|
|
|
WHERE |
|
|
|
|
question.id = test_question.question_id AND |
|
|
|
|
question.iid = test_question.question_id AND |
|
|
|
|
test_question.exercice_id = ".$exerciseId." AND |
|
|
|
|
question.c_id = $c_id AND |
|
|
|
|
test_question.c_id = $c_id "; |
|
|
|
|
@ -1085,22 +1083,19 @@ abstract class Question |
|
|
|
|
if ($exercise->questionFeedbackEnabled) { |
|
|
|
|
$params['feedback'] = $this->feedback; |
|
|
|
|
} |
|
|
|
|
$this->id = Database::insert($TBL_QUESTIONS, $params); |
|
|
|
|
|
|
|
|
|
if ($this->id) { |
|
|
|
|
$sql = "UPDATE $TBL_QUESTIONS SET id = iid WHERE iid = {$this->id}"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
$this->iid = Database::insert($TBL_QUESTIONS, $params); |
|
|
|
|
|
|
|
|
|
if ($this->iid) { |
|
|
|
|
Event::addEvent( |
|
|
|
|
LOG_QUESTION_CREATED, |
|
|
|
|
LOG_QUESTION_ID, |
|
|
|
|
$this->id |
|
|
|
|
$this->iid |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
api_item_property_update( |
|
|
|
|
$this->course, |
|
|
|
|
TOOL_QUIZ, |
|
|
|
|
$this->id, |
|
|
|
|
$this->iid, |
|
|
|
|
'QuizQuestionAdded', |
|
|
|
|
api_get_user_id() |
|
|
|
|
); |
|
|
|
|
@ -1110,7 +1105,7 @@ abstract class Question |
|
|
|
|
$quizAnswer = new CQuizAnswer(); |
|
|
|
|
$quizAnswer |
|
|
|
|
->setCId($c_id) |
|
|
|
|
->setQuestionId($this->id) |
|
|
|
|
->setQuestionId($this->iid) |
|
|
|
|
->setAnswer('') |
|
|
|
|
->setPonderation(10) |
|
|
|
|
->setPosition(1) |
|
|
|
|
@ -1120,7 +1115,7 @@ abstract class Question |
|
|
|
|
$em->persist($quizAnswer); |
|
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
|
|
$id = $quizAnswer->getIid(); |
|
|
|
|
$id = $quizAnswer->getId(); |
|
|
|
|
|
|
|
|
|
if ($id) { |
|
|
|
|
$quizAnswer |
|
|
|
|
@ -1136,7 +1131,7 @@ abstract class Question |
|
|
|
|
$quizAnswer = new CQuizAnswer(); |
|
|
|
|
$quizAnswer |
|
|
|
|
->setCId($c_id) |
|
|
|
|
->setQuestionId($this->id) |
|
|
|
|
->setQuestionId($this->iid) |
|
|
|
|
->setAnswer('') |
|
|
|
|
->setPonderation(10) |
|
|
|
|
->setPosition(1) |
|
|
|
|
@ -1146,7 +1141,7 @@ abstract class Question |
|
|
|
|
$em->persist($quizAnswer); |
|
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
|
|
$id = $quizAnswer->getIid(); |
|
|
|
|
$id = $quizAnswer->getId(); |
|
|
|
|
|
|
|
|
|
if ($id) { |
|
|
|
|
$quizAnswer |
|
|
|
|
@ -1192,12 +1187,12 @@ abstract class Question |
|
|
|
|
//there's only one row per question on normal db and one document per question on search engine db |
|
|
|
|
$sql = 'SELECT * FROM %s |
|
|
|
|
WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_second_level=%s LIMIT 1'; |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id); |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->iid); |
|
|
|
|
} else { |
|
|
|
|
$sql = 'SELECT * FROM %s |
|
|
|
|
WHERE course_code=\'%s\' AND tool_id=\'%s\' |
|
|
|
|
AND ref_id_high_level=%s AND ref_id_second_level=%s LIMIT 1'; |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $exerciseId, $this->id); |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $exerciseId, $this->iid); |
|
|
|
|
} |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
|
|
|
|
|
@ -1252,7 +1247,7 @@ abstract class Question |
|
|
|
|
SE_DATA => [ |
|
|
|
|
'type' => SE_DOCTYPE_EXERCISE_QUESTION, |
|
|
|
|
'exercise_ids' => $question_exercises, |
|
|
|
|
'question_id' => (int) $this->id, |
|
|
|
|
'question_id' => (int) $this->iid, |
|
|
|
|
], |
|
|
|
|
SE_USER => (int) api_get_user_id(), |
|
|
|
|
]; |
|
|
|
|
@ -1274,7 +1269,7 @@ abstract class Question |
|
|
|
|
if ($addQs || $rmQs) { |
|
|
|
|
$sql = "DELETE FROM %s |
|
|
|
|
WHERE course_code = '%s' AND tool_id = '%s' AND ref_id_second_level = '%s'"; |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id); |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->iid); |
|
|
|
|
} else { |
|
|
|
|
$sql = "DELETE FROM %S |
|
|
|
|
WHERE |
|
|
|
|
@ -1283,7 +1278,7 @@ abstract class Question |
|
|
|
|
AND tool_id = '%s' |
|
|
|
|
AND ref_id_high_level = '%s' |
|
|
|
|
AND ref_id_second_level = '%s'"; |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $exerciseId, $this->id); |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $exerciseId, $this->iid); |
|
|
|
|
} |
|
|
|
|
Database::query($sql); |
|
|
|
|
if ($rmQs) { |
|
|
|
|
@ -1300,7 +1295,7 @@ abstract class Question |
|
|
|
|
$course_id, |
|
|
|
|
TOOL_QUIZ, |
|
|
|
|
array_shift($question_exercises), |
|
|
|
|
$this->id, |
|
|
|
|
$this->iid, |
|
|
|
|
$did |
|
|
|
|
); |
|
|
|
|
Database::query($sql); |
|
|
|
|
@ -1312,7 +1307,7 @@ abstract class Question |
|
|
|
|
VALUES ( |
|
|
|
|
NULL , '%s', '%s', %s, %s, %s |
|
|
|
|
)"; |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $exerciseId, $this->id, $did); |
|
|
|
|
$sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $exerciseId, $this->iid, $did); |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -1331,7 +1326,7 @@ abstract class Question |
|
|
|
|
public function addToList($exerciseId, $fromSave = false) |
|
|
|
|
{ |
|
|
|
|
$exerciseRelQuestionTable = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
|
|
|
$id = (int) $this->id; |
|
|
|
|
$id = (int) $this->iid; |
|
|
|
|
$exerciseId = (int) $exerciseId; |
|
|
|
|
|
|
|
|
|
// checks if the exercise ID is not in the list |
|
|
|
|
@ -1343,7 +1338,7 @@ abstract class Question |
|
|
|
|
$count = $newExercise->getQuestionCount(); |
|
|
|
|
$count++; |
|
|
|
|
$sql = "INSERT INTO $exerciseRelQuestionTable (c_id, question_id, exercice_id, question_order) |
|
|
|
|
VALUES ({$this->course['real_id']}, ".$id.", ".$exerciseId.", '$count')"; |
|
|
|
|
VALUES ({$this->course['real_id']}, $id, $exerciseId, $count)"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
// we do not want to reindex if we had just saved adnd indexed the question |
|
|
|
|
@ -1366,7 +1361,7 @@ abstract class Question |
|
|
|
|
public function removeFromList($exerciseId, $courseId = 0) |
|
|
|
|
{ |
|
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
|
|
|
$id = (int) $this->id; |
|
|
|
|
$id = (int) $this->iid; |
|
|
|
|
$exerciseId = (int) $exerciseId; |
|
|
|
|
|
|
|
|
|
// searches the position of the exercise ID in the list |
|
|
|
|
@ -1439,14 +1434,14 @@ abstract class Question |
|
|
|
|
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
$TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
|
|
|
|
|
|
|
|
$id = (int) $this->id; |
|
|
|
|
$id = (int) $this->iid; |
|
|
|
|
|
|
|
|
|
// if the question must be removed from all exercises |
|
|
|
|
if (!$deleteFromEx) { |
|
|
|
|
//update the question_order of each question to avoid inconsistencies |
|
|
|
|
$sql = "SELECT exercice_id, question_order |
|
|
|
|
FROM $TBL_EXERCISE_QUESTION |
|
|
|
|
WHERE c_id = $courseId AND question_id = ".$id; |
|
|
|
|
WHERE c_id = $courseId AND question_id = $id"; |
|
|
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
if (Database::num_rows($res) > 0) { |
|
|
|
|
@ -1464,28 +1459,28 @@ abstract class Question |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM $TBL_EXERCISE_QUESTION |
|
|
|
|
WHERE c_id = $courseId AND question_id = ".$id; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM $TBL_QUESTIONS |
|
|
|
|
WHERE c_id = $courseId AND id = ".$id; |
|
|
|
|
WHERE c_id = $courseId AND question_id = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM $TBL_REPONSES |
|
|
|
|
WHERE c_id = $courseId AND question_id = ".$id; |
|
|
|
|
WHERE c_id = $courseId 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 = $courseId AND |
|
|
|
|
question_id = ".$id; |
|
|
|
|
question_id = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
// Add extra fields. |
|
|
|
|
$extraField = new ExtraFieldValue('question'); |
|
|
|
|
$extraField->deleteValuesByItem($this->iid); |
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM $TBL_QUESTIONS |
|
|
|
|
WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
api_item_property_update( |
|
|
|
|
$this->course, |
|
|
|
|
TOOL_QUIZ, |
|
|
|
|
@ -1568,7 +1563,7 @@ abstract class Question |
|
|
|
|
$course_id = $courseInfo['real_id']; |
|
|
|
|
|
|
|
|
|
// Read the source options |
|
|
|
|
$options = self::readQuestionOption($this->id, $this->course['real_id']); |
|
|
|
|
$options = self::readQuestionOption($this->iid, $this->course['real_id']); |
|
|
|
|
|
|
|
|
|
// Inserting in the new course db / or the same course db |
|
|
|
|
$params = [ |
|
|
|
|
@ -1584,11 +1579,6 @@ abstract class Question |
|
|
|
|
$newQuestionId = Database::insert($questionTable, $params); |
|
|
|
|
|
|
|
|
|
if ($newQuestionId) { |
|
|
|
|
$sql = "UPDATE $questionTable |
|
|
|
|
SET id = iid |
|
|
|
|
WHERE iid = $newQuestionId"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
// Add extra fields. |
|
|
|
|
$extraField = new ExtraFieldValue('question'); |
|
|
|
|
$extraField->copy($this->iid, $newQuestionId); |
|
|
|
|
@ -1598,15 +1588,9 @@ abstract class Question |
|
|
|
|
foreach ($options as $item) { |
|
|
|
|
$item['question_id'] = $newQuestionId; |
|
|
|
|
$item['c_id'] = $course_id; |
|
|
|
|
unset($item['id']); |
|
|
|
|
unset($item['iid']); |
|
|
|
|
unset($item['id']); |
|
|
|
|
$id = Database::insert($TBL_QUESTION_OPTIONS, $item); |
|
|
|
|
if ($id) { |
|
|
|
|
$sql = "UPDATE $TBL_QUESTION_OPTIONS |
|
|
|
|
SET id = iid |
|
|
|
|
WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1965,9 +1949,9 @@ abstract class Question |
|
|
|
|
|
|
|
|
|
//Save normal question if NOT media |
|
|
|
|
if (MEDIA_QUESTION != $this->type) { |
|
|
|
|
$creationMode = empty($this->id); |
|
|
|
|
$creationMode = empty($this->iid); |
|
|
|
|
$this->save($exercise); |
|
|
|
|
$exercise->addToList($this->id); |
|
|
|
|
$exercise->addToList($this->iid); |
|
|
|
|
|
|
|
|
|
// Only update position in creation and when using ordered or random types. |
|
|
|
|
if ($creationMode && |
|
|
|
|
@ -1977,7 +1961,7 @@ abstract class Question |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$params = $form->exportValues(); |
|
|
|
|
$params['item_id'] = $this->id; |
|
|
|
|
$params['item_id'] = $this->iid; |
|
|
|
|
|
|
|
|
|
$extraFieldValues = new ExtraFieldValue('question'); |
|
|
|
|
$extraFieldValues->saveFieldValues($params); |
|
|
|
|
@ -2009,7 +1993,7 @@ abstract class Question |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$feedbackType = $objExercise->getFeedbackType(); |
|
|
|
|
$exerciseId = $objExercise->id; |
|
|
|
|
$exerciseId = $objExercise->iid; |
|
|
|
|
|
|
|
|
|
// 1. by default we show all the question types |
|
|
|
|
$questionTypeList = self::getQuestionTypeList(); |
|
|
|
|
@ -2108,12 +2092,8 @@ abstract class Question |
|
|
|
|
$params['name'] = $name; |
|
|
|
|
$params['position'] = $position; |
|
|
|
|
$params['c_id'] = $course_id; |
|
|
|
|
$result = self::readQuestionOption($question_id, $course_id); |
|
|
|
|
//$result = self::readQuestionOption($question_id, $course_id); |
|
|
|
|
$last_id = Database::insert($table, $params); |
|
|
|
|
if ($last_id) { |
|
|
|
|
$sql = "UPDATE $table SET id = iid WHERE iid = $last_id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $last_id; |
|
|
|
|
} |
|
|
|
|
@ -2146,11 +2126,18 @@ abstract class Question |
|
|
|
|
public static function updateQuestionOption($id, $params, $course_id) |
|
|
|
|
{ |
|
|
|
|
$table = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); |
|
|
|
|
if (isset($params['id'])) { |
|
|
|
|
// 'id' has been replaced by 'iid' but is still defined into |
|
|
|
|
// $params because of Database::select() which add this index |
|
|
|
|
// by default, so "undefine" it to avoid errors if the field |
|
|
|
|
// does not exist |
|
|
|
|
unset($params['id']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Database::update( |
|
|
|
|
$table, |
|
|
|
|
$params, |
|
|
|
|
['c_id = ? AND id = ?' => [$course_id, $id]] |
|
|
|
|
['c_id = ? AND iid = ?' => [$course_id, $id]] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -2174,7 +2161,7 @@ abstract class Question |
|
|
|
|
$question_id, |
|
|
|
|
], |
|
|
|
|
], |
|
|
|
|
'order' => 'id ASC', |
|
|
|
|
'order' => 'iid ASC', |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
@ -2263,7 +2250,7 @@ abstract class Question |
|
|
|
|
// display question category, if any |
|
|
|
|
$header = ''; |
|
|
|
|
if ($exercise->display_category_name) { |
|
|
|
|
$header = TestCategory::returnCategoryAndTitle($this->id); |
|
|
|
|
$header = TestCategory::returnCategoryAndTitle($this->iid); |
|
|
|
|
} |
|
|
|
|
$show_media = ''; |
|
|
|
|
if ($show_media) { |
|
|
|
|
@ -2313,7 +2300,7 @@ abstract class Question |
|
|
|
|
['class' => 'question_description'] |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
if (true == $score['pass']) { |
|
|
|
|
if (isset($score['pass']) && true == $score['pass']) { |
|
|
|
|
$message = Display::div( |
|
|
|
|
sprintf( |
|
|
|
|
get_lang('ReadingQuestionCongratsSpeedXReachedForYWords'), |
|
|
|
|
@ -2357,7 +2344,6 @@ abstract class Question |
|
|
|
|
* @param int Maximum result for the question |
|
|
|
|
* @param int Type of question (see constants at beginning of question.class.php) |
|
|
|
|
* @param int Question level/category |
|
|
|
|
* @param string $quiz_id |
|
|
|
|
*/ |
|
|
|
|
public function create_question( |
|
|
|
|
$quiz_id, |
|
|
|
|
@ -2381,9 +2367,8 @@ abstract class Question |
|
|
|
|
FROM $tbl_quiz_question q |
|
|
|
|
INNER JOIN $tbl_quiz_rel_question r |
|
|
|
|
ON |
|
|
|
|
q.id = r.question_id AND |
|
|
|
|
q.iid = r.question_id AND |
|
|
|
|
exercice_id = $quiz_id AND |
|
|
|
|
q.c_id = $course_id AND |
|
|
|
|
r.c_id = $course_id"; |
|
|
|
|
$rs_max = Database::query($sql); |
|
|
|
|
$row_max = Database::fetch_object($rs_max); |
|
|
|
|
@ -2401,10 +2386,6 @@ abstract class Question |
|
|
|
|
$question_id = Database::insert($tbl_quiz_question, $params); |
|
|
|
|
|
|
|
|
|
if ($question_id) { |
|
|
|
|
$sql = "UPDATE $tbl_quiz_question |
|
|
|
|
SET id = iid WHERE iid = $question_id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
// Get the max question_order |
|
|
|
|
$sql = "SELECT max(question_order) as max_order |
|
|
|
|
FROM $tbl_quiz_rel_question |
|
|
|
|
@ -2515,7 +2496,7 @@ abstract class Question |
|
|
|
|
|
|
|
|
|
if (!empty($medias)) { |
|
|
|
|
foreach ($medias as $media) { |
|
|
|
|
$media_list[$media['id']] = empty($media['question']) ? get_lang('Untitled') : $media['question']; |
|
|
|
|
$media_list[$media['iid']] = empty($media['question']) ? get_lang('Untitled') : $media['question']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -2568,7 +2549,7 @@ abstract class Question |
|
|
|
|
Database::update( |
|
|
|
|
Database::get_course_table(TABLE_QUIZ_QUESTION), |
|
|
|
|
['type' => $this->type], |
|
|
|
|
['c_id = ? AND id = ?' => [$this->course['real_id'], $this->id]] |
|
|
|
|
['iid = ?' => [$this->iid]] |
|
|
|
|
); |
|
|
|
|
$answerClasses = [ |
|
|
|
|
UNIQUE_ANSWER => 'UniqueAnswer', |
|
|
|
|
@ -2657,9 +2638,9 @@ abstract class Question |
|
|
|
|
$count = $em |
|
|
|
|
->createQuery(' |
|
|
|
|
SELECT COUNT(qq.iid) FROM ChamiloCourseBundle:CQuizRelQuestion qq |
|
|
|
|
WHERE qq.questionId = :id |
|
|
|
|
WHERE qq.questionId = :iid |
|
|
|
|
') |
|
|
|
|
->setParameters(['id' => (int) $this->id]) |
|
|
|
|
->setParameters(['iid' => (int) $this->iid]) |
|
|
|
|
->getSingleScalarResult(); |
|
|
|
|
|
|
|
|
|
return (int) $count; |
|
|
|
|
@ -2681,9 +2662,9 @@ abstract class Question |
|
|
|
|
SELECT e |
|
|
|
|
FROM ChamiloCourseBundle:CQuizRelQuestion qq |
|
|
|
|
JOIN ChamiloCourseBundle:CQuiz e |
|
|
|
|
WHERE e.iid = qq.exerciceId AND qq.questionId = :id |
|
|
|
|
WHERE e.iid = qq.exerciceId AND qq.questionId = :iid |
|
|
|
|
') |
|
|
|
|
->setParameters(['id' => (int) $this->id]) |
|
|
|
|
->setParameters(['iid' => (int) $this->iid]) |
|
|
|
|
->getResult(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -2695,7 +2676,7 @@ abstract class Question |
|
|
|
|
$result = Database::select( |
|
|
|
|
'COUNT(1) AS c', |
|
|
|
|
Database::get_course_table(TABLE_QUIZ_ANSWER), |
|
|
|
|
['where' => ['question_id = ?' => [$this->id]]], |
|
|
|
|
['where' => ['question_id = ?' => [$this->iid]]], |
|
|
|
|
'first' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
@ -2716,7 +2697,7 @@ abstract class Question |
|
|
|
|
private function resizePicture($Dimension, $Max) |
|
|
|
|
{ |
|
|
|
|
// if the question has an ID |
|
|
|
|
if (!$this->id) { |
|
|
|
|
if (!$this->iid) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|