locallib.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // This file is part of
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. defined('MOODLE_INTERNAL') || die();
  17. function get_comments($cmid, $id) {
  18. global $DB, $USER, $CFG;
  19. $tp = $CFG->prefix; // gets moodle tables prefix, not everyone uses mdl_
  20. $sql = "
  21. SELECT gf.id gf_id,
  22. gf.grade,
  23. gf.comment gf_comment,
  24. gf.contextid gf_contextid,
  25. gf.fileid gf_fileid,
  26. gf.name gf_name,
  27. gs.name gs_name,
  28. gs.description gs_description,
  29. gst.name gst_name,
  30. gst.description gst_description,
  31. fileid
  32. FROM ".$tp."gradeimporter_feedback gf
  33. JOIN ".$tp."gradeimporter_submission gs
  34. ON gf.submissionid = gs.id
  35. JOIN ".$tp."gradeimporter_submissiontype gst
  36. ON gs.type = gst.id
  37. WHERE gf.studentid = ?";
  38. $records = $DB->get_records_sql($sql, array('studentid' => $USER->id));
  39. $data = array();
  40. if (count($records)) {
  41. foreach ($records as $value) {
  42. if (!array_key_exists($value->gst_name, $data)) {
  43. $data[$value->gst_name] = array();
  44. }
  45. $fileurl = buildurl($cmid, $value->gf_id, $value->gf_name);
  46. $data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->gf_comment, $fileurl);
  47. }
  48. }
  49. return $data;
  50. }
  51. require_once($CFG->libdir . '/filelib.php');
  52. require_once("$CFG->libdir/csvlib.class.php");
  53. function buildurl($cmid, $fileid, $filename) {
  54. $fileurl = new moodle_url("/mod/gradeimporter/view.php", array('id' => $cmid, 'fileid' => $fileid, 'filename' => $filename, 'action' => 1));
  55. return "<a href=$fileurl target=_blank> $filename</a>";
  56. }
  57. function editSub($subname, $gradeimporterid, $cmid, $subid) {
  58. $url = new moodle_url("/mod/gradeimporter/submission.php", array('id' => $gradeimporterid,
  59. 'cmid' => $cmid,
  60. 'subid' => $subid,
  61. 'update' => 1
  62. )
  63. );
  64. return $subname.'<a href='.$url.' target="_blank"><i class="icon fa fa-pencil fa-fw" title="'
  65. .get_string('editSub', 'gradeimporter')
  66. .'" aria-label="'
  67. .get_string('editSub', 'gradeimporter').'"></i>';
  68. }
  69. function exportCSV($context) {
  70. $enrolledusers = get_enrolled_users($context, 'mod/gradeimporter:student');
  71. $header = array('id', 'name', 'email', 'grade', 'comment', 'file');
  72. $csvexport = new csv_export_writer();
  73. $csvexport->set_filename('config');
  74. $csvexport->add_data($header);
  75. foreach ($enrolledusers as $value) {
  76. $name = $value->firstname . ' ' . $value->lastname;
  77. $studententry = array($value->id, $name, $value->email, '', '', '');
  78. $csvexport->add_data($studententry);
  79. }
  80. $csvexport->download_file();
  81. // $dlfile = $csvexporter->download_array('config', $data);
  82. }