123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- // This file is part of
- //
- // Moodle is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // Moodle is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
- 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 "<a href=$fileurl target=_blank> $filename</a>";
- }
- 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.'<a href='.$url.' target="_blank"><i class="icon fa fa-pencil fa-fw" title="'
- .get_string('editSub', 'gradeimporter')
- .'" aria-label="'
- .get_string('editSub', 'gradeimporter').'"></i>';
- }
- 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);
- }
|