Quellcode durchsuchen

individual student feedback insertion into gradeimporter_feedback table working

bernardo vor 5 Jahren
Ursprung
Commit
e5f1ffc7e7
7 geänderte Dateien mit 122 neuen und 87 gelöschten Zeilen
  1. 6 5
      db/install.xml
  2. 13 8
      lang/en/gradeimporter.php
  3. 88 1
      lib.php
  4. 0 57
      locallib.php
  5. 2 2
      submission.php
  6. 12 13
      submission_form.php
  7. 1 1
      version.php

+ 6 - 5
db/install.xml

@@ -30,7 +30,7 @@
               COMMENT="Which gradeimporter instance this submission is related to" PREVIOUS="id" NEXT="type"/>
         <FIELD NAME="type" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Type of the submission (exam, exercise list,"
                 PREVIOUS="gradeimporter" NEXT="gradebook"/>
-        <FIELD NAME="gradebook" TYPE="boolean" NOTNULL="true" SEQUENCE="false" COMMENT="Register if the submission is going to the gradebook"
+        <FIELD NAME="gradebook" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="Register if the submission is going to the gradebook"
                 PREVIOUS="type" NEXT="timecreated"/>
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"
                 PREVIOUS="gradebook" NEXT="timemodified"/>
@@ -41,11 +41,12 @@
         <FIELD NAME="name" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" COMMENT="submission name"
                 PREVIOUS="usermodified" NEXT="info"/>
         <FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Description of the submission type ex: exam 1 given on day YYYY/MM/DD"
-              PREVIOUS="name" NEXT="position"/>
-        <!--<FIELD NAME="descriptionformat" TYPE="char" LENGTH="10" NOTNULL="false" DEFAULT="plaintext" SEQUENCE="false" COMMENT="Description text format (html, plaintext, etc)"/>-->
+              PREVIOUS="name" NEXT="descriptionformat"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="position"/>
+
         <FIELD NAME="position" TYPE="int" LENGTH="3" NOTNULL="true" SEQUENCE="false" COMMENT="Position relative to other submissions"
-                PREVIOUS="info" NEXT="visibility"/>
-        <FIELD NAME="visibility" TYPE="boolean" NOTNULL="true" SEQUENCE="false" COMMENT="Registers if students can see this submission."
+                PREVIOUS="descriptionformat" NEXT="visibility"/>
+        <FIELD NAME="visibility" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="Registers if students can see this submission."
                 PREVIOUS="position"/>
       </FIELDS>
       <KEYS>

+ 13 - 8
lang/en/gradeimporter.php

@@ -1,5 +1,6 @@
 <?php
 $string['gradeimporter'] = 'Grade Importer';
+$string['pluginname'] = 'Grade Importer';
 
 $string['modulename'] = 'Grade Importer';
 $string['modulenameplural'] = 'Grade Importers';
@@ -31,9 +32,7 @@ $string['newsubmission'] = "Add new submission";
     $string['general'] = 'General informations';
     $string['visibilityOn'] = 'Students can see this';
     $string['visibilityOff'] = 'Students can\'t see this';
-    $string['csvdelimiter'] = 'Choose the csv delimiter';
-    $string['filehandling'] = 'File handling';
-    $string['gradebookYN'] = 'Results go to gradebook';
+    
     //subtypes
         $string['exam'] = 'Exam';
         $string['activity'] = 'Activity';
@@ -45,16 +44,22 @@ $string['newsubmission'] = "Add new submission";
     //submission form
     $string['gradebookN'] = 'This submission goes to gradebook';
     $string['gradebookY'] = 'This submission does not go to gradebook';
-    $string['submissionFiles'] = 'Choose the students feedback file';
+    $string['submissionFiles'] = 'Students feedback file';
     $string['submissionDescription'] = 'Submission description';
-    $string[''] = '';
+    $string['submissionType'] = 'Submission Type';
+    $string['visibilityYN'] = 'Visiblity';
+    $string['csvdelimiter'] = 'csv delimiter';
+    $string['filehandling'] = 'File handling';
+    $string['gradebookYN'] = 'Gradebook';
+    $string['visibilityYN'] = 'Students can see this submission';
 
 
     //submission form help buttons
-    $string['submissionfiles_help'] = 'Must be only one file, either a .zip or a .csv';
+    $string['submissionType_help'] = 'Choose submission type (e.g. Exam, Activity)'; 
+    $string['submissionFiles_help'] = 'Must be only one file, either a .zip or a .csv';
     $string['csvdelimiter_help'] = 'CSV delimiter of the config.csv file';
-    $string['gradebook_help'] = 'Yes, results go to gradebook \n No, Results don\'t go to gradebook';
-    $string['visibility_help'] = 'Yes, this is available to students \n No, This is not available to students';
+    $string['gradebookYN_help'] = 'Yes, results go to gradebook \n No, Results don\'t go to gradebook';
+    $string['visibilityYN_help'] = 'Yes, this is available to students \n No, This is not available to students';
 
     //submission form errors
 

+ 88 - 1
lib.php

@@ -88,4 +88,91 @@ function gradeimporter_delete_instance($data){
     //delete the instance itself
     $DB->delete_records('gradeimporter', array('id'=>$id) );
     return true;
-}
+}
+
+function gradeimporter_check_for_zips ($context, $cm, $submission){
+  global $DB;
+
+    $fs = get_file_storage();
+    $files = $fs->get_area_files($context->id, 'mod_gradeimporter', 'submission', $submission->id, "itemid, filepath, filename", false);
+echo "---- DEBUG ---- \n linha 96\n";
+    foreach ($files as $storedfile) {
+      if ($storedfile->get_mimetype() == 'application/zip') {
+        echo "---- DEBUG ---- \n linha 99 - unpack zip \n";
+        //unpack zip
+        $packer = get_file_packer('application/zip');
+        $fs->delete_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0);
+        $storedfile->extract_to_storage($packer, $context->id, 'mod_gradeimporter', 'unpacktemp', 0, "item, filepath, filename", false);
+        $tempfiles = $fs->get_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0, "itemid, filepath, filename", false);
+        if (count($tempfiles) > 0) {
+          echo "---- DEBUG ---- \n linha 105 - tempfiles > 0 \n";
+          $storedfile->delete(); // delete the zip
+
+          foreach ($tempfiles as $storedfile){
+            //copy files to known directory
+
+            echo $storedfile->get_filename();
+            echo "  mimetype  ";
+            echo $storedfile->get_mimetype();
+            echo "file location";
+            echo $storedfile->get_filepath(). ' \n ';
+          }
+
+          foreach ($tempfiles as $storedfile){
+            if ($storedfile->get_mimetype() == 'text/csv'){
+              echo "---- DEBUG ---- \n linha 110 - achou csv \n";
+
+              $csvData = $storedfile->get_content();
+              $csvLines = explode(PHP_EOL, $csvData);
+              $csv = array();
+              foreach($csvLines as $line){
+                $csv[] = str_getcsv($line);
+              }
+              print_r($csv);
+              //array_map('str_getcsv', $storedfile->get_content() );
+              array_walk($csv, function(&$a) use ($csv) { //adds first row as keys
+                $a = array_combine($csv[0], $a);
+              });
+              array_shift($csv); // remove column header
+  print_r($csv);
+              for ($i = 0; $i< sizeof($csv); $i++){
+                $fileinfo = array(
+                  'contextid'   =>  $context->id,
+                  'component'   =>  'mod_gradeimporter',
+                  'filearea'    =>  'submission',
+                  'itemid'      =>  $submission->id,
+                  'filepath'    =>  '/',
+                  'file'        =>  $csv[$i]['file'],
+                  'studentid'   => $csv[$i]['id']
+                );
+
+                foreach ($tempfiles as $storedfile) {
+                  echo '---- DEBUG ---- \n linha 129 - file name'.$storedfile->get_filename();
+                  if ($storedfile->get_filename() == $csv[$i]['file']){
+                    $storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
+                    $dbentry = new stdClass();
+                    $dbentry->id = null;
+                    $dbentry->submissionid  = $submission->id;
+                    $dbentry->studentid     = $csv[$i]['id'];
+                    $dbentry->grade        = $csv[$i]['grade'];
+                    $dbentry->comment      = $csv[$i]['comment'];
+                    $dbentry->fileid      = $storedfile;
+                    $dbentry->usermodified = 0;
+                    $dbentry->timecreated   = time();
+                    $dbentry->timemodified   = time();
+
+                    $dbentry->id = $DB->insert_record('gradeimporter_feedback', $dbentry);
+                    break;
+                  }
+                }
+                
+              }
+            }
+          }
+
+
+          }
+        $fs->delete_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0);
+      }
+    }
+  }

+ 0 - 57
locallib.php

@@ -38,64 +38,7 @@ class feedback {
     }
 }
 
-function gradeimporter_check_for_zips ($context, $cm, $submission){
-  $fs = get_file_storage();
-  $files = $fs->get_area_files($context->id, 'mod_gradeimporter', 'submission', $submission->id, "itemid, filepath, filename", false);
 
-  foreach ($files as $storedfile) {
-    if ($storedfile->get_mimetype() == 'application/zip') {
-      //unpack zip
-      $packer = get_file_packer('application/zip');
-      $fs->delete_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0);
-      $storedfiles = $fs->get_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0, "itemid, filepath, filename", false);
-      if (count($tempfiles > 0)) {
-        $storedfile->delete(); // delete the zip
-        
-        foreach (glob('*.csv') as $filename){
-          $csv = array_map('str_getcsv', file($filename));
-          array_walk($csv, function(&$a) use ($csv) { //adds first row as keys
-            $a = array_combine($csv[0], $a);
-          });
-          array_shift($csv); # remove column header
-
-          for ($i = 1; i< sizeof($csv); $i++){
-            $fileinfo = array(
-              'contextid'   =>  $context->id,
-              'component'   =>  'mod_gradeimporter',
-              'filearea'    =>  'submission',
-              'itemid'      =>  $submission->id,
-              'filepath'    =>  '/',
-              'filename'    =>  $csv[i]['filename'],
-              'studentid'   => $csv[i]['id']
-            );
-
-            foreach ($tempfiles as $storedfile) {
-              if ($storedfile->get_filename() == $csv[i]['filename']){
-                $storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
-                $bdentry = array(
-                          'submissionid'  => $submission->id,
-                          'studentid'     => $csv[i]['id'],
-                          'grade'         => $csv[i]['grade'],
-                          'comment'       => $csv[i]['comment'],
-                          'fileid'        => $csv[i][$storedfile],
-                          'usermodified'  => $USER->id,
-                          'timecreated'   => time(),
-                          'timemodified'  => time()
-                        ); 
-                $bdentry->id = $DB->insert_record("feedback", $dbentry);
-                break;
-              }
-            }
-            
-          }
-        }
-
-
-        }
-      $fs->delete_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0);
-    }
-  }
-}
 //
 // INSERT INTO `mdl_gradeimporter_feedback` (`id`, `submissionid`, `studentid`, `grade`, `comment`, `fileid`, `usermodified`, `timecreated`, `timemodified`)
 // VALUES

+ 2 - 2
submission.php

@@ -80,9 +80,9 @@ if ($mform->is_cancelled()){
     } else {
         $isnewentry                     = false;
     }
-
     $submission->description        = '';           //updated later
     $submission->descriptionformat  = FORMAT_HTML;  //updated later
+    $submission->definitiontrust    = 0;
     $submission->timemodified       = $timenow;     
     $submission->position           = -1;
 
@@ -107,7 +107,7 @@ if ($mform->is_cancelled()){
 
     //trigger event and update completion (if entry was created)
     $eventparams = array(
-        'context'=>context,
+        'context'=>$context,
         'objectid'=>$submission->id,
         );
     if ($isnewentry){

+ 12 - 13
submission_form.php

@@ -33,26 +33,25 @@
             $mform->addRule('name', get_string('error_nameField', 'gradeimporter'), 'required', null, 'client');
 
             //description
-            $mform->addElement('editor', 'description_editor', get_string('submissiondescription', 'gradeimporter'), null, $descriptionoptions);
+            $mform->addElement('editor', 'description_editor', get_string('submissionDescription', 'gradeimporter'), null, $descriptionoptions);
+            $mform->setType('description_editor', PARAM_RAW);
 
-            //description format
-            //kill on the install.xml
 
             $mform->addElement('header', 'filehandling', get_string('filehandling', 'gradeimporter'));
 
             //submission type
-            $submissiontype = array();
-            $submissiontype[0] = get_string('exam', 'gradeimporter');
-            $submissiontype[1] = get_string('activity', 'gradeimporter');
+            $submissionType = array();
+            $submissionType[0] = get_string('exam', 'gradeimporter');
+            $submissionType[1] = get_string('activity', 'gradeimporter');
             
    
-            $mform->addElement('select', 'type', get_string('submissiontype', 'gradeimporter'), $submissiontype, array('onChange' => 'config_type(this.value);'));
-            //$mform->setDefault('submissiontype', 0); // default submissiontype = 3
-            $mform->addHelpButton('submissiontype', 'subtype_help', 'gradeimporter');
+            $mform->addElement('select', 'type', get_string('submissionType', 'gradeimporter'), $submissionType, array('onChange' => 'config_type(this.value);'));
+            //$mform->setDefault('submissionType', 0); // default submissionType = 3
+            $mform->addHelpButton('type', 'submissionType', 'gradeimporter');
 
             //receive the files
             $mform->addElement('filemanager', 'submission_filemanager', get_string('submissionFiles', 'gradeimporter'), null, $descriptionoptions);
-            $mform->addHelpButton('submission_filemanager', 'submissionfiles', 'gradeimporter');
+            $mform->addHelpButton('submission_filemanager', 'submissionFiles', 'gradeimporter');
 
             //csv delimiter
             $csv_delimiter = array();
@@ -64,7 +63,7 @@
    
             $mform->addElement('select', 'csv_delimiter', get_string('csvdelimiter', 'gradeimporter'), $csv_delimiter, array('onChange' => 'config_type(this.value);'));
             $mform->setDefault('csv_delimiter', 1); // default csv_delimiter = 3
-            $mform->addHelpButton('csv_delimiter', 'csvdelimiter_help', 'gradeimporter');
+            $mform->addHelpButton('csv_delimiter', 'csvdelimiter', 'gradeimporter');
 
             
             //gradebook Y/N Combobox
@@ -73,13 +72,13 @@
             $ynarray[1] = get_string('yes', 'gradeimporter');
             $mform->addElement('select', 'gradebook', get_string('gradebookYN', 'gradeimporter'), $ynarray);
             //$mform->setDefault('gradebook', 0);
-            $mform->addHelpButton('gradebook', 'gradebook_help', 'gradeimporter');
+            $mform->addHelpButton('gradebook', 'gradebookYN', 'gradeimporter');
 
 
             //visibility Y/N Combobox
             $mform->addElement('select', 'visibility', get_string('visibilityYN', 'gradeimporter'), $ynarray);
             //$mform->setDefault('visibility', 0);
-            $mform->addHelpButton('visibility', 'visibility_help', 'gradeimporter');
+            $mform->addHelpButton('visibility', 'visibilityYN', 'gradeimporter');
 
         //-----------------------------
         //hidden fields

+ 1 - 1
version.php

@@ -2,7 +2,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version = 20191110;
+$plugin->version = 20191111;
 $plugin->requires = 2014021100;
 $plugin->release = 'v1.0';
 $plugin->component = 'mod_gradeimporter';