view.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
  17. require_once(dirname(__FILE__).'/lib.php');
  18. require_once($CFG->libdir.'/filelib.php');
  19. require_once('locallib.php');
  20. global $DB;
  21. $id = optional_param('id', 0, PARAM_INT); // Course_module ID.
  22. $g = optional_param('g', 0, PARAM_INT); // Gradeimporter instance ID, should be named as the first character of the module.
  23. $action = optional_param('action', 0, PARAM_INT);
  24. // $cmid = optional_param('cmid', 0, PARAM_INT);
  25. $id = optional_param('id', 0, PARAM_INT);
  26. $fileid = optional_param('fileid', 0, PARAM_INT);
  27. $filename = optional_param('filename', 'a', PARAM_TEXT);
  28. if ($id) {
  29. if (! $cm = get_coursemodule_from_id('gradeimporter', $id)) {
  30. error('Course Module ID was incorrect');
  31. }
  32. if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
  33. error('Course is misconfigured');
  34. }
  35. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id' => $cm->instance))) {
  36. error('Course module is incorrect');
  37. }
  38. } else if ($g) {
  39. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id' => $g))) {
  40. error('Course module is incorrect');
  41. }
  42. if (! $course = $DB->get_record('course', array('id' => $gradeimporter->course))) {
  43. error('Course is misconfigured');
  44. }
  45. if (! $cm = get_coursemodule_from_instance('gradeimporter', $gradeimporter->id, $course->id)) {
  46. error('Course Module ID was incorrect');
  47. }
  48. } else {
  49. error('You must specify a course_module ID or an instance ID');
  50. }
  51. require_login($course, true, $cm);
  52. $context = context_module::instance($cm->id);
  53. if ($action == 1 && has_capability('mod/gradeimporter:view', $context)) {
  54. // Download feedback file.
  55. $fs = get_file_storage();
  56. $file = $fs->get_file($context->id, 'mod_gradeimporter', 'gradeimporter_feedback', $fileid, '/', $filename);
  57. if ($file) {
  58. send_stored_file($file, 86400, 0, true);
  59. }
  60. } else if ($action == 2 && has_capability('mod/gradeimporter:edit', $context)) {
  61. // Download students csv with their id.
  62. exportCSV($context);
  63. }
  64. // Print the page header.
  65. $PAGE->set_cm($cm);
  66. $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $cm->id));
  67. $PAGE->set_title(format_string($gradeimporter->name));
  68. $PAGE->set_heading(format_string($course->fullname));
  69. $PAGE->set_context($context);
  70. $output = $PAGE->get_renderer('mod_folder');
  71. echo $output->header();
  72. $heading = get_string('displayingview', 'gradeimporter', $gradeimporter->name);
  73. echo $output->heading($heading);
  74. // Button to add new submission.
  75. if (has_capability('mod/gradeimporter:edit', $context)) {
  76. $url = new moodle_url('/mod/gradeimporter/submission.php');
  77. $newbutton = '<form action="'. $url . '">'.
  78. '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
  79. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  80. '<input type="hidden" name="page" value="0" />'.
  81. '<input type="submit" Value="'.get_string('newsubmission', 'gradeimporter').'" />'.
  82. '</form>';
  83. echo $newbutton;
  84. $url = new moodle_url("/mod/gradeimporter/view.php", array('id' => $id, 'cmid' => $cm->id, 'action' => 2));
  85. $newbutton = '<form action="'. $url . '">'.
  86. '<input type="hidden" name="id" value="'. $id .'" />'.
  87. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  88. '<input type="hidden" name="action" value="2" />'.
  89. '<input type="submit" Value="'.get_string('downloadconfigcsv', 'gradeimporter').'" />'.
  90. '</form>';
  91. echo $newbutton;
  92. }
  93. // Tabela com as notas vem aqui.
  94. require_once($CFG->libdir . '/tablelib.php');
  95. require_once(dirname(__FILE__).'/locallib.php');
  96. if (has_capability('mod/gradeimporter:edit', $context)) {
  97. // Loads teacher view.
  98. $enrolledusers = get_enrolled_users($context, 'mod/gradeimporter:view', 0, 'u.id, u.firstname, u.lastname', 'u.firstname, u.lastname');
  99. get_teacher_view($cm->id, $gradeimporter->id, $enrolledusers);
  100. } else {
  101. $data = get_comments($cm->id, $id);
  102. // Loads student view.
  103. $table = new html_table();
  104. $table->attributes['class'] = 'generaltable mod_index';
  105. $table->head = array(get_string('type', 'gradeimporter'),
  106. get_string('submission', 'gradeimporter'),
  107. get_string('grade', 'gradeimporter'),
  108. get_string('comment', 'gradeimporter'),
  109. get_string('file', 'gradeimporter'));
  110. $table->align = array('center', 'center', 'center', 'center', 'center');
  111. if (count($data)) {
  112. $current = "";
  113. foreach ($data as $tipo => $cells) {
  114. if ($current != "" && $current != $tipo) {
  115. $row = new html_table_row();
  116. $cell = new html_table_cell();
  117. $cell->colspan = 5;
  118. $row->cells[] = $cell;
  119. $table->data[] = $row;
  120. }
  121. $current = $tipo;
  122. $row = new html_table_row();
  123. $cell = new html_table_cell($tipo);
  124. $cell->rowspan = count($cells) + 1;
  125. $row->cells[] = $cell;
  126. $table->data[] = $row;
  127. foreach ($cells as $cell) {
  128. $row = new html_table_row();
  129. foreach ($cell as $value) {
  130. $cell = new html_table_cell($value);
  131. $row->cells[] = $cell;
  132. }
  133. $table->data[] = $row;
  134. }
  135. }
  136. }
  137. echo html_writer::table($table);
  138. }
  139. $PAGE->requires->js_call_amd('mod_gradeimporter/helloworld', 'helloworld');
  140. $PAGE->requires->js_call_amd('mod_gradeimporter/hello', 'informal', array('marquinho'));
  141. // Finishes the page!
  142. echo $output->footer();