. defined('MOODLE_INTERNAL') || die(); function get_comments($cmid, $id) { global $DB, $USER, $CFG; $tp = $CFG->prefix; // gets moodle tables prefix, not everyone uses mdl_ $sql = " SELECT gf.id gf_id, gf.grade, gf.comment gf_comment, gf.contextid gf_contextid, gf.fileid gf_fileid, gf.name gf_name, gs.name gs_name, gs.description gs_description, gst.name gst_name, gst.description gst_description, fileid FROM ".$tp."gradeimporter_feedback gf JOIN ".$tp."gradeimporter_submission gs ON gf.submissionid = gs.id JOIN ".$tp."gradeimporter_submissiontype gst ON gs.type = gst.id WHERE gf.studentid = ?"; $records = $DB->get_records_sql($sql, array('studentid' => $USER->id)); $data = array(); if (count($records)) { foreach ($records as $value) { if (!array_key_exists($value->gst_name, $data)) { $data[$value->gst_name] = array(); } $fileurl = buildurl($cmid, $value->gf_id, $value->gf_name); $data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->gf_comment, $fileurl); } } return $data; } require_once($CFG->libdir . '/filelib.php'); require_once("$CFG->libdir/csvlib.class.php"); function buildurl($cmid, $fileid, $filename) { $fileurl = new moodle_url("/mod/gradeimporter/view.php", array('id' => $cmid, 'fileid' => $fileid, 'filename' => $filename, 'action' => 1)); return " $filename"; } function editSub($subname, $gradeimporterid, $cmid, $subid) { $url = new moodle_url("/mod/gradeimporter/submission.php", array('id' => $gradeimporterid, 'cmid' => $cmid, 'subid' => $subid, 'update' => 1 ) ); return $subname.''; } function exportCSV($context) { $enrolledusers = get_enrolled_users($context, 'mod/gradeimporter:student'); $header = array('id', 'name', 'email', 'grade', 'comment', 'file'); $csvexport = new csv_export_writer(); $csvexport->set_filename('config'); $csvexport->add_data($header); foreach ($enrolledusers as $value) { $name = $value->firstname . ' ' . $value->lastname; $studententry = array($value->id, $name, $value->email, '', '', ''); $csvexport->add_data($studententry); } $csvexport->download_file(); // $dlfile = $csvexporter->download_array('config', $data); }