get_records_sql($sql, array('studentid'=>$USER->id)); $data = array(); if (count($records)) { foreach ($records as $key => $value) { if (!array_key_exists($value->gst_name, $data)) $data[$value->gst_name] = array(); $data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->fileid); } } return $data; } } 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 // (1, 10, 1, 10.00, 'ok muito bem', 100, 0, 0, 0); //