mod_form.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. if (!defined('MOODLE_INTERNAL')) {
  3. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  4. }
  5. require_once($CFG->dirroot.'/course/moodleform_mod.php');
  6. //require_once($CFG->dirroot.'/mod/gradeimporter/lib.php');
  7. class mod_gradeimporter_mod_form extends moodleform_mod {
  8. function definition() {
  9. global $CFG, $DB, $OUTPUT;
  10. $mform =& $this->_form;
  11. $course_modules_id = optional_param('update', 0, PARAM_INT);
  12. $mform->addElement('text', 'name', get_string('instanceName', 'gradeimporter'), array('size'=>'64'));
  13. $mform->setType('name', PARAM_TEXT);
  14. $mform->addRule('name', get_string('error_instanceNameField', 'gradeimporter'), 'required', null, 'client');
  15. $this->standard_intro_elements(get_string('description', 'gradeimporter'));
  16. $ynoptions = array(0 => get_string('visibilityOn', 'gradeimporter'),
  17. 1 => get_string('visibilityOff', 'gradeimporter'));
  18. $this->standard_coursemodule_elements();
  19. $this->add_action_buttons();
  20. }
  21. function data_preprocessing (&$default_values) {
  22. parent::data_preprocessing($default_values);
  23. $mform = & $this->_form;
  24. if (!$mform->isSubmitted() && array_key_exists('name', $default_values)) {
  25. //TODO Remove when updating all the iassign that are tag &lt;ia_uc&gt;
  26. $ia_uc = explode('&lt;ia_uc&gt;', $default_values['name']);
  27. $default_values['name'] = $ia_uc[0];
  28. }
  29. }
  30. function definition_after_data() {
  31. global $DB;
  32. $mform = & $this->_form;
  33. $data = $mform->exportValues();
  34. if ($mform->isSubmitted() && array_key_exists('iassign_statement', $data)) {
  35. $iassign_statements = $data['iassign_statement'];
  36. foreach ($iassign_statements as $key => $value) {
  37. if ($value == 1) {
  38. $updateentry = new stdClass();
  39. $updateentry->id = $key;
  40. $updateentry->timemodified = time();
  41. if (isset($data['grade_enabled']) && $data['grade_enabled'] == 1)
  42. $updateentry->grade = $data['grade'];
  43. if (isset($data['timedue_enabled']) && $data['timedue_enabled'] == 1)
  44. $updateentry->timedue = $data['timedue'];
  45. if (isset($data['timeavailable_enabled']) && $data['timeavailable_enabled'] == 1)
  46. $updateentry->timeavailable = $data['timeavailable'];
  47. if (isset($data['preventlate_enabled']) && $data['preventlate_enabled'] == 1)
  48. $updateentry->preventlate = $data['preventlate'];
  49. if (isset($data['test_enabled']) && $data['test_enabled'] == 1)
  50. $updateentry->test = $data['test'];
  51. if (isset($data['max_experiment_enabled']) && $data['max_experiment_enabled'] == 1)
  52. $updateentry->max_experiment = $data['max_experiment'];
  53. if (!$DB->update_record("iassign_statement", $updateentry))
  54. print_error('error_update', 'iassign');
  55. }
  56. }
  57. }
  58. }
  59. }