view.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
  3. require_once(dirname(__FILE__).'/lib.php');
  4. require_once($CFG->libdir.'/filelib.php');
  5. require_once('locallib.php');
  6. global $DB;
  7. $id = optional_param('id', 0, PARAM_INT); // course_module ID, or
  8. $g = optional_param('g', 0, PARAM_INT); // gradeimporter instance ID, should be named as the first character of the module
  9. $action = optional_param('action', 0, PARAM_INT);
  10. $cmid = optional_param('cmid', 0, PARAM_INT);
  11. $id = optional_param('id', 0, PARAM_INT);
  12. $fileid = optional_param('fileid', 0, PARAM_INT);
  13. $filename = optional_param('filename', 'a', PARAM_TEXT);
  14. if ($id) {
  15. if (! $cm = get_coursemodule_from_id('gradeimporter', $id)) {
  16. error('Course Module ID was incorrect');
  17. }
  18. if (! $course = $DB->get_record('course', array('id'=> $cm->course))) {
  19. error('Course is misconfigured');
  20. }
  21. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id'=> $cm->instance) ) ) {
  22. error('Course module is incorrect');
  23. }
  24. } else if ($g) {
  25. if (! $gradeimporter = $DB->get_record('gradeimporter', array('id'=> $g)) ){
  26. error('Course module is incorrect');
  27. }
  28. if (! $course = $DB->get_record('course', array('id'=> $gradeimporter->course)) ) {
  29. error('Course is misconfigured');
  30. }
  31. if (! $cm = get_coursemodule_from_instance('gradeimporter', $gradeimporter->id, $course->id)) {
  32. error('Course Module ID was incorrect');
  33. }
  34. } else {
  35. error('You must specify a course_module ID or an instance ID');
  36. }
  37. require_login($course, true, $cm);
  38. $context = context_module::instance($cm->id);
  39. if ($action==1 && has_capability('mod/gradeimporter:view', $context)){
  40. //download feedback file
  41. $fs = get_file_storage();
  42. $file = $fs->get_file($context->id, 'mod_gradeimporter', 'gradeimporter_feedback', $fileid, '/', $filename);
  43. if ($file){
  44. send_stored_file($file, 86400, 0, true);
  45. }
  46. } else if ($action == 2 && has_capability('mod/gradeimporter:edit', $context)){
  47. //download students csv with their id
  48. exportCSV($context);
  49. }
  50. /// Print the page header
  51. $PAGE->set_cm($cm);
  52. $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $cm->id));
  53. $PAGE->set_title(format_string($gradeimporter->name));
  54. $PAGE->set_heading(format_string($course->fullname));
  55. $PAGE->set_context($context);
  56. $output = $PAGE->get_renderer('mod_folder');
  57. echo $output->header();
  58. $heading = get_string('displayingview', 'gradeimporter', $gradeimporter->name);
  59. echo $output->heading($heading);
  60. //button to add new submission
  61. if (has_capability('mod/gradeimporter:edit', $context)) {
  62. $url = new moodle_url('/mod/gradeimporter/submission.php');
  63. $newbutton = '<form action="'. $url . '">'.
  64. '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
  65. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  66. '<input type="hidden" name="page" value="0" />'.
  67. '<input type="submit" Value="'.get_string('newsubmission', 'gradeimporter').'" />'.
  68. '</form>';
  69. echo $newbutton;
  70. $url = new moodle_url("/mod/gradeimporter/view.php", array('id'=>$id, 'cmid'=>$cm->id, 'action'=>2));
  71. $newbutton = '<form action="'. $url . '">'.
  72. '<input type="hidden" name="id" value="'. $id .'" />'.
  73. '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
  74. '<input type="hidden" name="action" value="2" />'.
  75. '<input type="submit" Value="'.get_string('downloadconfigcsv', 'gradeimporter').'" />'.
  76. '</form>';
  77. echo $newbutton;
  78. }
  79. //tabela com as notas vem aqui
  80. require_once($CFG->libdir . '/tablelib.php');
  81. require_once(dirname(__FILE__).'/locallib.php');
  82. use \gradeimporter\feedback;
  83. $data = feedback::get_comments($cm->id, $id);
  84. if (has_capability('mod/gradeimporter:edit', $context)){
  85. //loads teacher view
  86. $table = new html_table();
  87. $table->attributes['class'] = 'generaltable mod_index';
  88. $table->head = array ("Aluno", "Tipo", "Nome", "Nota", "Arquivos");
  89. $table->align = array ('center', 'center', 'center', 'center', 'center');
  90. if (count($data)) {
  91. $currentAluno = "";
  92. foreach ($data as $aluno => $datas) {
  93. if ($currentAluno != "" && $currentAluno != $aluno) {
  94. $row = new html_table_row();
  95. $cell = new html_table_cell();
  96. $cell->colspan = 6;
  97. $row->cells[] = $cell;
  98. $table->data[] = $row;
  99. }
  100. $t = count($datas);
  101. foreach ($datas as $tipo => $cells) {$t += count($cells);};
  102. $currentAluno = $aluno;
  103. $row = new html_table_row();
  104. $cell = new html_table_cell($aluno);
  105. $cell->rowspan = $t+1;
  106. $row->cells[] = $cell;
  107. $table->data[] = $row;
  108. foreach ($datas as $tipo => $cells) {
  109. $row = new html_table_row();
  110. $cell = new html_table_cell($tipo);
  111. $cell->rowspan = count($cells)+1;
  112. $row->cells[] = $cell;
  113. $table->data[] = $row;
  114. foreach ($cells as $cell) {
  115. $row = new html_table_row();
  116. foreach ($cell as $value) {
  117. $row->cells[] = new html_table_cell($value);
  118. }
  119. $table->data[] = $row;
  120. }
  121. }
  122. }
  123. }
  124. } else {
  125. //loads student view
  126. $table = new html_table();
  127. $table->attributes['class'] = 'generaltable mod_index';
  128. $table->head = array ("Tipo", "Nome", "Nota", "Comentários", "Arquivos");
  129. $table->align = array ('center', 'center', 'center', 'center', 'center');
  130. if (count($data)) {
  131. $current = "";
  132. foreach ($data as $tipo => $cells) {
  133. if ($current != "" && $current != $tipo) {
  134. $row = new html_table_row();
  135. $cell = new html_table_cell();
  136. $cell->colspan = 5;
  137. $row->cells[] = $cell;
  138. $table->data[] = $row;
  139. }
  140. $current = $tipo;
  141. $row = new html_table_row();
  142. $cell = new html_table_cell($tipo);
  143. $cell->rowspan = count($cells)+1;
  144. $row->cells[] = $cell;
  145. $table->data[] = $row;
  146. foreach ($cells as $cell) {
  147. $row = new html_table_row();
  148. foreach ($cell as $value) {
  149. $cell = new html_table_cell($value);
  150. $row->cells[] = $cell;
  151. }
  152. $table->data[] = $row;
  153. }
  154. }
  155. }
  156. }
  157. echo html_writer::table($table);
  158. /// Finish the page
  159. echo $output->footer();