Minor - cosmetic changes

skala
Julio Montoya 13 years ago
parent 0dbce703c1
commit e464d3804b
  1. 209
      main/coursecopy/classes/CourseRestorer.class.php

@ -56,19 +56,19 @@ class CourseRestorer
var $file_option;
var $set_tools_invisible_by_default;
var $skip_content;
var $tools_to_restore = array(
var $tools_to_restore = array(
'announcements',
'attendance',
'course_descriptions',
'documents',
'documents',
'events',
'forum_category',
'forum_category',
'forums',
// 'forum_topics',
'glossary',
'quizzes',
'links',
'learnpaths',
'quizzes',
'links',
'learnpaths',
'surveys',
//'scorm_documents', ??
'tool_intro',
@ -130,8 +130,8 @@ class CourseRestorer
$this->course->destination_path = $course_info['path'];
}
$this->destination_course_id = $course_info['real_id'];
//Getting first teacher (for the forums)
//Getting first teacher (for the forums)
$teacher_list = CourseManager::get_teacher_list_from_course_code($course_info['code']);
$this->first_teacher_id = api_get_user_id();
if (!empty($teacher_list)) {
@ -301,7 +301,7 @@ class CourseRestorer
$table = Database :: get_course_table(TABLE_DOCUMENT);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
//$dirs = explode('/', dirname($document->path));
@ -311,7 +311,7 @@ class CourseRestorer
} else {
$my_session_id = $session_id;
}
if ($document->file_type == FOLDER) {
$visibility = $document->item_properties[0]['visibility'];
if (!empty($document->title)) {
@ -321,17 +321,17 @@ class CourseRestorer
}
$new = substr($document->path, 8);
if (!is_dir($path.'document'.$new)) {
if (!is_dir($path.'document'.$new)) {
$created_dir = create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0 ,$path.'document', $new, $title, $visibility);
}
} elseif ($document->file_type == DOCUMENT) {
//Checking if folder exists in the database otherwise we created it
$dir_to_create = dirname($document->path);
} elseif ($document->file_type == DOCUMENT) {
//Checking if folder exists in the database otherwise we created it
$dir_to_create = dirname($document->path);
if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') {
if (is_dir($path.dirname($document->path))) {
$sql = "SELECT id FROM ".$table." WHERE c_id = ".$this->destination_course_id." AND path = '/".self::DBUTF8escapestring(substr(dirname($document->path), 9))."'";
$res = Database::query($sql);
if (Database::num_rows($res) == 0) {
$res = Database::query($sql);
if (Database::num_rows($res) == 0) {
//continue;
$visibility = $document->item_properties[0]['visibility'];
$new = '/'.substr(dirname($document->path), 9);
@ -346,7 +346,7 @@ class CourseRestorer
}
}
if (file_exists($path.$document->path)) {
if (file_exists($path.$document->path)) {
switch ($this->file_option) {
case FILE_OVERWRITE :
$origin_path = $this->course->backup_path.'/'.$document->path;
@ -386,7 +386,7 @@ class CourseRestorer
//Replace old course code with the new destination code
$file_info = pathinfo($path.$document->path);
if (in_array($file_info['extension'], array('html','htm'))) {
$content = file_get_contents($path.$document->path);
if (UTF8_CONVERT) $content = utf8_encode($content);
@ -714,50 +714,50 @@ class CourseRestorer
} else {
$cat_id = $this->course->resources[RESOURCE_FORUMCATEGORY][$params['forum_category']]->destination_id;
}
self::DBUTF8_array($params);
$params['c_id'] = $this->destination_course_id;
$params['forum_category'] = $cat_id;
$params['forum_category'] = $cat_id;
unset($params['forum_id']);
$params['forum_comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($params['forum_comment'], $this->course->code, $this->course->destination_path);
$params['forum_comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($params['forum_comment'], $this->course->code, $this->course->destination_path);
if (!empty($params['forum_image'])) {
$original_forum_image = $this->course->path.'upload/forum/images/'.$params['forum_image'];
$original_forum_image = $this->course->path.'upload/forum/images/'.$params['forum_image'];
if (file_exists($original_forum_image)) {
$new_forum_image = api_get_path(SYS_COURSE_PATH).$this->destination_course_info['path'].'/upload/forum/images/'.$params['forum_image'];
$new_forum_image = api_get_path(SYS_COURSE_PATH).$this->destination_course_info['path'].'/upload/forum/images/'.$params['forum_image'];
@copy($original_forum_image, $new_forum_image);
}
}
$new_id = Database::insert($table_forum, $params);
$this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
$forum_topics = 0;
if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
if ($topic->obj->forum_id == $id) {
$this->restore_topic($topic_id, $new_id);
$forum_topics ++;
}
}
}
if ($forum_topics > 0) {
$sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
if ($forum_topics > 0) {
$sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int)$new_id;
Database::query($sql);
}
}
}
}
/**
* Restore forum-categories
*/
*/
function restore_forum_category($my_id = null) {
$forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$resources = $this->course->resources;
$resources = $this->course->resources;
if (!empty($resources[RESOURCE_FORUMCATEGORY])) {
foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) {
if (!empty($my_id)) {
@ -776,29 +776,29 @@ class CourseRestorer
}
}
$params = (array) $forum_cat->obj;
$params['c_id'] = $this->destination_course_id;
$params['c_id'] = $this->destination_course_id;
$params['cat_comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($params['cat_comment'], $this->course->code, $this->course->destination_path);
unset($params['cat_id']);
self::DBUTF8_array($params);
$new_id = Database::insert($forum_cat_table, $params);
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
self::DBUTF8_array($params);
$new_id = Database::insert($forum_cat_table, $params);
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
if (!empty($my_id)) {
return $new_id;
}
}
}
}
}
}
/**
* Restore a forum-topic
*/
function restore_topic($thread_id, $forum_id) {
$table = Database :: get_course_table(TABLE_FORUM_THREAD);
$table = Database :: get_course_table(TABLE_FORUM_THREAD);
$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
$params = (array)$topic->obj;
self::DBUTF8_array($params);
self::DBUTF8_array($params);
$params['c_id'] = $this->destination_course_id;
$params['forum_id'] = $forum_id;
$params['thread_poster_id'] = $this->first_teacher_id;
@ -808,44 +808,44 @@ class CourseRestorer
$params['thread_replies'] = 0;
$params['thread_views'] = 0;
unset($params['thread_id']);
$new_id = Database::insert($table, $params);
$new_id = Database::insert($table, $params);
api_item_property_update($this->destination_course_info, TOOL_FORUM_THREAD, $new_id, 'ThreadAdded', api_get_user_id(), 0, 0, null, null);
$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
$topic_replies = -1;
foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post){
$topic_replies = -1;
foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post){
if ($post->obj->thread_id == $thread_id) {
$topic_replies++;
$this->restore_post($post_id, $new_id, $forum_id);
}
}
}
return $new_id;
}
/**
* Restore a forum-post
* @TODO Restore tree-structure of posts. For example: attachments to posts.
*/
function restore_post($id, $topic_id, $forum_id) {
$table_post = Database :: get_course_table(TABLE_FORUM_POST);
$post = $this->course->resources[RESOURCE_FORUMPOST][$id];
$post = $this->course->resources[RESOURCE_FORUMPOST][$id];
$params = (array) $post->obj;
$params['c_id'] = $this->destination_course_id;
$params['forum_id'] = $forum_id;
$params['thread_id'] = $topic_id;
$params['poster_id'] = $this->first_teacher_id;
$params['post_date'] = api_get_utc_datetime();
unset($params['post_id']);
$params['post_text'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($params['post_text'], $this->course->code, $this->course->destination_path);
unset($params['post_id']);
$params['post_text'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($params['post_text'], $this->course->code, $this->course->destination_path);
$new_id = Database::insert($table_post, $params);
api_item_property_update($this->destination_course_info, TOOL_FORUM_POST, $new_id, 'PostAdded', api_get_user_id(), 0, 0, null, null);
api_item_property_update($this->destination_course_info, TOOL_FORUM_POST, $new_id, 'PostAdded', api_get_user_id(), 0, 0, null, null);
$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
return $new_id;
}
/**
* Restore links
*/
@ -878,7 +878,7 @@ class CourseRestorer
}
}
}
/**
* Restore tool intro
*/
@ -944,7 +944,7 @@ class CourseRestorer
all_day = '".$event->all_day."',
start_date = '".$event->start_date."',
end_date = '".$event->end_date."'";
Database::query($sql);
$new_event_id = Database::insert_id();
$this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id;
@ -986,7 +986,7 @@ class CourseRestorer
}
}
}
/**
* Restore course-description
*/
@ -1017,7 +1017,7 @@ class CourseRestorer
}
}
}
/**
* Restore announcements
*/
@ -1150,14 +1150,14 @@ class CourseRestorer
// $id = -1 identifies the fictionary test for collecting orphan questions. We do not store it in the database.
$new_id = -1;
}
$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
$order = 0;
$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;
$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);
}
}
@ -1168,9 +1168,9 @@ class CourseRestorer
* Restore quiz-questions
*/
function restore_quiz_question($id) {
$resources = $this->course->resources;
$resources = $this->course->resources;
$question = $resources[RESOURCE_QUIZQUESTION][$id];
$new_id = 0;
if (is_object($question)) {
@ -1194,25 +1194,25 @@ class CourseRestorer
picture='".self::DBUTF8escapestring($question->picture)."',
level='".self::DBUTF8escapestring($question->level)."',
extra='".self::DBUTF8escapestring($question->extra)."'";
Database::query($sql);
$new_id = Database::insert_id();
$new_id = Database::insert_id();
if ($question->quiz_type == MATCHING) {
$t = array();
foreach ($question->answers as $index => $answer) {
$t[$answer['position']] = $answer;
}
foreach ($t as $index => $answer) {
$sql = "INSERT INTO ".$table_ans." SET
c_id = ".$this->destination_course_id." ,
id = '".$index."', question_id = '".$new_id."',
answer = '".self::DBUTF8escapestring($answer['answer'])."',
correct = '".$answer['correct']."',
comment = '".self::DBUTF8escapestring($answer['comment'])."',
ponderation = '".$answer['ponderation']."',
position = '".$answer['position']."',
hotspot_coordinates = '".$answer['hotspot_coordinates']."',
$sql = "INSERT INTO ".$table_ans." SET
c_id = ".$this->destination_course_id." ,
id = '".$index."', question_id = '".$new_id."',
answer = '".self::DBUTF8escapestring($answer['answer'])."',
correct = '".$answer['correct']."',
comment = '".self::DBUTF8escapestring($answer['comment'])."',
ponderation = '".$answer['ponderation']."',
position = '".$answer['position']."',
hotspot_coordinates = '".$answer['hotspot_coordinates']."',
hotspot_type = '".$answer['hotspot_type']."'";
Database::query($sql);
}
@ -1223,20 +1223,21 @@ class CourseRestorer
$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
c_id = ".$this->destination_course_id." ,
id = '". ($index + 1)."',
question_id = '".$new_id."',
answer = '".self::DBUTF8escapestring($answer['answer'])."',
correct = '".$answer['correct']."',
comment = '".self::DBUTF8escapestring($answer['comment'])."',
ponderation = '".$answer['ponderation']."',
position = '".$answer['position']."',
hotspot_coordinates = '".$answer['hotspot_coordinates']."',
$sql = "INSERT INTO ".$table_ans." SET
c_id = ".$this->destination_course_id." ,
id = '". ($index + 1)."',
question_id = '".$new_id."',
answer = '".self::DBUTF8escapestring($answer['answer'])."',
correct = '".$answer['correct']."',
comment = '".self::DBUTF8escapestring($answer['comment'])."',
ponderation = '".$answer['ponderation']."',
position = '".$answer['position']."',
hotspot_coordinates = '".$answer['hotspot_coordinates']."',
hotspot_type = '".$answer['hotspot_type']."'";
Database::query($sql);
}
}
//@todo check this
$course_id = api_get_course_int_id();
@ -1252,7 +1253,7 @@ class CourseRestorer
$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))));
$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']];
@ -1263,7 +1264,7 @@ class CourseRestorer
}
return $new_id;
}
/**
* Restore surveys
*/
@ -1572,19 +1573,19 @@ class CourseRestorer
$old_prerequisite = array();
$old_refs = array();
$prerequisite_ids = array();
foreach ($lp->get_items() as $index => $item) {
foreach ($lp->get_items() as $index => $item) {
// we set the ref code here and then we update in a for loop
$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
//Only fix the path for no scos
if ($item['item_type'] == 'sco') {
$path = self::DBUTF8escapestring($item['path']);
$path = self::DBUTF8escapestring($item['path']);
} else {
$path = self::DBUTF8escapestring($item['path']);
$path = self::DBUTF8escapestring($item['path']);
$path = $this->get_new_id($item['item_type'], $path);
}
}
$sql = "INSERT INTO ".$table_item." SET
c_id = ".$this->destination_course_id." ,
@ -1807,15 +1808,15 @@ class CourseRestorer
return $ref;
}
if ($tool == 'hotpotatoes') {
$tool = 'document';
if ($tool == 'hotpotatoes') {
$tool = 'document';
}
if (!empty($this->course->resources[$tool][$ref]->destination_id)) {
return $this->course->resources[$tool][$ref]->destination_id;
}
return '';
}
/**
* Restore glossary
*/
@ -1978,9 +1979,9 @@ class CourseRestorer
if (UTF8_CONVERT) $str = utf8_encode($str);
return Database::escape_string($str);
}
function DBUTF8_array($array) {
if (UTF8_CONVERT) {
function DBUTF8_array($array) {
if (UTF8_CONVERT) {
foreach ($array as &$item) {
$item = utf8_encode($item);
}

Loading…
Cancel
Save