]> git.mjollnir.org Git - moodle.git/commitdiff
utf8 migrate support for additional fields MDL-6339
authortoyomoyo <toyomoyo>
Wed, 30 Aug 2006 06:12:12 +0000 (06:12 +0000)
committertoyomoyo <toyomoyo>
Wed, 30 Aug 2006 06:12:12 +0000 (06:12 +0000)
mod/quiz/db/migrate2utf8.php
mod/quiz/db/migrate2utf8.xml

index 40772d213524ab59bdc9a13136780d8fba912af3..282b05bc2a002e2341f7f3af1eaa3e8f8ab8063c 100755 (executable)
@@ -1,5 +1,161 @@
 <?php // $Id$
 
+function migrate2utf8_question_multichoice_correctfeedback($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,
+                {$CFG->prefix}question_multichoice qm
+           WHERE qc.id = qq.category
+                 AND qq.id = qm.question
+                 AND qm.id =  $recordid";
+
+    if (!$quiz = get_record_sql($SQL)) {
+        log_the_problem_somewhere();
+        return false;
+    }
+
+    if (!$questionmultichoice = get_record('question_multichoice','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($questionmultichoice->correctfeedback, $fromenc);
+
+        $newquestionmultichoice = new object;
+        $newquestionmultichoice->id = $recordid;
+        $newquestionmultichoice->correctfeedback = $result;
+        update_record('question_multichoice',$newquestionmultichoice);
+    }
+/// And finally, just return the converted field
+    return $result;
+}
+
+function migrate2utf8_question_multichoice_partiallycorrectfeedback($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,
+                {$CFG->prefix}question_multichoice qm
+           WHERE qc.id = qq.category
+                 AND qq.id = qm.question
+                 AND qm.id =  $recordid";
+
+    if (!$quiz = get_record_sql($SQL)) {
+        log_the_problem_somewhere();
+        return false;
+    }
+
+    if (!$questionmultichoice = get_record('question_multichoice','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($questionmultichoice->partiallycorrectfeedback, $fromenc);
+
+        $newquestionmultichoice = new object;
+        $newquestionmultichoice->id = $recordid;
+        $newquestionmultichoice->partiallycorrectfeedback= $result;
+        update_record('question_multichoice',$newquestionmultichoice);
+    }
+/// And finally, just return the converted field
+    return $result;
+}
+
+function migrate2utf8_question_multichoice_incorrectfeedback($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,
+                {$CFG->prefix}question_multichoice qm
+           WHERE qc.id = qq.category
+                 AND qq.id = qm.question
+                 AND qm.id =  $recordid";
+
+    if (!$quiz = get_record_sql($SQL)) {
+        log_the_problem_somewhere();
+        return false;
+    }
+
+    if (!$questionmultichoice = get_record('question_multichoice','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($questionmultichoice->incorrectfeedback, $fromenc);
+
+        $newquestionmultichoice = new object;
+        $newquestionmultichoice->id = $recordid;
+        $newquestionmultichoice->incorrectfeedback= $result;
+        update_record('question_multichoice',$newquestionmultichoice);
+    }
+/// And finally, just return the converted field
+    return $result;
+}
+
 function migrate2utf8_quiz_feedback_feedbacktext($recordid) {
     global $CFG, $globallang; 
     /// Some trivial checks
@@ -198,6 +354,55 @@ function migrate2utf8_question_questiontext($recordid){
     return $result;
 }
 
+function migrate2utf8_question_commentarytext($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->commentarytext, $fromenc);
+
+        $newquizquestion = new object;
+        $newquizquestion->id = $recordid;
+        $newquizquestion->commentarytext = $result;
+        update_record('question',$newquizquestion);
+    }
+/// And finally, just return the converted field
+    return $result;
+}
 
 function migrate2utf8_question_numerical_units_unit($recordid){
     global $CFG, $globallang;
index 4e672aa095cf4212359fddfdfdf6d7fb6a902cc1..50a704764d9f244637bd0a08be193448a9e3f8b5 100755 (executable)
     <TABLE name="question_multichoice">
       <FIELDS>
         <FIELD name="answers" method="NO_CONV" type="varchar" length="255" />
+        <FIELD name="correctfeedback" method="PHP_FUNCTION" type="text" length="0">
+          <PHP_FUNCTION>
+            migrate2utf8_question_multichoice_correctfeedback(RECORDID)
+          </PHP_FUNCTION>
+        </FIELD>
+        <FIELD name="partiallycorrectfeedback" method="PHP_FUNCTION" type="text" length="0">
+          <PHP_FUNCTION>
+            migrate2utf8_question_multichoice_partiallycorrectfeedback(RECORDID)
+          </PHP_FUNCTION>
+        </FIELD>
+        <FIELD name="incorrectfeedback" method="PHP_FUNCTION" type="text" length="0">
+          <PHP_FUNCTION>
+            migrate2utf8_question_multichoice_incorrectfeedback(RECORDID)
+          </PHP_FUNCTION>
+        </FIELD>
       </FIELDS>
     </TABLE>
     <TABLE name="question_multianswer">
           </PHP_FUNCTION>
         </FIELD>
         <FIELD name="image" method="NO_CONV" type="varchar" length="255" />
+        <FIELD name="commentarytext" method="PHP_FUNCTION" type="text" length="0">
+          <PHP_FUNCTION>
+            migrate2utf8_question_commentarytext(RECORDID)
+          </PHP_FUNCTION>
+        </FIELD>
         <FIELD name="stamp" method="NO_CONV" type="varchar" length="255" />
       </FIELDS>
     </TABLE>