📄 courserestorer.class.php
字号:
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; $doc = api_sql_query($sql, __FILE__, __LINE__); $doc = Database::fetch_object($doc); $doc = str_replace('/audio/', '', $doc->path); } } $sql = "INSERT INTO ".$table_qui." SET title = '".Database::escape_string($quiz->title)."', description = '".Database::escape_string($quiz->description)."', type = '".$quiz->quiz_type."', random = '".$quiz->random."', active = '".$quiz->active."', sound = '".Database::escape_string($doc)."' "; api_sql_query($sql, __FILE__, __LINE__); $new_id = Database::get_last_insert_id(); $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id; foreach ($quiz->question_ids as $index => $question_id) { $qid = $this->restore_quiz_question($question_id); $sql = "INSERT IGNORE INTO ".$table_rel." SET question_id = ".$qid.", exercice_id = ".$new_id.""; api_sql_query($sql, __FILE__, __LINE__); } } } } /** * Restore quiz-questions */ function restore_quiz_question($id) { $resources = $this->course->resources; $question = $resources[RESOURCE_QUIZQUESTION][$id]; $new_id=0; 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); $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)."'"; api_sql_query($sql, __FILE__, __LINE__); $new_id = Database::get_last_insert_id(); foreach ($question->answers as $index => $answer) { $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']."'"; api_sql_query($sql, __FILE__, __LINE__); } $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id; } return $new_id; } /** * Restore Quiz */ function restore_surveys() { if ($this->course->has_resources(RESOURCE_SURVEY)) { $table_sur = Database :: get_course_table(TABLE_SURVEY, $this->course->destination_db); $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION, $this->course->destination_db); $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION, $this->course->destination_db); $resources = $this->course->resources; foreach ($resources[RESOURCE_SURVEY] as $id => $survey) { $doc = ''; $sql = "INSERT INTO ".$table_sur." " . "SET code = '".Database::escape_string($survey->code)."', " . "title = '".Database::escape_string($survey->title)."', " . "subtitle = '".Database::escape_string($survey->subtitle)."', " . "author = '".Database::escape_string($survey->author)."', " . "lang = '".Database::escape_string($survey->lang)."', " . "avail_from = '".Database::escape_string($survey->avail_from)."', " . "avail_till = '".Database::escape_string($survey->avail_till)."', " . "is_shared = '".Database::escape_string($survey->is_shared)."', " . "template = '".Database::escape_string($survey->template)."', " . "intro = '".Database::escape_string($survey->intro)."', " . "surveythanks = '".Database::escape_string($survey->surveythanks)."', " . "creation_date = '".Database::escape_string($survey->creation_date)."', " . "invited = '0', " . "answered = '0', " . "invite_mail = '".Database::escape_string($survey->invite_mail)."', " . "reminder_mail = '".Database::escape_string($survey->reminder_mail)."'"; api_sql_query($sql, __FILE__, __LINE__); $new_id = Database::get_last_insert_id(); $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id; foreach ($survey->question_ids as $index => $question_id) { $qid = $this->restore_survey_question($question_id); $sql = "UPDATE ".$table_que." " . "SET survey_id = ".$new_id." WHERE " . "question_id = ".$qid.""; api_sql_query($sql, __FILE__, __LINE__); $sql = "UPDATE ".$table_ans." ". "SET survey_id = ".$new_id." WHERE " . "question_id = ".$qid.""; api_sql_query($sql, __FILE__, __LINE__); } } } } /** * Restore survey-questions */ function restore_survey_question($id) { $resources = $this->course->resources; $question = $resources[RESOURCE_SURVEYQUESTION][$id]; $new_id=0; if(is_object($question)) { if ($question->is_restored()) { return $question->destination_id; } $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION, $this->course->destination_db); $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION, $this->course->destination_db); $sql = "INSERT INTO ".$table_que." " . "SET survey_id = '".addslashes($question->survey_id)."', " . "survey_question = '".addslashes($question->survey_question)."', " . "survey_question_comment = '".addslashes($question->survey_question_comment)."', " . "type = '".addslashes($question->survey_question_type)."', " . "display = '".addslashes($question->display)."', " . "sort = '".addslashes($question->sort)."', " . "shared_question_id = '".addslashes($question->shared_question_id)."', " . "max_value = '".addslashes($question->max_value)."' "; api_sql_query($sql, __FILE__, __LINE__); $new_id = Database::get_last_insert_id(); foreach ($question->answers as $index => $answer) { $sql = "INSERT INTO ".$table_ans." " . "SET " . "question_id = '".addslashes($new_id)."', " . "option_text = '".addslashes($answer['option_text'])."', " . "sort = '".addslashes($answer['sort'])."', " . "survey_id = '".addslashes($question->survey_id)."'"; api_sql_query($sql, __FILE__, __LINE__); } $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id; } return $new_id; } /** * Restore learnpaths */ function restore_learnpaths() { if ($this->course->has_resources(RESOURCE_LEARNPATH)) { $table_main = Database :: get_course_table(TABLE_LP_MAIN, $this->course->destination_db); $table_item = Database :: get_course_table(TABLE_LP_ITEM, $this->course->destination_db); $table_tool = Database::get_course_table(TABLE_TOOL_LIST, $this->course->destination_db); $resources = $this->course->resources; $prereq_old = array (); $item_old_id = array (); foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) { $sql = "INSERT INTO ".$table_main." " . "SET lp_type = '".$lp->lp_type."', " . "name = '".Database::escape_string($lp->name)."', " . "path = '".Database::escape_string($lp->path)."', " . "ref = '".$lp->ref."', " . "description = '".Database::escape_string($lp->description)."', " . "content_local = '".Database::escape_string($lp->content_local)."', " . "default_encoding = '".Database::escape_string($lp->default_encoding)."', " . "default_view_mod = '".Database::escape_string($lp->default_view_mod)."', " . "prevent_reinit = '".Database::escape_string($lp->prevent_reinit)."', " . "force_commit = '".Database::escape_string($lp->force_commit)."', " . "content_maker = '".Database::escape_string($lp->content_maker)."', " . "display_order = '".Database::escape_string($lp->display_order)."', " . "js_lib= '".Database::escape_string($lp->js_lib)."', " . "content_license= '".Database::escape_string($lp->content_license)."', " . "debug= '".Database::escape_string($lp->debug)."' "; api_sql_query($sql, __FILE__, __LINE__); $new_lp_id = Database::get_last_insert_id(); if($lp->visibility) { $sql = "INSERT INTO $table_tool SET name='".Database::escape_string($lp->name)."', link='newscorm/lp_controller.php?action=view&lp_id=$new_lp_id', image='scormbuilder.gif', visibility='1', admin='0', address='squaregrey.gif'"; api_sql_query($sql, __FILE__, __LINE__); } $new_item_ids = array(); $parent_item_ids = array(); $previous_item_ids = array(); $next_item_ids = array(); foreach ($lp->get_items() as $index => $item) { /* if ($item['id'] != 0) { // Links in learnpath have types 'Link _self' or 'Link _blank'. We only need 'Link' here. $type_parts = explode(' ',$item['type']); $item['id'] = $this->course->resources[$type_parts[0]][$item['id']]->destination_id; } */ //Get the new ref ID for all items that are not sco (dokeos quizzes, documents, etc) $ref = ''; if(!empty($item['ref']) && $lp->lp_type!='2'){ $ref = $this->get_new_id($item['item_type'],$item['ref']); }else{ $ref = $item['ref']; } //Dealing with path the same way as ref as some data has been put into path when it's a //local resource $path = Database::escape_string($item['path']); if(strval(intval($path)) === $path) { $path = $this->get_new_id($item['item_type'],$path); } $sql = "INSERT INTO ".$table_item." SET " . "lp_id = '".$new_lp_id."', " . "item_type='".$item['item_type']."', " . "ref = '".$ref."', " . "title = '".Database::escape_string($item['title'])."', " . "description ='".Database::escape_string($item['description'])."', " . "path = '".$path."', " . "min_score = '".$item['min_score']."', " . "max_score = '".$item['max_score']."', " . "mastery_score = '".$item['mastery_score']."', " . "parent_item_id = '".$item['parent_item_id']."', " . "previous_item_id = '".$item['previous_item_id']."', " . "next_item_id = '".$item['next_item_id']."', " . "display_order = '".$item['display_order']."', " . "prerequisite = '".Database::escape_string($item['prerequisite'])."', " . "parameters='".Database::escape_string($item['parameters'])."', " . "launch_data = '".Database::escape_string($item['launch_dataprereq_type'])."'"; api_sql_query($sql, __FILE__, __LINE__); $new_item_id = Database::get_last_insert_id(); //save a link between old and new item IDs $new_item_ids[$item['id']] = $new_item_id; //save a reference of items that need a parent_item_id refresh $parent_item_ids[$new_item_id] = $item['parent_item_id']; //save a reference of items that need a previous_item_id refresh $previous_item_ids[$new_item_id] = $item['previous_item_id']; //save a reference of items that need a next_item_id refresh $next_item_ids[$new_item_id] = $item['next_item_id']; } foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) { $parent_new_id = 0; if($parent_item_old_id != 0){ $parent_new_id = $new_item_ids[$parent_item_old_id]; } $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."' WHERE id = '".$new_item_id."'"; api_sql_query($sql, __FILE__, __LINE__); } foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) { $previous_new_id = 0; if($previous_item_old_id != 0){ $previous_new_id = $new_item_ids[$previous_item_old_id]; } $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."' WHERE id = '".$new_item_id."'"; api_sql_query($sql, __FILE__, __LINE__); } foreach ($next_item_ids as $new_item_id => $next_item_old_id) { $next_new_id = 0; if($next_item_old_id != 0){ $next_new_id = $new_item_ids[$next_item_old_id]; } $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."' WHERE id = '".$new_item_id."'"; api_sql_query($sql, __FILE__, __LINE__); } $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id; } } } /** * Gets the new ID of one specific tool item from the tool name and the old ID * @param string Tool name * @param integer Old ID * @return integer New ID */ function get_new_id($tool,$ref) { //transform $tool into one backup/restore constant if($tool == 'hotpotatoes'){$tool = 'document';} if(!empty($this->course->resources[$tool][$ref]->destination_id)){ return $this->course->resources[$tool][$ref]->destination_id; } return ''; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -