teacher_viewlib.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. class Teacherview {
  17. private $cmid;
  18. private $gradeimporterid;
  19. private $context;
  20. private $table;
  21. private $cellstyle = "border:1px solid black";
  22. public function __construct(int $cmid, int $gradeimporterid) {
  23. $this->$cmid = $cmid;
  24. $this->$gradeimporterid = $gradeimporterid;
  25. $this->context = context_module::instance($this->get_cmid);
  26. $this->$table = make_table($cmid, $gradeimporterid);
  27. }
  28. private function get_cmid() {
  29. return $this->cmid;
  30. }
  31. private function get_gradeimporterid() {
  32. return $this->gradeimporterid;
  33. }
  34. private function get_context() {
  35. return $this->context;
  36. }
  37. private function get_cellstyle() {
  38. return $this->cellstyle;
  39. }
  40. public function get_table() {
  41. return $this->table;
  42. }
  43. private function make_table() {
  44. global $DB, $CFG;
  45. // Prepare variables
  46. $studentlist = get_studentlist();
  47. // Create table
  48. $table = new html_table();
  49. $table->align = array('center');
  50. $table->attributes = array('class' => 'generaltable mod_index');
  51. $table->head = get_table_head();
  52. return $table;
  53. }
  54. private function get_studentlist() {
  55. // Get students list with userid as key and fullname as value
  56. $enrolledusers = get_enrolled_users($this->get_context(), 'mod/gradeimporter:view',
  57. 0, 'u.id, u.firstname, u.lastname',
  58. 'u.firstname, u.lastname'
  59. );
  60. $studentlist = array();
  61. foreach ($enrolledusers as $user) {
  62. $userslist[$user->id] = array('name' => $user->firstname." ".$user->lastname);
  63. }
  64. return $studentlist;
  65. }
  66. private function get_table_head() {
  67. global $CFG;
  68. $tp = $CFG->prefix;
  69. // Creates teacher view table head
  70. $head = new html_table_row();
  71. // Creates name column header
  72. $cell = new html_table_cell(get_string('nameCol', 'gradeimporter'));
  73. $cell->style = $this->get_cellstyle();
  74. $cell->colspan = 1;
  75. // Add name header to header row
  76. $header->cells[] = $cell;
  77. // Get Submissions names and ids
  78. $sql = "SELECT id, name, type
  79. FROM {$tp}gradeimporter_submission
  80. WHERE gradeimporterid = {$this->get_gradeimporterid()}
  81. ORDER BY type, id";
  82. $submissions = $DB->get_records($sql);
  83. foreach ($submissions as $submission) {
  84. // $subname = editSub($submission->name, $gradeimporterid, $cmid, $submission->id);
  85. $cell = new html_table_cell($submission->name);
  86. $cell->colspan = 2;
  87. $cell->style = $this->get_cellstyle();
  88. $header->cells[] = $cell;
  89. }
  90. return $header;
  91. }
  92. }