student_viewlib.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. function query_feedbacks($cmid, $gradeimporterid) {
  17. global $DB, $USER, $CFG;
  18. // Get moodle table prefix, usually 'mdl_'
  19. $tp = $CFG->prefix;
  20. // Build database query to fetch feedbacks for the student
  21. $query = " SELECT
  22. /* gst.name as typename,
  23. gst.id as typeid,
  24. gst.description as typedescription, */
  25. gf.id as id,
  26. gs.name as submissionname,
  27. gs.id as submissionid,
  28. gf.grade as grade,
  29. gf.comment as comment,
  30. gf.name as filename,
  31. gs.description as submissiondescription,
  32. gs.position as position
  33. FROM {$tp}gradeimporter_feedback as gf
  34. JOIN {$tp}gradeimporter_submission as gs
  35. ON gf.submissionid = gs.id
  36. /* JOIN {$tp}gradeimporter_submissiontype as gst
  37. ON gs.type = gst.id */
  38. WHERE gs.gradeimporterid = {$gradeimporterid}
  39. AND gf.studentid = {$USER->id}
  40. AND gs.visibility = 1
  41. ";
  42. // Query database to find students feedbacks
  43. $records = $DB->get_records_sql($query);
  44. // Return query result
  45. return $records;
  46. }
  47. function make_feedback_table ($feedbacks, $cmid) {
  48. $table = new html_table();
  49. $table->head = array(get_string('type', 'gradeimporter'),
  50. get_string('submission', 'gradeimporter'),
  51. get_string('grade', 'gradeimporter'),
  52. get_string('comment', 'gradeimporter'),
  53. get_string('file', 'gradeimporter')
  54. );
  55. $table->aling = array('center', 'center', 'center', 'center', 'center');
  56. if (count($feedbacks)) {
  57. // If feedbacks is not an empty list
  58. foreach ($feedbacks as $type => $feedback) {
  59. $rowvalues = array('type_name',
  60. $feedback->submissionname,
  61. $feedback->grade,
  62. $feedback->comment,
  63. get_file($feedback, $cmid)
  64. );
  65. $row = new html_table_row($rowvalues);
  66. $table->data[] = $row;
  67. }
  68. }
  69. echo html_writer::table($table);
  70. }
  71. function get_file ($feedback, $cmid) {
  72. global $CFG;
  73. $fs = get_file_storage();
  74. $context = context_module::instance($cmid);
  75. $url = moodle_url::make_pluginfile_url($context->id,
  76. 'mod_gradeimporter',
  77. 'submissionfiles',
  78. 0,
  79. "/",
  80. $feedback->filename,
  81. true
  82. );
  83. // Return pluginfile url, will use function mod_gradeimporter_pluginfile at lib.php to serve the file
  84. return "<a href='{$url}'>$feedback->filename</a>";
  85. }