locallib.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace gradeimporter;
  3. use context_user;
  4. class feedback {
  5. public static function is_capability() {
  6. global $USER;
  7. $usercontext = context_user::instance($USER->id);
  8. return has_capability('moodle/course:update', $usercontext);
  9. }
  10. public static function get_comments() {
  11. global $DB, $USER, $CFG;
  12. $tp = $CFG->prefix; // gets moodle tables prefix, not everyone uses mdl_
  13. $sql = "
  14. SELECT gf.id,
  15. gf.grade,
  16. gf.comment,
  17. gf.contextid,
  18. gf.name gf_name,
  19. gs.name gs_name,
  20. gs.description gs_description,
  21. gst.name gst_name,
  22. gst.description gst_description,
  23. fileid
  24. FROM ".$tp."gradeimporter_feedback gf
  25. JOIN ".$tp."gradeimporter_submission gs
  26. ON gf.submissionid = gs.id
  27. JOIN ".$tp."gradeimporter_submissiontype gst
  28. ON gs.type = gst.id
  29. WHERE gf.studentid = ?";
  30. $comments = array();
  31. $records = $DB->get_records_sql($sql, array('studentid'=>$USER->id));
  32. $data = array();
  33. if (count($records)) {
  34. foreach ($records as $key => $value) {
  35. if (!array_key_exists($value->gst_name, $data)) $data[$value->gst_name] = array();
  36. //$fileurl = moodle_url::make_pluginfile_url($value->gf_contextid, 'mod_gradeimporter', 'gradeimporter_feedback', $value->gf_submissionid, '/', $value->gf_filename, false);
  37. $data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->gf_name);
  38. //$data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->fileid);
  39. }
  40. }
  41. return $data;
  42. }
  43. }
  44. //
  45. // INSERT INTO `mdl_gradeimporter_feedback` (`id`, `submissionid`, `studentid`, `grade`, `comment`, `fileid`, `usermodified`, `timecreated`, `timemodified`)
  46. // VALUES
  47. // (1, 10, 1, 10.00, 'ok muito bem', 100, 0, 0, 0);
  48. //