student_viewlib.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. $table->attributes = array('class' => 'generaltable mod_index');
  57. if (count($feedbacks)) {
  58. // If feedbacks is not an empty list
  59. foreach ($feedbacks as $type => $feedback) {
  60. $rowvalues = array('type_name',
  61. $feedback->submissionname,
  62. $feedback->grade,
  63. $feedback->comment,
  64. get_file($feedback, $cmid)
  65. );
  66. $row = new html_table_row($rowvalues);
  67. $table->data[] = $row;
  68. }
  69. }
  70. echo html_writer::table($table);
  71. }
  72. function get_file ($feedback, $cmid) {
  73. global $CFG;
  74. $fs = get_file_storage();
  75. $context = context_module::instance($cmid);
  76. $url = moodle_url::make_pluginfile_url($context->id,
  77. 'mod_gradeimporter',
  78. 'submissionfiles',
  79. 0,
  80. "/",
  81. $feedback->filename,
  82. true
  83. );
  84. // Return pluginfile url, will use function mod_gradeimporter_pluginfile at lib.php to serve the file
  85. return "<a href='{$url}'>$feedback->filename</a>";
  86. }