]> git.mjollnir.org Git - moodle.git/commitdiff
grade import temporary buffer tables and encoding/import form changes
authortoyomoyo <toyomoyo>
Tue, 5 Jun 2007 09:28:15 +0000 (09:28 +0000)
committertoyomoyo <toyomoyo>
Tue, 5 Jun 2007 09:28:15 +0000 (09:28 +0000)
grade/import/grade_import_form.php
lib/db/install.xml
lib/db/upgrade.php
lib/textlib.class.php
version.php

index 70b836681ed64f51a71ec1af3fdda09336cb6af7..68173d7604e6b8f414129a5fd09a1d641ea74c3c 100755 (executable)
@@ -7,11 +7,16 @@ class grade_import_form extends moodleform {
 
         // course id needs to be passed for auth purposes
         $mform->addElement('hidden', 'id', optional_param('id'));
-
+        $mform->addElement('header', 'general', get_string('importfile'));
         // file upload
         $mform->addElement('file', 'userfile', get_string('file'));
         $mform->addRule('userfile', null, 'required');
+        $textlib = new textlib();
+        $encodings = $textlib->get_encodings();
+        $mform->addElement('select', 'encoding', get_string('encoding'), $encodings);
 
+        $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000); 
+        $mform->addElement('select', 'previewrows', 'Preview rows', $options); // TODO: localize
         $this->add_action_buttons(false, get_string('uploadgrades'));
     }
 
index fcfa70ec801ce9b003fac6facb0603bc56820adc..36c1d4e3173eff03928711bb5e747e8e22c25a05 100644 (file)
         <KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id" PREVIOUS="scaleid"/>
       </KEYS>
     </TABLE>
-    <TABLE NAME="grade_history" COMMENT="This table keeps track of grade changes. Using this it should be possible to reconstruct the grades at any point in time in the past, or to audit grade changes over time. It should be quicker to use this table for that, rather than storing this information in the main Moodle log.  Note we use itemid and userid as a key rather than grade_grade id, just in case one of the things we want to log here is the deletion of a grade entirely." PREVIOUS="grade_outcomes">
+    <TABLE NAME="grade_history" COMMENT="This table keeps track of grade changes. Using this it should be possible to reconstruct the grades at any point in time in the past, or to audit grade changes over time. It should be quicker to use this table for that, rather than storing this information in the main Moodle log.  Note we use itemid and userid as a key rather than grade_grade id, just in case one of the things we want to log here is the deletion of a grade entirely." PREVIOUS="grade_outcomes" NEXT="grade_import_values">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="itemid"/>
         <FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="The grade_item the grade is from" PREVIOUS="id" NEXT="userid"/>
         <KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id" PREVIOUS="userid"/>
       </KEYS>
     </TABLE>
+    <TABLE NAME="grade_import_values" COMMENT="Temporary table for importing grades" PREVIOUS="grade_history" NEXT="grade_import_newitem">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="itemid"/>
+        <FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="if set, this points to existing grade_items id" PREVIOUS="id" NEXT="newgradeitem"/>
+        <FIELD NAME="newgradeitem" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="if set, points to the id of grade_import_newitem" PREVIOUS="itemid" NEXT="userid"/>
+        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="newgradeitem" NEXT="gradevalue"/>
+        <FIELD NAME="gradevalue" TYPE="number" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0.0" SEQUENCE="false" ENUM="false" DECIMALS="5" COMMENT="raw grade value" PREVIOUS="userid" NEXT="import_code"/>
+        <FIELD NAME="import_code" TYPE="int" LENGTH="12" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="similar to backup_code, a unique batch code for identifying one batch of imports" PREVIOUS="gradevalue"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="itemid"/>
+        <KEY NAME="itemid" TYPE="foreign" FIELDS="itemid" REFTABLE="grade_items" REFFIELDS="id" PREVIOUS="primary" NEXT="newgradeitem"/>
+        <KEY NAME="newgradeitem" TYPE="foreign" FIELDS="newgradeitem" REFTABLE="grade_import_newitem" REFFIELDS="id" PREVIOUS="itemid"/>
+      </KEYS>
+    </TABLE>
+    <TABLE NAME="grade_import_newitem" COMMENT="temporary table for storing new grade_item names from grade import" PREVIOUS="grade_import_values">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" COMMENT="id of the table, please edit me" NEXT="itemname"/>
+        <FIELD NAME="itemname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" COMMENT="new grade item name" PREVIOUS="id" NEXT="import_cpde"/>
+        <FIELD NAME="import_cpde" TYPE="int" LENGTH="12" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="import batch code for identification" PREVIOUS="itemname"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me"/>
+      </KEYS>
+    </TABLE>
   </TABLES>
   <STATEMENTS>
     <STATEMENT NAME="insert log_display" TYPE="insert" TABLE="log_display" COMMENT="Initial insert of records on table log_display">
index 2a2281324803886951efd2ff247788629dec8a78..3a25d94e278965811e1401bb60efa4ef61dac915 100644 (file)
@@ -1356,6 +1356,44 @@ function xmldb_main_upgrade($oldversion=0) {
         $result = $result && change_field_default($table, $field);
     }
     
+    /// new tables for import buffers
+    if ($result && $oldversion < 2007060502) {
+    
+    /// Define table grade_import_values to be created
+        $table = new XMLDBTable('grade_import_values');
+
+    /// Adding fields to table grade_import_values
+        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
+        $table->addFieldInfo('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
+        $table->addFieldInfo('newgradeitem', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
+        $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
+        $table->addFieldInfo('gradevalue', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0.0');
+        $table->addFieldInfo('import_code', XMLDB_TYPE_INTEGER, '12', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
+
+    /// Adding keys to table grade_import_values
+        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
+        $table->addKeyInfo('itemid', XMLDB_KEY_FOREIGN, array('itemid'), 'grade_items', array('id'));
+        $table->addKeyInfo('newgradeitem', XMLDB_KEY_FOREIGN, array('newgradeitem'), 'grade_import_newitem', array('id'));
+
+    /// Launch create table for grade_import_values
+        $result = $result && create_table($table);
+        
+    /// Define table grade_import_newitem to be created
+        $table = new XMLDBTable('grade_import_newitem');
+
+    /// Adding fields to table grade_import_newitem
+        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
+        $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
+        $table->addFieldInfo('import_cpde', XMLDB_TYPE_INTEGER, '12', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
+
+    /// Adding keys to table grade_import_newitem
+        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
+
+    /// Launch create table for grade_import_newitem
+        $result = $result && create_table($table);
+    }
+    
+    
     return $result; 
 }
 
index dd2626f81ee0e706ba620b8bc76d34cede09c971..fb833154d418e38cb6f324ef3d15995fdef067cf 100644 (file)
@@ -332,5 +332,26 @@ class textlib {
         }
         return $str;
     }
+    
+    /**
+     * Returns encoding options for select boxes, utf-8 and platform encoding first
+     * @return array encodings     
+     */
+    function get_encodings() {
+        $encodings = array();
+        $encodings['UTF-8'] = 'UTF-8';
+        $winenc = strtoupper(get_string('localewincharset'));
+        if ($winenc != '') {
+            $encodings[$winenc] = $winenc;
+        }
+        $nixenc = strtoupper(get_string('oldcharset'));
+        $encodings[$nixenc] = $nixenc;
+        
+        foreach ($this->typo3cs->synonyms as $enc) {
+            $enc = strtoupper($enc);
+            $encodings[$enc] = $enc;
+        }
+        return $encodings;
+    }
 }
 ?>
index 11f36df16fea7818daca000c4ce2057e96c43bb3..e24ad1b58f89b38703bb45da5485e6b67e90dc5b 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-   $version = 2007060501;  // YYYYMMDD = date
+   $version = 2007060502;  // YYYYMMDD = date
                            //       XY = increments within a single day
 
    $release = '1.9 dev';    // Human-friendly version name