| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | <?phpnamespace gradeimporter;class feedback {    public static function get_comments() {        global $DB, $USER;        $sql = "        SELECT gf.id,               gf.grade,               gf.comment,               gs.name gs_name,               gs.description gs_description,               gst.name gst_name,               gst.info gst_info,               fileid          FROM mdl_gradeimporter_feedback gf          JOIN mdl_gradeimporter_submission gs            ON gf.submissionid = gs.id          JOIN mdl_gradeimporter_submissiontype gst            ON gs.type = gst.id         WHERE gf.studentid = ?";        $comments = array();        $records = $DB->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);//
 |