|
@@ -95,32 +95,18 @@ function gradeimporter_check_for_zips ($context, $cm, $submission){
|
|
|
|
|
|
$fs = get_file_storage();
|
|
$fs = get_file_storage();
|
|
$files = $fs->get_area_files($context->id, 'mod_gradeimporter', 'submission', $submission->id, "itemid, filepath, filename", false);
|
|
$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) {
|
|
foreach ($files as $storedfile) {
|
|
if ($storedfile->get_mimetype() == 'application/zip') {
|
|
if ($storedfile->get_mimetype() == 'application/zip') {
|
|
- echo "---- DEBUG ---- \n linha 99 - unpack zip \n";
|
|
|
|
//unpack zip
|
|
//unpack zip
|
|
$packer = get_file_packer('application/zip');
|
|
$packer = get_file_packer('application/zip');
|
|
$fs->delete_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0);
|
|
$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);
|
|
$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);
|
|
$tempfiles = $fs->get_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0, "itemid, filepath, filename", false);
|
|
if (count($tempfiles) > 0) {
|
|
if (count($tempfiles) > 0) {
|
|
- echo "---- DEBUG ---- \n linha 105 - tempfiles > 0 \n";
|
|
|
|
$storedfile->delete(); // delete the zip
|
|
$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){
|
|
foreach ($tempfiles as $storedfile){
|
|
if ($storedfile->get_mimetype() == 'text/csv'){
|
|
if ($storedfile->get_mimetype() == 'text/csv'){
|
|
- echo "---- DEBUG ---- \n linha 110 - achou csv \n";
|
|
|
|
|
|
|
|
$csvData = $storedfile->get_content();
|
|
$csvData = $storedfile->get_content();
|
|
$csvLines = explode(PHP_EOL, $csvData);
|
|
$csvLines = explode(PHP_EOL, $csvData);
|
|
@@ -128,38 +114,38 @@ echo "---- DEBUG ---- \n linha 96\n";
|
|
foreach($csvLines as $line){
|
|
foreach($csvLines as $line){
|
|
$csv[] = str_getcsv($line);
|
|
$csv[] = str_getcsv($line);
|
|
}
|
|
}
|
|
- print_r($csv);
|
|
|
|
//array_map('str_getcsv', $storedfile->get_content() );
|
|
//array_map('str_getcsv', $storedfile->get_content() );
|
|
array_walk($csv, function(&$a) use ($csv) { //adds first row as keys
|
|
array_walk($csv, function(&$a) use ($csv) { //adds first row as keys
|
|
$a = array_combine($csv[0], $a);
|
|
$a = array_combine($csv[0], $a);
|
|
});
|
|
});
|
|
array_shift($csv); // remove column header
|
|
array_shift($csv); // remove column header
|
|
- print_r($csv);
|
|
|
|
for ($i = 0; $i< sizeof($csv); $i++){
|
|
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) {
|
|
foreach ($tempfiles as $storedfile) {
|
|
- echo '---- DEBUG ---- \n linha 129 - file name'.$storedfile->get_filename();
|
|
|
|
if ($storedfile->get_filename() == $csv[$i]['file']){
|
|
if ($storedfile->get_filename() == $csv[$i]['file']){
|
|
- $storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
|
|
|
|
|
|
+
|
|
|
|
+ $fileinfo = array(
|
|
|
|
+ 'contextid' => $context->id,
|
|
|
|
+ 'component' => 'mod_gradeimporter',
|
|
|
|
+ 'filearea' => 'gradeimporter_feedback',
|
|
|
|
+ 'itemid' => $submission->id,
|
|
|
|
+ 'filepath' => '/'.$csv[$i]['file'].'.',
|
|
|
|
+ 'filename' => $csv[$i]['file']
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ //$storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
|
|
|
|
+
|
|
$dbentry = new stdClass();
|
|
$dbentry = new stdClass();
|
|
$dbentry->id = null;
|
|
$dbentry->id = null;
|
|
$dbentry->submissionid = $submission->id;
|
|
$dbentry->submissionid = $submission->id;
|
|
$dbentry->studentid = $csv[$i]['id'];
|
|
$dbentry->studentid = $csv[$i]['id'];
|
|
$dbentry->grade = $csv[$i]['grade'];
|
|
$dbentry->grade = $csv[$i]['grade'];
|
|
$dbentry->comment = $csv[$i]['comment'];
|
|
$dbentry->comment = $csv[$i]['comment'];
|
|
- $dbentry->fileid = $storedfile;
|
|
|
|
|
|
+ $dbentry->fileid = 0; //precisa consertar
|
|
$dbentry->usermodified = 0;
|
|
$dbentry->usermodified = 0;
|
|
$dbentry->timecreated = time();
|
|
$dbentry->timecreated = time();
|
|
$dbentry->timemodified = time();
|
|
$dbentry->timemodified = time();
|
|
|
|
+ $dbentry->contextid = $context->id;
|
|
|
|
+ $dbentry->name = $csv[$i]['file'];
|
|
|
|
|
|
$dbentry->id = $DB->insert_record('gradeimporter_feedback', $dbentry);
|
|
$dbentry->id = $DB->insert_record('gradeimporter_feedback', $dbentry);
|
|
break;
|
|
break;
|