Adding support when copying the course for the new table quiz_question_option

skala
Julio Montoya 15 years ago
parent 92945848d6
commit 41ecc2f698
  1. 24
      main/coursecopy/classes/CourseBuilder.class.php
  2. 43
      main/coursecopy/classes/CourseRestorer.class.php
  3. 18
      main/coursecopy/classes/QuizQuestion.class.php

@ -372,13 +372,11 @@ class CourseBuilder {
// Building normal tests.
$sql = 'SELECT * FROM '.$table_que;
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result))
{
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
while ($obj = Database::fetch_object($db_result)) {
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level, $obj->extra);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2))
{
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
}
$this->course->add_resource($question);
@ -390,23 +388,19 @@ class CourseBuilder {
' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; // active = -1 means "deleted" test.
$db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0)
{
if (Database::num_rows($db_result) > 0) {
$build_orphan_questions = true;
while ($obj = Database::fetch_object($db_result))
{
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
while ($obj = Database::fetch_object($db_result)) {
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level, $obj->extra);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.(int)$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2))
{
while ($obj2 = Database::fetch_object($db_result2)) {
$question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
}
$this->course->add_resource($question);
}
}
if ($build_orphan_questions)
{
if ($build_orphan_questions) {
//$this->course->add_resource(new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0));
}
}
@ -430,7 +424,7 @@ class CourseBuilder {
$this->course->add_resource($orphan_questions);
while ($obj = Database::fetch_object($db_result))
{
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level,$obj->extra);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2))

@ -14,6 +14,7 @@ require_once 'CourseDescription.class.php';
require_once 'CourseCopyLearnpath.class.php';
require_once 'Survey.class.php';
require_once 'SurveyQuestion.class.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
//require_once 'mkdirr.php';
//require_once 'rmdirr.php';
require_once 'Glossary.class.php';
@ -857,11 +858,9 @@ class CourseRestorer
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION, $this->course->destination_db);
$table_doc = Database :: get_course_table(TABLE_DOCUMENT, $this->course->destination_db);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_QUIZ] as $id => $quiz)
{
foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
$doc = '';
if (strlen($quiz->media) > 0)
{
if (strlen($quiz->media) > 0) {
if ($this->course->resources[RESOURCE_DOCUMENT][$quiz->media]->is_restored())
{
$sql = "SELECT path FROM ".$table_doc." WHERE id = ".$resources[RESOURCE_DOCUMENT][$quiz->media]->destination_id;
@ -870,8 +869,7 @@ class CourseRestorer
$doc = str_replace('/audio/', '', $doc->path);
}
}
if ($id != -1)
{
if ($id != -1) {
$condition_session = "";
if (!empty($session_id)) {
@ -910,11 +908,12 @@ class CourseRestorer
$qid = $this->restore_quiz_question($question_id);
$question_order = $quiz->question_orders[$index] ? $quiz->question_orders[$index] : 1;
$sql = "INSERT IGNORE INTO ".$table_rel." SET question_id = ".$qid.", exercice_id = ".$new_id.", question_order = ".$question_order;
Database::query($sql);
Database::query($sql);
}
}
}
}
/**
* Restore quiz-questions
*/
@ -925,24 +924,24 @@ class CourseRestorer
$new_id=0;
if(is_object($question))
{
if(is_object($question)) {
if ($question->is_restored())
{
return $question->destination_id;
}
$table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION, $this->course->destination_db);
$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER, $this->course->destination_db);
$table_options = Database :: get_course_table(TABLE_QUIZ_QUESTION_OPTION, $this->course->destination_db);
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($question->description, $this->course->code, $this->course->destination_path);
$sql = "INSERT INTO ".$table_que." SET question = '".addslashes($question->question)."', description = '".addslashes($question->description)."', ponderation = '".addslashes($question->ponderation)."', position = '".addslashes($question->position)."', type='".addslashes($question->quiz_type)."', picture='".addslashes($question->picture)."', level='".addslashes($question->level)."'";
$sql = "INSERT INTO ".$table_que." SET question = '".addslashes($question->question)."', description = '".addslashes($question->description)."', ponderation = '".addslashes($question->ponderation)."', position = '".addslashes($question->position)."', type='".addslashes($question->quiz_type)."', picture='".addslashes($question->picture)."', level='".addslashes($question->level)."', extra='".addslashes($question->extra)."'";
Database::query($sql);
$new_id = Database::insert_id();
if ($question->quiz_type == 4) { // for answer type matching
if ($question->quiz_type == MATCHING) { // for answer type matching
foreach ($question->answers as $index => $answer) {
$sql = "INSERT INTO ".$table_ans." SET id= '".$answer['id']."',question_id = '".$new_id."', answer = '".Database::escape_string($answer['answer'])."', correct = '".$answer['correct']."', comment = '".Database::escape_string($answer['comment'])."', ponderation='".$answer['ponderation']."', position = '".$answer['position']."', hotspot_coordinates = '".$answer['hotspot_coordinates']."', hotspot_type = '".$answer['hotspot_type']."'";
Database::query($sql);
@ -951,13 +950,31 @@ class CourseRestorer
foreach ($question->answers as $index => $answer) {
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['answer'], $this->course->code, $this->course->destination_path);
$answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['answer'], $this->course->code, $this->course->destination_path);
$answer['comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['comment'], $this->course->code, $this->course->destination_path);
$sql = "INSERT INTO ".$table_ans." SET id= '". ($index +1)."',question_id = '".$new_id."', answer = '".Database::escape_string($answer['answer'])."', correct = '".$answer['correct']."', comment = '".Database::escape_string($answer['comment'])."', ponderation='".$answer['ponderation']."', position = '".$answer['position']."', hotspot_coordinates = '".$answer['hotspot_coordinates']."', hotspot_type = '".$answer['hotspot_type']."'";
Database::query($sql);
}
}
}
//Moving quiz_question_options
if ($question->quiz_type == MULTIPLE_ANSWER_TRUE_FALSE) {
$question_option_list = Question::readQuestionOption($id);
$old_option_ids = array();
foreach ($question_option_list as $item) {
$old_id = $item['id'];
unset($item['id']);
$item['question_id'] = $new_id;
$question_option_id = Database::insert($table_options, $item);
$old_option_ids[$old_id] = $question_option_id;
}
$new_answers = Database::find($table_ans,'id, correct', array('question_id = ?'=>$new_id));
foreach ($new_answers as $answer_item) {
$params['correct'] = $old_option_ids[$answer_item['correct']];
$question_option_id = Database::update_query($table_ans, $params, array('id = ?'=>$answer_item['id']));
}
}
$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
}
return $new_id;

@ -6,7 +6,7 @@ require_once 'Resource.class.php';
/**
* An QuizQuestion
* @author Bart Mollet <bart.mollet@hogent.be>
* @package dokeos.backup
* @package chamilo.backup
*/
class QuizQuestion extends Resource
{
@ -42,6 +42,8 @@ class QuizQuestion extends Resource
* Picture
*/
var $picture;
var $extra;
/**
* Create a new QuizQuestion
* @param string $question
@ -50,8 +52,7 @@ class QuizQuestion extends Resource
* @param int $type
* @param int $position
*/
function QuizQuestion($id,$question,$description,$ponderation,$type,$position,$picture,$level)
{
function QuizQuestion($id,$question,$description,$ponderation,$type,$position,$picture,$level, $extra) {
parent::Resource($id,RESOURCE_QUIZQUESTION);
$this->question = $question;
$this->description = $description;
@ -61,12 +62,13 @@ class QuizQuestion extends Resource
$this->picture = $picture;
$this->level = $level;
$this->answers = array();
$this->extra = $extra;
}
/**
* Add an answer to this QuizQuestion
*/
function add_answer($answer_id, $answer_text,$correct,$comment,$ponderation,$position,$hotspot_coordinates,$hotspot_type)
{
function add_answer($answer_id, $answer_text,$correct,$comment,$ponderation,$position,$hotspot_coordinates,$hotspot_type) {
$answer = array();
$answer['id'] = $answer_id;
$answer['answer'] = $answer_text;
@ -78,12 +80,12 @@ class QuizQuestion extends Resource
$answer['hotspot_type'] = $hotspot_type;
$this->answers[] = $answer;
}
/**
* Show this question
*/
function show()
{
function show() {
parent::show();
echo $this->question;
}
}
}
Loading…
Cancel
Save