]> git.mjollnir.org Git - moodle.git/commitdiff
question->qtype
authortoyomoyo <toyomoyo>
Mon, 10 Apr 2006 05:08:19 +0000 (05:08 +0000)
committertoyomoyo <toyomoyo>
Mon, 10 Apr 2006 05:08:19 +0000 (05:08 +0000)
mod/quiz/db/migrate2utf8.php
mod/quiz/db/migrate2utf8.xml

index 5b0555e12a5bc1fc0eb4bfa74ebd6b6dd133eee5..3196922b5fa2b46e07bdbdedc560800d9d1e5eef 100755 (executable)
@@ -48,6 +48,56 @@ function migrate2utf8_question_name($recordid){
     return $result;
 }
 
+
+function migrate2utf8_question_qtype($recordid){
+    global $CFG, $globallang;
+
+/// Some trivial checks
+    if (empty($recordid)) {
+        log_the_problem_somewhere();
+        return false;
+    }
+
+    $SQL = "SELECT qc.course
+           FROM {$CFG->prefix}question_categories qc,
+                {$CFG->prefix}question qq
+           WHERE qc.id = qq.category
+                 AND qq.id = $recordid";
+
+    if (!$quiz = get_record_sql($SQL)) {
+        log_the_problem_somewhere();
+        return false;
+    }
+
+    if (!$quizquestions = get_record('question','id',$recordid)) {
+        log_the_problem_somewhere();
+        return false;
+    }
+    if ($globallang) {
+        $fromenc = $globallang;
+    } else {
+        $sitelang   = $CFG->lang;
+        $courselang = get_course_lang($quiz->course);  //Non existing!
+        $userlang   = get_main_teacher_lang($quiz->course); //N.E.!!
+
+        $fromenc = get_original_encoding($sitelang, $courselang, $userlang);
+    }
+
+/// We are going to use textlib facilities
+
+/// Convert the text
+    if (($fromenc != 'utf-8') && ($fromenc != 'UTF-8')) {
+        $result = utfconvert($quizquestions->qtype, $fromenc);
+
+        $newquizquestion = new object;
+        $newquizquestion->id = $recordid;
+        $newquizquestion->qtype = $result;
+        update_record('question',$newquizquestion);
+    }
+/// And finally, just return the converted field
+    return $result;
+}
+
 function migrate2utf8_question_questiontext($recordid){
     global $CFG, $globallang;
 
index 34dfbe31aa1b43c0f8b88083379b632a732a6bef..b5e0f8e31d641728a0329d7f4f0c4753f4e77140 100755 (executable)
             migrate2utf8_question_name(RECORDID)
           </PHP_FUNCTION>
         </FIELD>
+        <FIELD name="qtype" method="PHP_FUNCTION" type="varchar" length="20">
+          <PHP_FUNCTION>
+            migrate2utf8_question_qtype(RECORDID)
+          </PHP_FUNCTION>
+        </FIELD>
         <FIELD name="questiontext" method="PHP_FUNCTION" type="text" length="0">
           <PHP_FUNCTION>
             migrate2utf8_question_questiontext(RECORDID)