.
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;
}
function get_teacher_view($cmid, $gradeimporterid, $enrolledusers) {
global $DB, $CFG;
$tp = $CFG->prefix; // gets moodle tables prefix, not everyone uses mdl_
$table = new html_table();
$table->align = array('center');
$table->attributes = array('class' => 'generaltable mod_index');
// Creates table head
$subrow = new html_table_row();
$cell = new html_table_cell(get_string('nameCol', 'gradeimporter'));
$cell->style = "border:1px solid black";
$cell->colspan = 1;
$subrow->cells[] = $cell;
$submissionssql = "SELECT id, name
FROM ".$tp."gradeimporter_submission
WHERE gradeimporterid = $gradeimporterid
ORDER BY id";
$submissions = $DB->get_records_sql($submissionssql);
foreach ($submissions as $submission) {
$subname = editSub($submission->name, $gradeimporterid, $cmid, $submission->id);
$cell = new html_table_cell($subname);
$cell->colspan = 2;
$cell->style = "border:1px solid black";
$subrow->cells[] = $cell;
// Adds 2 align, one for grade and another to the file
$table->align[] = 'center';
$table->align[] = 'center';
}
$table->data[] = $subrow;
// All submissions names are on the table
$sql = " SELECT gs.id gs_id,
gs.gradeimporterid gs_gradeimporterid,
gs.type gs_type,
gs.name gs_name,
gst.name gst_name,
gf.id gf_id,
gf.studentid gf_studentid,
gf.grade gf_grade,
gf.fileid gf_fileid,
gf.contextid gf_contextid,
gf.name gf_name,
user.firstname user_firstname,
user.lastname user_lastname
FROM ".$tp."gradeimporter_feedback gf
JOIN ".$tp."user user
ON user.id = gf.studentid
JOIN ".$tp."gradeimporter_submission gs
ON gs.id = gf.submissionid
JOIN ".$tp."gradeimporter_submissiontype gst
ON gst.id = gs.type
WHERE gs.gradeimporterid = $gradeimporterid
ORDER BY user.firstname, user.lastname, gs.id, gf.id";
$records = $DB->get_recordset_sql($sql);
$userslist = array();
foreach ($enrolledusers as $user) {
$userslist[$user->id] = array('name' => $user->firstname." ".$user->lastname);
}
foreach ($records as $record) {
$url = buildurl($cmid, $record->gf_id, $record->gf_name);
$userslist[$record->gf_studentid][$record->gs_id] = array('grade' => $record->gf_grade, 'file' => $url);
}
foreach ($userslist as $user) {
$row = new html_table_row();
$cell = new html_table_cell($user['name']);
$cell->style = "border:1px solid black";
$row->cells[] = $cell;
foreach ($submissions as $submission) {
if (array_key_exists($submission->id, $user)) {
$url = $user[$submission->id]['file'];
$grade = $user[$submission->id]['grade'];
} else {
$url = '-';
$grade = '-';
}
$cell = new html_table_cell($grade);
$cell->style = "border:1px solid black; border-right:0";
$row->cells[] = $cell;
$cell = new html_table_cell($url);
$cell->style = "border:1px solid black; border-left:0";
$row->cells[] = $cell;
}
$table->data[] = $row;
}
echo html_writer::table($table);
}
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);
}