lib.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. //adds gradeimporter to add new activity page
  3. function tool_devcourse_extend_navigation_course($navigation, $course, $coursecontext) {
  4. $url = new moodle_url('/admin/tool/devcourse/index.php');
  5. $devcoursenode = navigation_node::create('Development course', $url, navigation_node::TYPE_CUSTOM, 'Dev course', 'devcourse');
  6. $navigation->add_node($devcoursenode);
  7. }
  8. function gradeimporter_supports($feature) {
  9. switch($feature) {
  10. case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE;
  11. case FEATURE_GROUPS: return false;
  12. case FEATURE_GROUPINGS: return false;
  13. case FEATURE_MOD_INTRO: return true;
  14. case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
  15. case FEATURE_GRADE_HAS_GRADE: return false;
  16. case FEATURE_GRADE_OUTCOMES: return false;
  17. case FEATURE_BACKUP_MOODLE2: return true;
  18. default: return null;
  19. }
  20. }
  21. function gradeimporter_add_instance ($data, $mform) {
  22. /*
  23. *Given an object containing all the necessary data,
  24. *(defined by the form in mod_form.php) this function
  25. *creates a new instance and returns the id of this new
  26. *instance.
  27. *
  28. *@param $data: an object from the form in mod_form.php
  29. *@return int: the id of the newly inserted gradeimport record
  30. */
  31. global $DB;
  32. $data->timemodified = time();
  33. $data->id = $DB->insert_record("gradeimporter", $data);
  34. return $data->id;
  35. }
  36. function gradeimporter_update_instance ($data){
  37. /*
  38. *given an object containing all the necessary data,
  39. *(defined by the form in mod_form.php) this function
  40. *updates an existing instance with the new data.
  41. *
  42. *@param $data: an object from the form mod_form.php
  43. *@return boolean: if the record update was a success of fail
  44. */
  45. global $DB;
  46. $data->timemodified = time();
  47. $data->id = $data->instance;
  48. return $DB->update_record('gradeimporter', $data);
  49. }
  50. function gradeimporter_delete_instance($data){
  51. /*
  52. *Given an id of a gradeimporter instance,
  53. * this function permanently deletes the instance
  54. * and any data that depends on it.
  55. *
  56. *@param int $id: Id of the gradeimporter instance
  57. *@return boolean, if the deletion was a success or
  58. * a failure.
  59. */
  60. global $DB;
  61. if (!$data = $DB->get_record('gradeimporter', array('id'=>$id) ) ){
  62. return false;
  63. }
  64. $cm = get_coursemodule_from_instance('gradeimporter', $gradeimporter->id);
  65. $context = context_module::instance($cm->id);
  66. // Files
  67. $fs = get_file_storage();
  68. $fs->delete_area_files($context->id, 'mod_gradeimporter');
  69. //delete all files and submissions associated with this instance
  70. $DB->delete_records('gradeimporter_submission', array('gradeimporterid' => $gradeimporter->id));
  71. $DB->delete_records('gradeimporter_feedback', array('gradeimporterid' => $gradeimporter->id));
  72. //delete the instance itself
  73. $DB->delete_records('gradeimporter', array('id'=>$id) );
  74. return true;
  75. }