Fixing question pool when copying an question to another course see #5164

skala
Julio Montoya 13 years ago
parent add5933892
commit f332d961e2
  1. 9
      main/exercice/answer.class.php
  2. 7
      main/exercice/question.class.php
  3. 21
      main/exercice/question_pool.php
  4. 14
      main/inc/lib/database.constants.inc.php

@ -511,7 +511,6 @@ class Answer {
* @param array course info (result of the function api_get_course_info() )
*/
function duplicate($newQuestionId, $course_info = null) {
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
if (empty($course_info)) {
$course_info = $this->course;
@ -521,7 +520,7 @@ class Answer {
$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {
//Selecting origin options
$origin_options = Question::readQuestionOption($this->selectQuestionId(), $course_info['real_id']);
@ -530,7 +529,7 @@ class Answer {
foreach($origin_options as $item) {
$new_option_list[]=$item['id'];
}
}
}
$destination_options = Question::readQuestionOption($newQuestionId, $course_info['real_id']);
$i=0;
@ -546,7 +545,7 @@ class Answer {
// if at least one answer
if ($this->nbrAnswers) {
// 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";
$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++) {
@ -572,7 +571,7 @@ class Answer {
"'$weighting','$position','$hotspot_coordinates','$hotspot_type','$destination'),";
}
$sql=api_substr($sql,0,-1);
$sql = api_substr($sql,0,-1);
Database::query($sql);
}
}

@ -1019,16 +1019,17 @@ abstract class Question
$extra = $this->extra;
//Using the same method used in the course copy to transform URLs
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
if ($course_info['db_name'] != $this->course['db_name']) {
if ($this->course['id'] != $course_info['id']) {
$description = DocumentManager::replace_urls_inside_content_html_from_copy_course($description, $this->course['id'], $course_info['id']);
$question = DocumentManager::replace_urls_inside_content_html_from_copy_course($question, $this->course['id'], $course_info['id']);
}
$course_id = $course_info['real_id'];
//Read the source options
$options = self::readQuestionOption($this->id, $this->course['real_id']);
$options = self::readQuestionOption($this->id, $course_id);
//Inserting in the new course db / or the same course db
$sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, level, extra )
VALUES('$course_id', '".Database::escape_string($question)."','".Database::escape_string($description)."','".Database::escape_string($weighting)."','".Database::escape_string($position)."','".Database::escape_string($type)."' ,'".Database::escape_string($level)."' ,'".Database::escape_string($extra)."' )";

@ -62,8 +62,8 @@ if(!empty($_GET['copy_question'])){
$copy_question = intval($_GET['copy_question']);
}
$session_id = intval($_GET['session_id']);
$selected_course = intval($_GET['selected_course']);
$session_id = intval($_GET['session_id']);
$selected_course = intval($_GET['selected_course']);
$course_id_changed = intval($_GET['course_id_changed']); // save the id of the previous course selected by user to reset menu if we detect that user change course hub 13-10-2011
$exercice_id_changed = intval($_GET['exercice_id_changed']); // save the id of the previous exercice selected by user to reset menu if we detect that user change course hub 13-10-2011
@ -94,19 +94,20 @@ if ($is_allowedToEdit) {
$origin_course_info = api_get_course_info_by_id($origin_course_id);
$current_course = api_get_course_info();
$old_question_id = $copy_question;
//Reading the source question
//Reading the source question
$old_question_obj = Question::read($old_question_id, $origin_course_id);
if ($old_question_obj) {
$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
//Duplicating the source question, in the current course
//Duplicating the source question, in the current course
$new_id = $old_question_obj->duplicate($current_course);
//Reading new question
//Reading new question
$new_question_obj = Question::read($new_id);
$new_question_obj->addToList($fromExercise);
//Reading Answers obj of the current course
//Reading Answers obj of the current course
$new_answer_obj = new Answer($old_question_id, $origin_course_id);
$new_answer_obj->read();
//Duplicating the Answers in the current course
//Duplicating the Answers in the current course
$new_answer_obj->duplicate($new_id, $current_course);
// destruction of the Question object
unset($new_question_obj);
@ -115,17 +116,15 @@ if ($is_allowedToEdit) {
$objExercise = new Exercise();
$objExercise->read($fromExercise);
}
Session::write('objExercise',$objExercise);
Session::write('objExercise', $objExercise);
}
$displayMessage = get_lang('ItemAdded');
// header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
// exit();
}
// deletes a question from the database and all exercises
if ($delete) {
// construction of the Question object
// if the question exists
if($objQuestionTmp = Question::read($delete)) {
if ($objQuestionTmp = Question::read($delete)) {
// deletes the question from all exercises
$objQuestionTmp->delete();
}

@ -191,13 +191,13 @@ define('TABLE_DROPBOX_FILE', 'dropbox_file');
define('TABLE_DROPBOX_PERSON', 'dropbox_person');
// Course quiz (or test, or exercice) tables
define('TABLE_QUIZ_QUESTION', 'quiz_question');
define('TABLE_QUIZ_TEST', 'quiz');
define('TABLE_QUIZ_ANSWER', 'quiz_answer');
define('TABLE_QUIZ_TEST_QUESTION', 'quiz_rel_question');
define('TABLE_QUIZ_QUESTION_OPTION','quiz_question_option');
define('TABLE_QUIZ_QUESTION_CATEGORY', 'quiz_question_category');
define('TABLE_QUIZ_QUESTION_REL_CATEGORY', 'quiz_question_rel_category');
define('TABLE_QUIZ_QUESTION', 'quiz_question');
define('TABLE_QUIZ_TEST', 'quiz');
define('TABLE_QUIZ_ANSWER', 'quiz_answer');
define('TABLE_QUIZ_TEST_QUESTION', 'quiz_rel_question');
define('TABLE_QUIZ_QUESTION_OPTION', 'quiz_question_option');
define('TABLE_QUIZ_QUESTION_CATEGORY', 'quiz_question_category');
define('TABLE_QUIZ_QUESTION_REL_CATEGORY', 'quiz_question_rel_category');
// Linked resource table
//@todo table exists?

Loading…
Cancel
Save