Feature #272 - Course restorer: Encoding detection for course archives has been added. It is necessary for importing archives that are created with systems older than 1.8.6.1. Next to do: The read/detected encoding value should be used for data conversion.

skala
Ivan Tcholakov 16 years ago
parent 1eb1d8a2b1
commit 1fc500cd90
  1. 97
      main/coursecopy/classes/Course.class.php
  2. 19
      main/coursecopy/classes/CourseRestorer.class.php

@ -109,5 +109,102 @@ class Course
// }
}
/**
* Returns sample text based on the imported course content.
* This sample text is to be used for course language or encoding detection if there is missing (meta)data in the archive.
* @return string The resulting sample text extracted from some common resources' data fields.
*/
public function get_sample_text() {
$sample_text = '';
foreach ($this->resources as $type => & $resources) {
if (count($resources) > 0) {
foreach ($resources as $id => & $resource) {
$title = '';
$description = '';
switch ($type) {
case RESOURCE_ANNOUNCEMENT:
case RESOURCE_EVENT:
case RESOURCE_WIKI:
$title = $resource->title;
$description = $resource->content;
break;
case RESOURCE_DOCUMENT:
$title = $resource->title;
$description = $resource->comment;
break;
case RESOURCE_FORUM:
case RESOURCE_FORUMCATEGORY:
case RESOURCE_LINK:
case RESOURCE_LINKCATEGORY:
case RESOURCE_QUIZ:
$title = $resource->title;
$description = $resource->description;
break;
case RESOURCE_FORUMPOST:
$title = $resource->title;
$description = $resource->text;
break;
case RESOURCE_GLOSSARY:
case RESOURCE_LEARNPATH:
$title = $resource->name;
$description = $resource->description;
break;
case RESOURCE_FORUMTOPIC:
case RESOURCE_SCORM:
$title = $resource->title;
break;
case RESOURCE_QUIZQUESTION:
$title = $resource->question;
$description = $resource->description;
break;
case RESOURCE_SURVEY:
$title = $resource->title;
$description = $resource->subtitle;
break;
case RESOURCE_SURVEYQUESTION:
$title = $resource->survey_question;
$description = $resource->survey_question_comment;
break;
case RESOURCE_TOOL_INTRO:
$description = $resource->intro_text;
break;
default:
break;
}
$title = api_html_to_text($title);
$description = api_html_to_text($description);
if (!empty($title)) {
$sample_text .= $title."\n";
}
if (!empty($description)) {
$sample_text .= $description."\n";
}
if (!empty($title) || !empty($description)) {
$sample_text .= "\n";
}
}
}
}
return $sample_text;
}
}
?>

@ -94,8 +94,23 @@ class CourseRestorer
$this->course->destination_db = $course_info['database'];
$this->course->destination_path = $course_info['directory'];
}
// platform encoding
$course_charset = $this->course->encoding;
// Source platform encoding - reading/detection
// The correspondent data field has been added as of version 1.8.6.1.
if (empty($this->course->encoding)) {
// The archive has been created by a system wich is prior to 1.8.6.1 version.
// In this case we have to detect the encoding.
$sample_text = $this->course->get_sample_text()."\n";
// Let us exclude ASCII lines, probably they are English texts.
$sample_text = explode("\n", $sample_text);
foreach ($sample_text as $key => &$line) {
if (api_is_valid_ascii($line)) {
unset($sample_text[$key]);
}
}
$sample_text = join("\n", $sample_text);
$this->course->encoding = api_detect_encoding($sample_text);
}
if (!empty($session_id)) {
$this->restore_documents($session_id,$destination_course_code);

Loading…
Cancel
Save