No need to add c_id when saving c_quiz_answer items because this items are related to a unique question (iid), the relationship of quiz-question-course stays in c_quiz_rel_question.

skala
Julio Montoya 13 years ago
parent df666219b8
commit 249fe52343
  1. 2
      main/coursecopy/classes/CourseBuilder.class.php
  2. 2
      main/coursecopy/classes/CourseRecycler.class.php
  3. 78
      main/exercice/answer.class.php
  4. 4
      main/exercice/exercise.class.php
  5. 6
      main/exercice/hotspot_actionscript.as.php
  6. 6
      main/exercice/hotspot_answers.as.php
  7. 4
      main/exercice/hotspot_save.inc.php
  8. 6
      main/exercice/media.php
  9. 36
      main/exercice/multiple_answer.class.php
  10. 64
      main/exercice/question.class.php
  11. 7
      main/exercice/question_admin.inc.php
  12. 9
      main/exercice/question_create.php
  13. 13
      main/exercice/unique_answer.class.php

@ -499,7 +499,7 @@ class CourseBuilder
}
$question = new QuizQuestion($obj->iid, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture, $obj->level, $obj->extra, $parent_info, $categories);
$sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->iid;
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->iid;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer($obj2->iid, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);

@ -381,7 +381,7 @@ class CourseRecycler
$orphan_ids = implode(',', $orphan_ids);
$sql = "DELETE FROM ".$table_rel." WHERE c_id = ".$this->course_id." AND question_id IN(".$orphan_ids.")";
Database::query($sql);
$sql = "DELETE FROM ".$table_qui_ans." WHERE c_id = ".$this->course_id." AND question_id IN(".$orphan_ids.")";
$sql = "DELETE FROM ".$table_qui_ans." WHERE question_id IN(".$orphan_ids.")";
Database::query($sql);
$sql = "DELETE FROM ".$table_qui_que." WHERE c_id = ".$this->course_id." AND iid IN(".$orphan_ids.")";
Database::query($sql);

@ -48,7 +48,7 @@ class Answer
* @author Olivier Brouckaert
* @param integer Question ID that answers belong to
*/
function Answer($questionId, $course_id = null)
public function Answer($questionId, $course_id = null)
{
$this->questionId = intval($questionId);
$this->answer = array();
@ -59,6 +59,7 @@ class Answer
$this->hotspot_coordinates = array();
$this->hotspot_type = array();
$this->destination = array();
// clears $new_* arrays
$this->cancel();
@ -92,7 +93,7 @@ class Answer
*
* @author - Olivier Brouckaert
*/
function cancel()
public function cancel()
{
$this->new_answer = array();
$this->new_correct = array();
@ -110,7 +111,7 @@ class Answer
*
* @author - Olivier Brouckaert
*/
function read()
public function read()
{
$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
$questionId = $this->questionId;
@ -120,7 +121,8 @@ class Answer
*/
$sql = "SELECT iid, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type, destination
FROM $TBL_ANSWER
WHERE question_id ='".$questionId."' ORDER BY position";
WHERE question_id ='".$questionId."'
ORDER BY position";
$result = Database::query($sql);
$counter = 1;
@ -150,7 +152,7 @@ class Answer
* @param string DESC or ASC
* @author Frederic Vauthier
*/
function readOrderedBy($field, $order = 'ASC')
public function readOrderedBy($field, $order = 'ASC')
{
$field = Database::escape_string($field);
if (empty($field)) {
@ -165,7 +167,7 @@ class 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 iid = $questionId";
$sql = "SELECT type FROM $TBL_QUIZ WHERE iid = $questionId";
$result_question = Database::query($sql);
$question_type = Database::fetch_array($result_question);
@ -215,7 +217,7 @@ class Answer
* @author - Juan Carlos Ra<EFBFBD>a
* @return - integer - answer num
*/
function selectAutoId($id)
public function selectAutoId($id)
{
return $this->autoId[$id];
}
@ -226,7 +228,7 @@ class Answer
* @author - Olivier Brouckaert
* @return - integer - number of answers
*/
function selectNbrAnswers()
public function selectNbrAnswers()
{
return $this->nbrAnswers;
}
@ -237,7 +239,7 @@ class Answer
* @author - Olivier Brouckaert
* @return - integer - the question ID
*/
function selectQuestionId()
public function selectQuestionId()
{
return $this->questionId;
}
@ -267,13 +269,14 @@ class Answer
/**
* return array answer by id else return a bool
* @deprecated seems to be unused
*/
function selectAnswerByAutoId($auto_id)
public function selectAnswerByAutoId($auto_id)
{
$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'";
$sql = "SELECT id, answer FROM $TBL_ANSWER WHERE id_auto='$auto_id'";
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
@ -306,7 +309,7 @@ class Answer
* @author Yannick Warnier <ywarnier@beeznest.org>
* @return array List of answers where each answer is an array of (id, answer, comment, grade) and grade=weighting
*/
function getAnswersList($decode = false)
public function getAnswersList($decode = false)
{
$list = array();
for ($i = 1; $i <= $this->nbrAnswers; $i++) {
@ -346,7 +349,7 @@ class Answer
* @author Yannick Warnier <ywarnier@beeznest.org>
* @return array List of grades where grade=weighting (?)
*/
function getGradesList()
public function getGradesList()
{
$list = array();
for ($i = 0; $i < $this->nbrAnswers; $i++) {
@ -362,7 +365,7 @@ class Answer
* @author Yannick Warnier <ywarnier@beeznest.org>
* @return integer The type of the question this answer is bound to
*/
function getQuestionType()
public function getQuestionType()
{
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$sql = "SELECT type FROM $TBL_QUESTIONS WHERE c_id = {$this->course_id} AND iid = '".$this->questionId."'";
@ -381,12 +384,12 @@ class Answer
* @param - integer $id - answer ID
* @return - integer - 0 if bad answer, not 0 if good answer
*/
function isCorrect($id)
public function isCorrect($id)
{
return $this->correct[$id];
}
function getAnswerIdFromList($answer_id) {
public function getAnswerIdFromList($answer_id) {
$counter = 1;
foreach ($this->answer as $my_answer_id => $item) {
if ($answer_id == $my_answer_id) {
@ -396,7 +399,7 @@ class Answer
}
}
function getRealAnswerIdFromList($answer_id) {
public function getRealAnswerIdFromList($answer_id) {
$counter = 1;
foreach ($this->answer as $my_answer_id => $item) {
if ($answer_id == $counter) {
@ -406,7 +409,7 @@ class Answer
}
}
function getCorrectAnswerPosition($correct_id) {
public function getCorrectAnswerPosition($correct_id) {
$counter = 1;
foreach ($this->correct as $my_correct_id => $item) {
if ($correct_id == $my_correct_id) {
@ -423,7 +426,7 @@ class Answer
* @param - integer $id - answer ID
* @return - string - answer comment
*/
function selectComment($id)
public function selectComment($id)
{
return $this->comment[$id];
}
@ -435,7 +438,7 @@ class Answer
* @param - integer $id - answer ID
* @return - integer - answer weighting
*/
function selectWeighting($id)
public function selectWeighting($id)
{
return $this->weighting[$id];
}
@ -447,7 +450,7 @@ class Answer
* @param - integer $id - answer ID
* @return - integer - answer position
*/
function selectPosition($id)
public function selectPosition($id)
{
return $this->position[$id];
}
@ -459,7 +462,7 @@ class Answer
* @param integer Answer ID
* @return integer Answer position
*/
function selectHotspotCoordinates($id)
public function selectHotspotCoordinates($id)
{
return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null;
}
@ -471,7 +474,7 @@ class Answer
* @param integer Answer ID
* @return integer Answer position
*/
function selectHotspotType($id)
public function selectHotspotType($id)
{
return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null;
}
@ -519,7 +522,7 @@ class Answer
* @param integer Answer weighting
* @param integer Answer position
*/
function updateAnswers($answer, $comment, $weighting, $position, $destination)
public function updateAnswers($answer, $comment, $weighting, $position, $destination)
{
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
@ -530,8 +533,7 @@ class Answer
ponderation = '".Database::escape_string($weighting)."',
position = '".Database::escape_string($position)."',
destination = '".Database::escape_string($destination)."'
WHERE c_id = {$this->course_id} AND iid = '".Database::escape_string($position)."'
AND question_id = '".Database::escape_string($questionId)."'";
WHERE iid = '".Database::escape_string($position)."' AND question_id = '".Database::escape_string($questionId)."'";
Database::query($sql);
}
@ -540,13 +542,11 @@ class Answer
*
* @author - Olivier Brouckaert
*/
function save()
public function save()
{
$table_quiz_answer = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$questionId = intval($this->questionId);
$c_id = $this->course['real_id'];
$answersAlreadyCreated = array_keys($this->answer);
// @todo don't do this!
@ -587,8 +587,10 @@ class Answer
Database::update($table_quiz_answer, $params, array('iid = ? '=> array($update)));
$latest_insert_id = $update;
} else {
$sql = "INSERT INTO $table_quiz_answer (c_id, question_id, answer, correct, comment, ponderation, position, hotspot_coordinates,hotspot_type, destination) VALUES ";
$sql.= "($c_id, '$questionId','$answer','$correct','$comment','$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination')";
// No need to add the c_id because the answers are unique per question
$sql = "INSERT INTO $table_quiz_answer (question_id, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type, destination) VALUES ";
$sql.= "('$questionId','$answer','$correct','$comment','$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination')";
error_log($sql);
Database::query($sql);
$latest_insert_id = Database::insert_id();
}
@ -598,8 +600,9 @@ class Answer
// Delete unused answers
if (!empty($latest_insert_id)) {
$idsToDelete = implode("','", $real_correct_ids);
if (!empty($idsToDelete) && !empty($c_id) && !empty($questionId)) {
$sql = "DELETE FROM $table_quiz_answer WHERE c_id = $c_id AND question_id = $questionId AND iid NOT IN ('$idsToDelete')";
if (!empty($idsToDelete) && !empty($questionId)) {
//$sql = "DELETE FROM $table_quiz_answer WHERE c_id = $c_id AND question_id = $questionId AND iid NOT IN ('$idsToDelete')";
$sql = "DELETE FROM $table_quiz_answer WHERE question_id = $questionId AND iid NOT IN ('$idsToDelete')";
Database::query($sql);
}
}
@ -630,6 +633,7 @@ class Answer
$this->nbrAnswers = $this->new_nbrAnswers;
$this->destination = $this->new_destination;
// clears $new_* arrays
$this->cancel();
}
@ -641,7 +645,7 @@ class Answer
* @param int question id
* @param array destination course info (result of the function api_get_course_info() )
*/
function duplicate($newQuestionId, $course_info = null)
public function duplicate($newQuestionId, $course_info = null)
{
if (empty($course_info)) {
$course_info = $this->course;
@ -705,8 +709,8 @@ class Answer
$hotspot_coordinates = Database::escape_string($this->hotspot_coordinates[$i]);
$hotspot_type = Database::escape_string($this->hotspot_type[$i]);
$destination = Database::escape_string($this->destination[$i]);
$sql = "INSERT INTO $TBL_REPONSES (c_id, question_id, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type ,destination) VALUES";
$sql.= "($c_id, '$newQuestionId','$answer','$correct','$comment', '$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination')";
$sql = "INSERT INTO $TBL_REPONSES(question_id, answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type ,destination) VALUES";
$sql.= "('$newQuestionId','$answer','$correct','$comment', '$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination')";
Database::query($sql);
$new_id = Database::insert_id();
$new_ids[$answer_id] = $new_id;
@ -726,7 +730,7 @@ class Answer
}
}
function getJs()
public function getJs()
{
//if ($this->questionId == 2)
echo '<script>jsPlumb.ready(function() {

@ -2680,7 +2680,7 @@ class Exercise
$user_answer = '';
// Get answer list for matching
$sql_answer = 'SELECT iid, answer FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = "'.$questionId.'" ';
$sql_answer = 'SELECT iid, answer FROM '.$table_ans.' WHERE question_id = "'.$questionId.'" ';
$res_answer = Database::query($sql_answer);
$answer_matching = array();
@ -5130,4 +5130,4 @@ class Exercise
}
}
}
}
}

@ -18,7 +18,7 @@ include('../inc/global.inc.php');
// set vars
$questionId = intval($_GET['modifyAnswers']);
$objQuestion = Question::read($questionId);
$answer_type = $objQuestion->selectType(); //very important
$answer_type = $objQuestion->selectType(); //very important
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$picturePath = $documentPath.'/images';
@ -36,7 +36,7 @@ $course_id = api_get_course_int_id();
// Query db for answers
if ($answer_type==HOT_SPOT_DELINEATION) {
$sql = "SELECT iid, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS
WHERE c_id = $course_id AND question_id = '".Database::escape_string($questionId)."' AND hotspot_type = 'delineation'
WHERE question_id = '".Database::escape_string($questionId)."' AND hotspot_type = 'delineation'
ORDER BY iid";
} else {
$sql = "SELECT iid, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS
@ -72,7 +72,7 @@ while ($hotspot = Database::fetch_assoc($result)) {
// No error
if ($hotspot['hotspot_type'] == 'noerror') {
$output .= "&hotspot_".$hotspot_id."_type=noerror";
}
}
// This is a good answer, count + 1 for nmbr of clicks
if ($hotspot['hotspot_type'] > 0) {

@ -39,11 +39,11 @@ $course_id = api_get_course_int_id();
if ($answer_type == HOT_SPOT_DELINEATION) {
// Query db for answers
$sql = "SELECT iid, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
WHERE c_id = $course_id AND question_id = '".Database::escape_string($questionId)."' AND hotspot_type <> 'noerror'
WHERE question_id = '".Database::escape_string($questionId)."' AND hotspot_type <> 'noerror'
ORDER BY iid";
} else {
$sql = "SELECT iid, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS
WHERE c_id = $course_id AND question_id = '".Database::escape_string($questionId)."' ORDER BY iid";
WHERE question_id = '".Database::escape_string($questionId)."' ORDER BY iid";
}
$result = Database::query($sql);
// Init
@ -109,4 +109,4 @@ if(isset($_SESSION['exerciseResultCoordinates']) && $from_db==0) {
}
$output .= "&p_hotspot_answers=".api_substr($output2,0,-1)."&done=done";
$explode = explode('&', $output);
echo $output;
echo $output;

@ -39,7 +39,7 @@ if ($_GET['type'] == "poly" || $_GET['type'] == "delineation" || $_GET['type'] =
$hotspot_coordinates = api_substr($hotspot_coordinates,0,-2);
}
$course_id = api_get_course_int_id();
$sql = "UPDATE $TBL_ANSWER SET hotspot_coordinates = '".Database::escape_string($hotspot_coordinates)."',hotspot_type = '".Database::escape_string($hotspot_type)."'
WHERE c_id = $course_id AND id = '".Database::escape_string($answerId)."' AND question_id ='".Database::escape_string($questionId)."' LIMIT 1 ;";
$sql = "UPDATE $TBL_ANSWER SET hotspot_coordinates = '".Database::escape_string($hotspot_coordinates)."',hotspot_type = '".Database::escape_string($hotspot_type)."'
WHERE iid = '".Database::escape_string($answerId)."' AND question_id ='".Database::escape_string($questionId)."' LIMIT 1 ;";
$result = Database::query($sql);
echo "done=done";

@ -36,7 +36,7 @@ switch ($action) {
// question
$objQuestion->processCreation($form, null);
// answers
$objQuestion->processAnswersCreation($form, null);
$objQuestion->processAnswersCreation($form);
} else {
$form->display();
}
@ -62,7 +62,7 @@ switch ($action) {
// question
$objQuestion->processCreation($form, null);
// answers
$objQuestion->processAnswersCreation($form, null);
$objQuestion->processAnswersCreation($form);
} else {
$form->display();
}
@ -109,4 +109,4 @@ $items = array(
array('content' => Display::return_icon('add.png'), 'url' => $page_url.'&action=add')
);
echo Display::actions($items);
echo Display::grid_html('medias');
echo Display::grid_html('medias');

@ -26,7 +26,7 @@ class MultipleAnswer extends Question {
/**
* Constructor
*/
function MultipleAnswer() {
public function MultipleAnswer() {
parent::question();
$this ->type = MULTIPLE_ANSWER;
$this ->isContent = $this-> getIsContent();
@ -37,7 +37,7 @@ class MultipleAnswer extends Question {
* @param the formvalidator instance
* @param the answers number to display
*/
function createAnswersForm ($form) {
public function createAnswersForm ($form) {
$nb_answers = isset($_POST['nb_answers']) ? $_POST['nb_answers'] : 4; // The previous default value was 2. See task #1759.
$nb_answers += (isset($_POST['lessAnswers']) ? -1 : (isset($_POST['moreAnswers']) ? 1 : 0));
@ -88,10 +88,10 @@ class MultipleAnswer extends Question {
for ($i = 1 ; $i <= $nb_answers ; ++$i) {
if (isset($answer) && is_object($answer)) {
$answer_id = $answer->getRealAnswerIdFromList($i);
$defaults['answer['.$i.']'] = $answer->answer[$answer_id];
$defaults['comment['.$i.']'] = $answer->comment[$answer_id];
$defaults['weighting['.$i.']'] = Text::float_format($answer->weighting[$answer_id], 1);
$defaults['correct['.$i.']'] = $answer->correct[$answer_id];
$defaults['answer['.$i.']'] = isset($answer->answer[$answer_id]) ? $answer->answer[$answer_id] : null;
$defaults['comment['.$i.']'] = isset($answer->comment[$answer_id]) ? $answer->comment[$answer_id] : null;
$defaults['weighting['.$i.']'] = isset($answer->weighting[$answer_id]) ? Text::float_format($answer->weighting[$answer_id], 1) : null;
$defaults['correct['.$i.']'] = isset($answer->correct[$answer_id]) ? $answer->correct[$answer_id] : null;
} else {
$defaults['answer[1]'] = get_lang('DefaultMultipleAnswer2');
$defaults['comment[1]'] = get_lang('DefaultMultipleComment2');
@ -128,10 +128,10 @@ class MultipleAnswer extends Question {
$form->addElement('text', 'weighting['.$i.']',null, array('class' => "span1", 'value' => '0'));
$form -> addElement ('html', '</tr>');
}
$form -> addElement ('html', '</table>');
$form -> addElement ('html', '<br />');
$form->addElement ('html', '</table>');
$form->addElement ('html', '<br />');
$form -> add_multiple_required_rule ($boxes_names , get_lang('ChooseAtLeastOneCheckbox') , 'multiple_required');
$form->add_multiple_required_rule ($boxes_names , get_lang('ChooseAtLeastOneCheckbox') , 'multiple_required');
$navigator_info = api_get_navigator();
if ($obj_ex->edit_exercise_in_lp == true) {
@ -170,39 +170,39 @@ class MultipleAnswer extends Question {
* @param the formvalidator instance
* @param the answers number to display
*/
function processAnswersCreation($form) {
public function processAnswersCreation($form) {
$questionWeighting = $nbrGoodAnswers = 0;
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
for($i=1 ; $i <= $nb_answers ; $i++) {
for ($i=1 ; $i <= $nb_answers ; $i++) {
$answer = trim($form -> getSubmitValue('answer['.$i.']'));
$comment = trim($form -> getSubmitValue('comment['.$i.']'));
$weighting = trim($form -> getSubmitValue('weighting['.$i.']'));
$goodAnswer = trim($form -> getSubmitValue('correct['.$i.']'));
if($goodAnswer){
if ($goodAnswer) {
$weighting = abs($weighting);
} else {
$weighting = abs($weighting);
$weighting = -$weighting;
}
if($weighting > 0) {
if ($weighting > 0) {
$questionWeighting += $weighting;
}
$objAnswer -> createAnswer($answer,$goodAnswer,$comment,$weighting,$i);
$objAnswer->createAnswer($answer, $goodAnswer, $comment, $weighting,$i);
}
// saves the answers into the data base
$objAnswer -> save();
// Saves the answers into the data base.
$objAnswer->save();
// sets the total weighting of the question
// Sets the total weighting of the question.
$this->updateWeighting($questionWeighting);
$this->save();
}
function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false) {
public function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false) {
$header = parent::return_header($feedback_type, $counter, $score, $show_media);
$header .= '<table class="'.$this->question_table_class .'">
<tr>

@ -43,6 +43,7 @@ abstract class Question
public $setDefaultValues = false;
public $submitClass;
public $submitText;
public $setDefaultQuestionValues = false;
public static $questionTypes = array(
UNIQUE_ANSWER => array('unique_answer.class.php', 'UniqueAnswer'),
@ -129,10 +130,12 @@ abstract class Question
*
* @author Olivier Brouckaert
* @param int $id - question ID
* @param int $course_id
* @param Exercise
*
* @return boolean - true if question exists, otherwise false
*/
static function read($id, $course_id = null, Exercise $exercise = null)
public static function read($id, $course_id = null, Exercise $exercise = null)
{
$id = intval($id);
@ -534,9 +537,7 @@ abstract class Question
)
) {
// removes old answers
$sql = "DELETE FROM $TBL_REPONSES WHERE c_id = $course_id AND question_id='".Database::escape_string(
$this->id
)."'";
$sql = "DELETE FROM $TBL_REPONSES WHERE question_id='".Database::escape_string($this->id)."'";
Database::query($sql);
}
@ -833,32 +834,32 @@ abstract class Question
picture ='".Database::escape_string($picture)."',
extra ='".Database::escape_string($extra)."',
level ='".Database::escape_string($level)."',
parent_id = ".$this->parent_id."
WHERE c_id = $c_id AND iid = '".Database::escape_string($id)."'";
parent_id = ".$this->parent_id."
WHERE iid = '".Database::escape_string($id)."'";
//WHERE c_id = $c_id AND iid = '".Database::escape_string($id)."'";
Database::query($sql);
$this->saveCategories($category_list);
if (!empty($exerciseId)) {
api_item_property_update($this->course, TOOL_QUIZ, $id, 'QuizQuestionUpdated', api_get_user_id());
}
if (api_get_setting('search_enabled') == 'true') {
if ($exerciseId != 0) {
if (api_get_setting('search_enabled') == 'true') {
$this->search_engine_edit($exerciseId);
}
}
} else {
// Creates a new question
$sql = "SELECT max(position) FROM $TBL_QUESTIONS as question, $TBL_EXERCICE_QUESTION as test_question
WHERE question.id = test_question.question_id AND
test_question.exercice_id = '".Database::escape_string($exerciseId)."' AND
question.c_id = $c_id AND
test_question.c_id = $c_id ";
$result = Database::query($sql);
$sql = "SELECT max(position) FROM $TBL_QUESTIONS as question, $TBL_EXERCICE_QUESTION as test_question
WHERE question.id = test_question.question_id AND
test_question.exercice_id = '".Database::escape_string($exerciseId)."' AND
question.c_id = $c_id AND
test_question.c_id = $c_id ";
$result = Database::query($sql);
$current_position = Database::result($result, 0, 0);
$this->updatePosition($current_position + 1);
$position = $this->position;
$sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, picture, extra, level, parent_id) VALUES ( ".
$sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, picture, extra, level, parent_id) VALUES ( ".
" $c_id, ".
" '".Database::escape_string($question)."', ".
" '".Database::escape_string($description)."', ".
@ -879,30 +880,21 @@ abstract class Question
// If hotspot, create first answer
if ($type == HOT_SPOT || $type == HOT_SPOT_ORDER) {
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql = "INSERT INTO $TBL_ANSWERS (c_id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES (".$c_id.", '".Database::escape_string(
$this->id
)."', '', NULL , '', '10' , '1', '0;0|0|0', 'square')";
$sql = "INSERT INTO $TBL_ANSWERS (question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES ('".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'square')";
Database::query($sql);
}
if ($type == HOT_SPOT_DELINEATION) {
$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
$sql = "INSERT INTO $TBL_ANSWERS (c_id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES (".$c_id.", '".Database::escape_string(
$this->id
)."', '', NULL , '', '10' , '1', '0;0|0|0', 'delineation')";
$sql = "INSERT INTO $TBL_ANSWERS (question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )
VALUES ('".Database::escape_string($this->id)."', '', NULL , '', '10' , '1', '0;0|0|0', 'delineation')";
Database::query($sql);
}
if (api_get_setting('search_enabled') == 'true') {
if ($exerciseId != 0) {
$this->search_engine_edit($exerciseId, true);
} else {
/**
* actually there is *not* an user interface for
* creating questions without a relation with an exercise
*/
}
}
}
@ -1162,9 +1154,7 @@ abstract class Question
$sql = "DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id='".Database::escape_string($id)."'";
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 question_id='".Database::escape_string($id)."'";
Database::query($sql);
// remove the category of this question in the question_rel_category table
@ -1518,7 +1508,7 @@ abstract class Question
}
//@todo why we need this condition??
if (!isset($_GET['fromExercise'])) {
if ($this->setDefaultQuestionValues) {
switch ($answerType) {
case 1:
$this->question = get_lang('DefaultUniqueQuestion');
@ -1590,9 +1580,11 @@ abstract class Question
$params['question_id'] = $this->id;
$field_value->save_field_values($params);
// modify the exercise
$objExercise->addToList($this->id);
$objExercise->update_question_positions();
if ($objExercise) {
// modify the exercise
$objExercise->addToList($this->id);
$objExercise->update_question_positions();
}
}
}

@ -33,12 +33,15 @@ if (is_object($objQuestion)) {
if (isset($_GET['editQuestion'])) {
$objQuestion->submitClass = "btn save";
$objQuestion->submitText = get_lang('ModifyQuestion');
} else {
$objQuestion->submitClass = "btn add";
$objQuestion->submitText = get_lang('AddQuestionToExercise');
}
if (isset($_GET['fromExercise'])) {
$objQuestion->setDefaultQuestionValues = true;
}
$types_information = Question::get_question_type_list();
$form_title_extra = get_lang($types_information[$type][1]);
@ -69,7 +72,7 @@ if (is_object($objQuestion)) {
$objQuestion->processCreation($form, $objExercise);
// Answers
$objQuestion->processAnswersCreation($form, $nb_answers);
$objQuestion->processAnswersCreation($form);
// TODO: maybe here is the better place to index this tool, including answers text

@ -77,10 +77,9 @@ if ($form->validate()) {
// check feedback_type from current exercise for type of question delineation
$exercise_id = intval($values['exercice']);
$sql = "SELECT feedback_type FROM $tbl_exercices WHERE c_id = $course_id AND id = '$exercise_id'";
$rs_feedback_type = Database::query($sql);
$row_feedback_type = Database::fetch_row($rs_feedback_type);
$feedback_type = $row_feedback_type[0];
$exercise = new Exercise();
$exercise->read($exercise_id);
$feedback_type = $exercise->feedback_type;
// if question type does not belong to self-evaluation (immediate feedback) it'll send an error
if (($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1) ||
@ -115,4 +114,4 @@ function check_question_type($parameter) {
} else {
return false;
}
}
}

@ -317,8 +317,8 @@ class UniqueAnswer extends Question
*/
public function processAnswersCreation($form)
{
$questionWeighting = $nbrGoodAnswers = 0;
$correct = $form->getSubmitValue('correct');
$objAnswer = new Answer($this->id);
$nb_answers = $form->getSubmitValue('nb_answers');
@ -447,19 +447,18 @@ class UniqueAnswer extends Question
$score = filter_var($score, FILTER_SANITIZE_NUMBER_FLOAT);
$correct = filter_var($correct, FILTER_SANITIZE_NUMBER_INT);
// Get the max position
$sql = "SELECT max(position) as max_position FROM $tbl_quiz_answer "
." WHERE c_id = $course_id AND question_id = $question_id";
$sql = "SELECT max(position) as max_position FROM $tbl_quiz_answer WHERE question_id = $question_id";
$rs_max = Database::query($sql);
$row_max = Database::fetch_object($rs_max);
$position = $row_max->max_position + 1;
// Insert a new answer
$sql = "INSERT INTO $tbl_quiz_answer (c_id, question_id,answer,correct,comment,ponderation,position,destination)"
."VALUES ($course_id, $question_id,'".Database::escape_string($answer_title)."',"
$sql = "INSERT INTO $tbl_quiz_answer (question_id,answer,correct,comment,ponderation,position,destination)"
."VALUES ($question_id, '".Database::escape_string($answer_title)."',"
."$correct,'".Database::escape_string($comment)."',$score,$position, "
." '0@@0@@0@@0')";
$rs = Database::query($sql);
Database::query($sql);
if ($correct) {
$sql = "UPDATE $tbl_quiz_question SET ponderation = (ponderation + $score) WHERE c_id = $course_id AND iid = ".$question_id;
$sql = "UPDATE $tbl_quiz_question SET ponderation = (ponderation + $score) WHERE iid = ".$question_id;
$rs = Database::query($sql);
return $rs;

Loading…
Cancel
Save