|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|