1
0

student_viewlib.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. /**
  17. * Queries all feedbacks for a student on gradeimporter_feedback table
  18. * @param int $gradeimporterid - Which gradeimporter instance the feedbacks are related to
  19. * @return array $records - With all feedbacks this student has on this gradeimporter instance
  20. */
  21. function query_feedbacks ($gradeimporterid) {
  22. global $DB, $USER, $CFG;
  23. // Get moodle table prefix, usually 'mdl_'
  24. $tp = $CFG->prefix;
  25. // Build database query to fetch feedbacks for the student
  26. $query = " SELECT
  27. gf.id as id,
  28. gst.name as typename,
  29. gst.id as typeid,
  30. gst.description as typedescription,
  31. gs.name as submissionname,
  32. gs.id as submissionid,
  33. gf.grade as grade,
  34. gf.comment as comment,
  35. gf.name as filename,
  36. gf.contextid as contextid,
  37. gs.description as submissiondescription,
  38. gs.position as position
  39. FROM {$tp}gradeimporter_feedback as gf
  40. JOIN {$tp}gradeimporter_submission as gs
  41. ON gf.submissionid = gs.id
  42. JOIN {$tp}gradeimporter_submissiontype as gst
  43. ON gs.type = gst.id
  44. WHERE gs.gradeimporterid = {$gradeimporterid}
  45. AND gf.studentid = {$USER->id}
  46. AND gs.visibility = 1
  47. ";
  48. // Query database to find students feedbacks
  49. $records = $DB->get_records_sql($query);
  50. // Return query result
  51. return $records;
  52. }
  53. /**
  54. * Builds table to show all feedbacks
  55. * @param array $feedbacks - array with all feedbacks of the student, fetched with query_feedbacks()
  56. * @param int $cmid - Course module id, to build pluginfile as we have to know which course the feedbacks are related to
  57. * @return html_writer $table - String with table html with all feedbacks, ready to be shown
  58. */
  59. function make_feedback_table ($feedbacks, $cmid) {
  60. $table = new html_table();
  61. $table->head = array(get_string('type', 'gradeimporter'),
  62. get_string('submission', 'gradeimporter'),
  63. get_string('grade', 'gradeimporter'),
  64. get_string('comment', 'gradeimporter'),
  65. get_string('file', 'gradeimporter')
  66. );
  67. $table->aling = array('center', 'center', 'center', 'center', 'center');
  68. $table->attributes = array('class' => 'generaltable mod_index');
  69. if (count($feedbacks)) {
  70. // If feedbacks is not an empty list
  71. foreach ($feedbacks as $type => $feedback) {
  72. $rowvalues = array('type_name',
  73. $feedback->submissionname,
  74. $feedback->grade,
  75. $feedback->comment,
  76. get_file($feedback, $cmid)
  77. );
  78. $row = new html_table_row($rowvalues);
  79. $table->data[] = $row;
  80. }
  81. }
  82. echo html_writer::table($table);
  83. }
  84. function get_file ($feedback, $cmid) {
  85. $context = context_module::instance($cmid);
  86. $url = moodle_url::make_pluginfile_url($feedback->contextid,
  87. 'mod_gradeimporter',
  88. 'submissionfiles',
  89. $feedback->submissionid,
  90. "/",
  91. $feedback->filename,
  92. true
  93. );
  94. // Return pluginfile url, will use function mod_gradeimporter_pluginfile at lib.php to serve the file
  95. return "<a href='{$url}'>$feedback->filename</a>";
  96. }