Fixing exercises problems when importing exercises see #5811

skala
Julio Montoya 13 years ago
parent b61151737e
commit a38b1df6ed
  1. 9
      main/coursecopy/classes/CourseBuilder.class.php
  2. 77
      main/coursecopy/classes/CourseRestorer.class.php
  3. 4
      main/coursecopy/classes/QuizQuestion.class.php
  4. 34
      main/coursecopy/classes/QuizQuestionOption.class.php
  5. 35
      main/inc/lib/autoload.class.php

@ -482,6 +482,15 @@ class CourseBuilder {
$db_result2 = Database::query($sql);
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);
if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) {
$table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$sql = 'SELECT * FROM '.$table_options.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
$db_result3 = Database::query($sql);
while ($obj3 = Database::fetch_object($db_result3)) {
$question_option = new QuizQuestionOption($obj3);
$question->add_option($question_option);
}
}
}
$this->course->add_resource($question);
}

@ -1167,13 +1167,14 @@ class CourseRestorer
$this->course->resources[RESOURCE_QUIZ][$id]->obj->destination_id = $new_id;
$order = 0;
foreach ($quiz->question_ids as $index => $question_id) {
$qid = $this->restore_quiz_question($question_id);
$question_order = $quiz->question_orders[$index] ? $quiz->question_orders[$index] : ++$order;
$sql = "INSERT IGNORE INTO ".$table_rel." SET c_id = ".$this->destination_course_id.", question_id = ".$qid.", exercice_id = ".$new_id.", question_order = ".$question_order;
Database::query($sql);
}
if (!empty($quiz->question_ids)) {
foreach ($quiz->question_ids as $index => $question_id) {
$qid = $this->restore_quiz_question($question_id);
$question_order = $quiz->question_orders[$index] ? $quiz->question_orders[$index] : ++$order;
$sql = "INSERT IGNORE INTO ".$table_rel." SET c_id = ".$this->destination_course_id.", question_id = ".$qid.", exercice_id = ".$new_id.", question_order = ".$question_order;
Database::query($sql);
}
}
}
}
}
@ -1199,8 +1200,6 @@ class CourseRestorer
// 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
c_id = ".$this->destination_course_id." ,
question = '".self::DBUTF8escapestring($question->question)."',
@ -1241,6 +1240,7 @@ class CourseRestorer
foreach ($question->answers as $index => $answer) {
$temp[$answer['position']] = $answer;
}
foreach ($temp as $index => $answer) {
$sql = "INSERT INTO ".$table_ans." SET
c_id = ".$this->destination_course_id." ,
@ -1256,7 +1256,7 @@ class CourseRestorer
Database::query($sql);
}
} else {
$correct_answers = array();
foreach ($question->answers as $index => $answer) {
// check resources inside html from fckeditor tool and copy correct urls into recipient course
@ -1275,6 +1275,7 @@ class CourseRestorer
hotspot_coordinates = '".$answer['hotspot_coordinates']."',
hotspot_type = '".$answer['hotspot_type']."'";
Database::query($sql);
$correct_answers[$index + 1] = $answer['correct'];
}
}
@ -1284,20 +1285,48 @@ class CourseRestorer
//Moving quiz_question_options
if ($question->quiz_type == MULTIPLE_ANSWER_TRUE_FALSE) {
$question_option_list = Question::readQuestionOption($id, $course_id);
$old_option_ids = array();
foreach ($question_option_list as $item) {
$old_id = $item['id'];
unset($item['id']);
$item['question_id'] = $new_id;
$item['c_id'] = $this->destination_course_id;
$question_option_id = Database::insert($table_options, $item);
$old_option_ids[$old_id] = $question_option_id;
}
$new_answers = Database::select('id, correct', $table_ans, array('WHERE' => array('question_id = ? AND c_id = ? '=> array($new_id, $this->destination_course_id))));
foreach ($new_answers as $answer_item) {
$params = array();
$params['correct'] = $old_option_ids[$answer_item['correct']];
$question_option_id = Database::update($table_ans, $params, array('id = ? AND c_id = ? AND question_id = ? '=> array($answer_item['id'], $this->destination_course_id, $new_id)), false);
//Question copied from the current platform
if ($question_option_list) {
$old_option_ids = array();
foreach ($question_option_list as $item) {
$old_id = $item['id'];
unset($item['id']);
$item['question_id'] = $new_id;
$item['c_id'] = $this->destination_course_id;
$question_option_id = Database::insert($table_options, $item);
$old_option_ids[$old_id] = $question_option_id;
}
if ($old_option_ids) {
$new_answers = Database::select('id, correct', $table_ans, array('WHERE' => array('question_id = ? AND c_id = ? '=> array($new_id, $this->destination_course_id))));
foreach ($new_answers as $answer_item) {
$params = array();
$params['correct'] = $old_option_ids[$answer_item['correct']];
$question_option_id = Database::update($table_ans, $params, array('id = ? AND c_id = ? AND question_id = ? '=> array($answer_item['id'], $this->destination_course_id, $new_id)), false);
}
}
} else {
$new_options = array();
if ($question->question_options) {
foreach($question->question_options as $obj) {
$item = array();
$item['question_id'] = $new_id;
$item['c_id'] = $this->destination_course_id;
$item['name'] = $obj->obj->name;
$item['position'] = $obj->obj->position;
$question_option_id = Database::insert($table_options, $item);
$new_options[$obj->obj->id] = $question_option_id;
}
//var_dump($new_options, $correct_answers);
foreach($correct_answers as $answer_id => $correct_answer) {
$params = array();
$params['correct'] = $new_options[$correct_answer];
Database::update($table_ans, $params, array('id = ? AND c_id = ? AND question_id = ? '=> array($answer_id, $this->destination_course_id, $new_id)), false);
}
}
}
}
$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;

@ -96,6 +96,10 @@ class QuizQuestion extends Resource
$this->answers[] = $answer;
}
function add_option($option_obj) {
$this->question_options[$option_obj->obj->id] = $option_obj;
}
/**
* Show this question
*/

@ -0,0 +1,34 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Exercises questions backup script
* @package chamilo.backup
*/
/**
* Code
*/
require_once 'Resource.class.php';
/**
* An QuizQuestion
* @author Bart Mollet <bart.mollet@hogent.be>
* @package chamilo.backup
*/
class QuizQuestionOption extends Resource
{
public $obj; //question_option
/**
* Create a new QuizQuestion
* @param string $question
* @param string $description
* @param int $ponderation
* @param int $type
* @param int $position
*/
function QuizQuestionOption($obj) {
parent::Resource($obj->id, RESOURCE_QUIZQUESTION);
$this->obj = $obj;
}
}

@ -2,7 +2,7 @@
/**
* Autoload Chamilo classes
*
*
* @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
@ -12,7 +12,7 @@ class Autoload
static private $is_registered = false;
/**
* Register the Chamilo autoloader on the stack.
* Register the Chamilo autoloader on the stack.
* Will only do it once so this method is repeatable.
*/
static public function register()
@ -43,14 +43,14 @@ class Autoload
$root = dirname(__FILE__) . '/../../';
/**
* WARNING
*
*
* This map is autogeneated by AutoloadClassFinder. It may be ovewrite
* by future run.
*
* If you need to manually add mappings do it at the end and clearly
* identifies that as manually added or better ensure your class is
* captured by the finder.
*
*
* If you need to manually add mappings do it at the end and clearly
* identifies that as manually added or better ensure your class is
* captured by the finder.
*
* If it comes from a different package you may want to add another autoload
* function on the stack.
*/
@ -73,7 +73,7 @@ class Autoload
$result['Agenda'] = '/main/calendar/agenda.lib.php';
$result['AjaxController'] = '/main/inc/lib/ajax_controller.class.php';
$result['Announcement'] = '/main/coursecopy/classes/Announcement.class.php';
$result['AnnouncementManager'] = '/main/announcements/announcements.inc.php';
$result['AnnouncementManager'] = '/main/announcements/announcements.inc.php';
$result['AnnouncementEmail'] = '/main/announcements/announcement_email.class.php';
$result['Answer'] = '/main/exercice/answer.class.php';
$result['AppPlugin'] = '/main/inc/lib/plugin.lib.php';
@ -585,7 +585,7 @@ class Autoload
$result['EventsMail'] = '/main/inc/lib/events_email.class.php';
$result['Exercise'] = '/main/exercice/exercise.class.php';
$result['ExerciseLink'] = '/main/gradebook/lib/be/exerciselink.class.php';
$result['Testcategory'] = '/main/exercice/testcategory.class.php';
$result['Testcategory'] = '/main/exercice/testcategory.class.php';
$result['ExerciseResult'] = '/main/exercice/exercise_result.class.php';
$result['ExerciseShowFunctions'] = '/main/inc/lib/exercise_show_functions.lib.php';
$result['FileManager'] = '/main/inc/lib/fileManage.lib.php';
@ -789,6 +789,7 @@ class Autoload
$result['QuickformForm'] = '/main/inc/lib/pear/HTML/QuickForm/Renderer/Object.php';
$result['Quiz'] = '/main/coursecopy/classes/Quiz.class.php';
$result['QuizQuestion'] = '/main/coursecopy/classes/QuizQuestion.class.php';
$result['QuizQuestionOption'] = '/main/coursecopy/classes/QuizQuestionOption.class.php';
$result['Redirect'] = '/main/inc/lib/redirect.class.php';
$result['Request'] = '/main/inc/lib/system/web/request.class.php';
$result['RequestServer'] = '/main/inc/lib/system/web/request_server.class.php';
@ -999,10 +1000,10 @@ class Autoload
}
/**
* Scan directorie for class declarations and returns an array made of
*
* Scan directorie for class declarations and returns an array made of
*
* classname => relative path
*
*
* @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
@ -1092,12 +1093,12 @@ class AutoloadClassFinder
/**
* Synchronize the autoloader map with the current file structure.
*
*
* Searches all files and sub directories for class declarations.
* Creates a map of class name to (relative) file path.
* Update the autoloader with the map declaration if $update equals true.
* Returns a map of class name to file path.
*
*
* @param string $current_dir The current directory in which we search for class declarations
*/
protected function synch($current_dir = null)
@ -1109,7 +1110,7 @@ class AutoloadClassFinder
$current_dir = $current_dir ? $current_dir : $root_dir;
$current_dir = realpath($current_dir);
//plugins are not handled by the autoloader.
//plugins are not handled by the autoloader.
if (basename($current_dir) == 'plugin') {
return $result;
}
@ -1128,7 +1129,7 @@ class AutoloadClassFinder
foreach ($classes as $class) {
/* a few classes have the same namespace and class name
* in this case we let the latest win as this may
* in this case we let the latest win as this may
* relates to different autoloader.
*/
$rel_path = realpath($path);

Loading…
Cancel
Save