|
|
|
@ -49,7 +49,7 @@ class Answer { |
|
|
|
|
* @param integer Question ID that answers belong to |
|
|
|
|
*/ |
|
|
|
|
function Answer($questionId, $course_id = null) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->questionId = intval($questionId); |
|
|
|
|
$this->answer = array(); |
|
|
|
|
$this->correct = array(); |
|
|
|
@ -61,19 +61,19 @@ class Answer { |
|
|
|
|
$this->destination = array(); |
|
|
|
|
// clears $new_* arrays |
|
|
|
|
$this->cancel(); |
|
|
|
|
|
|
|
|
|
if (!empty($course_id)) { |
|
|
|
|
|
|
|
|
|
if (!empty($course_id)) { |
|
|
|
|
$course_info = api_get_course_info_by_id($course_id); |
|
|
|
|
} else { |
|
|
|
|
} else { |
|
|
|
|
$course_info = api_get_course_info(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->course = $course_info; |
|
|
|
|
$this->course_id = $course_info['real_id']; |
|
|
|
|
$this->course_id = $course_info['real_id']; |
|
|
|
|
|
|
|
|
|
// fills arrays |
|
|
|
|
$objExercise = new Exercise($this->course_id); |
|
|
|
|
$objExercise->read($_REQUEST['exerciseId']); |
|
|
|
|
$objExercise->read($_REQUEST['exerciseId']); |
|
|
|
|
if ($objExercise->random_answers=='1') { |
|
|
|
|
$this->readOrderedBy('rand()', '');// randomize answers |
|
|
|
|
} else { |
|
|
|
@ -103,10 +103,10 @@ class Answer { |
|
|
|
|
* |
|
|
|
|
* @author - Olivier Brouckaert |
|
|
|
|
*/ |
|
|
|
|
function read() { |
|
|
|
|
function read() { |
|
|
|
|
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
$questionId = $this->questionId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql="SELECT id, id_auto, answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination FROM |
|
|
|
|
$TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id ='".$questionId."' ORDER BY position"; |
|
|
|
|
|
|
|
|
@ -119,7 +119,7 @@ class Answer { |
|
|
|
|
$this->answer[$i] = $object->answer; |
|
|
|
|
$this->correct[$i] = $object->correct; |
|
|
|
|
$this->comment[$i] = $object->comment; |
|
|
|
|
$this->weighting[$i] = $object->ponderation; |
|
|
|
|
$this->weighting[$i] = $object->ponderation; |
|
|
|
|
$this->position[$i] = $object->position; |
|
|
|
|
$this->hotspot_coordinates[$i] = $object->hotspot_coordinates; |
|
|
|
|
$this->hotspot_type[$i] = $object->hotspot_type; |
|
|
|
@ -135,30 +135,30 @@ class Answer { |
|
|
|
|
* @param string DESC or ASC |
|
|
|
|
* @author Frederic Vauthier |
|
|
|
|
*/ |
|
|
|
|
function readOrderedBy($field, $order='ASC') { |
|
|
|
|
function readOrderedBy($field, $order='ASC') { |
|
|
|
|
$field = Database::escape_string($field); |
|
|
|
|
if (empty($field)) { |
|
|
|
|
$field = 'position'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($order != 'ASC' && $order!='DESC') { |
|
|
|
|
$order = 'ASC'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
$TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
|
|
|
$questionId=intval($this->questionId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT type FROM $TBL_QUIZ WHERE c_id = {$this->course_id} AND id = $questionId"; |
|
|
|
|
$result_question=Database::query($sql); |
|
|
|
|
$question_type=Database::fetch_array($result_question); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql="SELECT answer,correct,comment,ponderation,position, hotspot_coordinates, hotspot_type, destination, id_auto " . |
|
|
|
|
"FROM $TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id='".$questionId."' " . |
|
|
|
|
"ORDER BY $field $order"; |
|
|
|
|
$result=Database::query($sql); |
|
|
|
|
|
|
|
|
|
"ORDER BY $field $order"; |
|
|
|
|
$result=Database::query($sql); |
|
|
|
|
|
|
|
|
|
$i=1; |
|
|
|
|
// while a record is found |
|
|
|
|
$doubt_data = null; |
|
|
|
@ -175,9 +175,9 @@ class Answer { |
|
|
|
|
$this->destination[$i] = $object->destination; |
|
|
|
|
$this->autoId[$i] = $object->id_auto; |
|
|
|
|
$i++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($question_type['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($question_type['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) { |
|
|
|
|
$this->answer[$i] = $doubt_data->answer; |
|
|
|
|
$this->correct[$i] = $doubt_data->correct; |
|
|
|
|
$this->comment[$i] = $doubt_data->comment; |
|
|
|
@ -185,7 +185,7 @@ class Answer { |
|
|
|
|
$this->position[$i] = $doubt_data->position; |
|
|
|
|
$this->destination[$i] = $doubt_data->destination; |
|
|
|
|
$this->autoId[$i] = $doubt_data->id_auto; |
|
|
|
|
$i++; |
|
|
|
|
$i++; |
|
|
|
|
} |
|
|
|
|
$this->nbrAnswers=$i-1; |
|
|
|
|
} |
|
|
|
@ -246,8 +246,8 @@ class Answer { |
|
|
|
|
* return array answer by id else return a bool |
|
|
|
|
*/ |
|
|
|
|
function selectAnswerByAutoId($auto_id) { |
|
|
|
|
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
|
|
|
|
|
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
|
|
|
|
|
$auto_id = intval($auto_id); |
|
|
|
|
$sql="SELECT id, answer FROM $TBL_ANSWER WHERE c_id = {$this->course_id} AND id_auto='$auto_id'"; |
|
|
|
|
$rs = Database::query($sql); |
|
|
|
@ -283,13 +283,13 @@ class Answer { |
|
|
|
|
$list = array(); |
|
|
|
|
for($i = 1; $i<=$this->nbrAnswers;$i++){ |
|
|
|
|
if(!empty($this->answer[$i])){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Avoid problems when parsing elements with accents |
|
|
|
|
if ($decode) { |
|
|
|
|
$this->answer[$i] = api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding()); |
|
|
|
|
$this->comment[$i] = api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$list[] = array( |
|
|
|
|
'id' => $i, |
|
|
|
|
'answer' => $this->answer[$i], |
|
|
|
@ -420,7 +420,8 @@ class Answer { |
|
|
|
|
* @param coordinates Coordinates for hotspot exercises (optional) |
|
|
|
|
* @param integer Type for hotspot exercises (optional) |
|
|
|
|
*/ |
|
|
|
|
function createAnswer($answer,$correct,$comment,$weighting,$position,$new_hotspot_coordinates = null, $new_hotspot_type = null, $destination='') { |
|
|
|
|
function createAnswer($answer,$correct,$comment,$weighting, $position, $new_hotspot_coordinates = null, $new_hotspot_type = null, $destination='') |
|
|
|
|
{ |
|
|
|
|
$this->new_nbrAnswers++; |
|
|
|
|
$id=$this->new_nbrAnswers; |
|
|
|
|
$this->new_answer[$id]=$answer; |
|
|
|
@ -442,16 +443,17 @@ class Answer { |
|
|
|
|
* @param integer Answer weighting |
|
|
|
|
* @param integer Answer position |
|
|
|
|
*/ |
|
|
|
|
function updateAnswers($answer,$comment, $correct, $weighting,$position,$destination) { |
|
|
|
|
function updateAnswers($answer,$comment, $correct, $weighting, $position, $destination) |
|
|
|
|
{ |
|
|
|
|
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
|
|
|
|
|
$questionId=$this->questionId; |
|
|
|
|
$sql = "UPDATE $TBL_REPONSES SET |
|
|
|
|
$sql = "UPDATE $TBL_REPONSES SET |
|
|
|
|
answer = '".Database::escape_string($answer)."', |
|
|
|
|
comment = '".Database::escape_string($comment)."', |
|
|
|
|
correct = '".Database::escape_string($correct)."', |
|
|
|
|
ponderation = '".Database::escape_string($weighting)."', |
|
|
|
|
position = '".Database::escape_string($position)."', |
|
|
|
|
correct = '".Database::escape_string($correct)."', |
|
|
|
|
ponderation = '".Database::escape_string($weighting)."', |
|
|
|
|
position = '".Database::escape_string($position)."', |
|
|
|
|
destination = '".Database::escape_string($destination)."' |
|
|
|
|
WHERE c_id = {$this->course_id} AND id = '".Database::escape_string($position)."' |
|
|
|
|
AND question_id = '".Database::escape_string($questionId)."'"; |
|
|
|
@ -463,17 +465,17 @@ class Answer { |
|
|
|
|
* |
|
|
|
|
* @author - Olivier Brouckaert |
|
|
|
|
*/ |
|
|
|
|
function save() { |
|
|
|
|
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
$table_track_e_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
|
|
|
|
function save() |
|
|
|
|
{ |
|
|
|
|
$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
$questionId = intval($this->questionId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$c_id = $this->course['real_id']; |
|
|
|
|
// inserts new answers into data base |
|
|
|
|
$flag = 0; |
|
|
|
|
$sql = "INSERT INTO $TBL_REPONSES (c_id, id, question_id, answer, correct, comment, ponderation, position, hotspot_coordinates,hotspot_type, destination) VALUES "; |
|
|
|
|
$sql = "INSERT INTO $TBL_REPONSES (c_id, id, question_id, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type, destination) VALUES "; |
|
|
|
|
for ($i=1;$i <= $this->new_nbrAnswers; $i++) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$answer = Database::escape_string($this->new_answer[$i]); |
|
|
|
|
$correct = Database::escape_string($this->new_correct[$i]); |
|
|
|
|
$comment = Database::escape_string($this->new_comment[$i]); |
|
|
|
@ -482,17 +484,26 @@ class Answer { |
|
|
|
|
$hotspot_coordinates = Database::escape_string($this->new_hotspot_coordinates[$i]); |
|
|
|
|
$hotspot_type = Database::escape_string($this->new_hotspot_type[$i]); |
|
|
|
|
$destination = Database::escape_string($this->new_destination[$i]); |
|
|
|
|
|
|
|
|
|
if (!(isset($this->position[$i]))) { |
|
|
|
|
$flag = 1; |
|
|
|
|
$sql.="($c_id, '$i','$questionId','$answer','$correct','$comment','$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination'),"; |
|
|
|
|
} else { |
|
|
|
|
// https://support.chamilo.org/issues/6558 |
|
|
|
|
// function updateAnswers already escape_string, error if we do it twice. Feed function updateAnswers with none escaped strings |
|
|
|
|
$this->updateAnswers($this->new_answer[$i], $this->new_comment[$i], $this->new_correct[$i], $this->new_weighting[$i], $this->new_position[$i], $this->new_destination[$i]); |
|
|
|
|
$this->updateAnswers( |
|
|
|
|
$this->new_answer[$i], |
|
|
|
|
$this->new_comment[$i], |
|
|
|
|
$this->new_correct[$i], |
|
|
|
|
$this->new_weighting[$i], |
|
|
|
|
$this->new_position[$i], |
|
|
|
|
$this->new_destination[$i] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($flag == 1) { |
|
|
|
|
$sql = api_substr($sql,0,-1); |
|
|
|
|
$sql = api_substr($sql,0,-1); |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
if (count($this->position) > $this->new_nbrAnswers) { |
|
|
|
@ -503,7 +514,7 @@ class Answer { |
|
|
|
|
Database::query($sql); |
|
|
|
|
$i++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// moves $new_* arrays |
|
|
|
@ -518,7 +529,7 @@ class Answer { |
|
|
|
|
$this->nbrAnswers=$this->new_nbrAnswers; |
|
|
|
|
$this->destination=$this->new_destination; |
|
|
|
|
// clears $new_* arrays |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->cancel(); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
@ -526,38 +537,38 @@ class Answer { |
|
|
|
|
* |
|
|
|
|
* @author Olivier Brouckaert |
|
|
|
|
* @param int question id |
|
|
|
|
* @param array destination course info (result of the function api_get_course_info() ) |
|
|
|
|
* @param array destination course info (result of the function api_get_course_info() ) |
|
|
|
|
*/ |
|
|
|
|
function duplicate($newQuestionId, $course_info = null) { |
|
|
|
|
function duplicate($newQuestionId, $course_info = null) { |
|
|
|
|
if (empty($course_info)) { |
|
|
|
|
$course_info = $this->course; |
|
|
|
|
} else { |
|
|
|
|
$course_info = $course_info; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Selecting origin options |
|
|
|
|
$origin_options = Question::readQuestionOption($this->selectQuestionId(), $this->course['real_id']); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($origin_options)) { |
|
|
|
|
foreach($origin_options as $item) { |
|
|
|
|
$new_option_list[]=$item['id']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$destination_options = Question::readQuestionOption($newQuestionId, $course_info['real_id']); |
|
|
|
|
$i=0; |
|
|
|
|
$fixed_list = array(); |
|
|
|
|
if (!empty($destination_options)) { |
|
|
|
|
foreach($destination_options as $item) { |
|
|
|
|
foreach($destination_options as $item) { |
|
|
|
|
$fixed_list[$new_option_list[$i]] = $item['id']; |
|
|
|
|
$i++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if at least one answer |
|
|
|
@ -565,20 +576,20 @@ class Answer { |
|
|
|
|
// inserts new answers into data base |
|
|
|
|
$sql = "INSERT INTO $TBL_REPONSES (c_id, id,question_id,answer,correct,comment, ponderation,position,hotspot_coordinates,hotspot_type,destination) VALUES"; |
|
|
|
|
$c_id = $course_info['real_id']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ($i=1;$i <= $this->nbrAnswers;$i++) { |
|
|
|
|
if ($this->course['id'] != $course_info['id']) { |
|
|
|
|
if ($this->course['id'] != $course_info['id']) { |
|
|
|
|
$this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course($this->answer[$i],$this->course['id'], $course_info['id']) ; |
|
|
|
|
$this->comment[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course($this->comment[$i],$this->course['id'], $course_info['id']) ; |
|
|
|
|
$this->comment[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course($this->comment[$i],$this->course['id'], $course_info['id']) ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$answer = Database::escape_string($this->answer[$i]); |
|
|
|
|
$correct = Database::escape_string($this->correct[$i]); |
|
|
|
|
|
|
|
|
|
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ) { |
|
|
|
|
|
|
|
|
|
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ) { |
|
|
|
|
$correct = $fixed_list[intval($correct)]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$comment = Database::escape_string($this->comment[$i]); |
|
|
|
|
$weighting = Database::escape_string($this->weighting[$i]); |
|
|
|
|
$position = Database::escape_string($this->position[$i]); |
|
|
|
@ -593,4 +604,4 @@ class Answer { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
endif; |
|
|
|
|
endif; |
|
|
|
|