PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/poasassignment/mod_form.php

https://code.google.com/p/oasychev-moodle-plugins/
PHP | 185 lines | 109 code | 33 blank | 43 comment | 23 complexity | e87d57cb198f3032965f4b5970397d87 MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  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. /**
  17. * The main poasassignment configuration form
  18. *
  19. * It uses the standard core Moodle formslib. For more info about them, please
  20. * visit: http://docs.moodle.org/en/Development:lib/formslib.php
  21. *
  22. * @package mod_poasassignment
  23. * @copyright 2010 Your Name
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25. */
  26. defined('MOODLE_INTERNAL') || die();
  27. require_once($CFG->dirroot.'/course/lib.php');
  28. require_once($CFG->dirroot.'/course/moodleform_mod.php');
  29. class mod_poasassignment_mod_form extends moodleform_mod {
  30. function definition() {
  31. global $COURSE, $CFG;
  32. $mform =& $this->_form;
  33. //echo $this->_instance;
  34. //-------------------------------------------------------------------------------
  35. /// Adding the "general" fieldset, where all the common settings are showed
  36. $mform->addElement('header', 'general', get_string('general', 'form'));
  37. /// Adding the standard "name" field
  38. $mform->addElement('text', 'name', get_string('poasassignmentname', 'poasassignment'), array('size'=>'64'));
  39. if (!empty($CFG->formatstringstriptags)) {
  40. $mform->setType('name', PARAM_TEXT);
  41. } else {
  42. $mform->setType('name', PARAM_CLEAN);
  43. }
  44. $mform->addRule('name', null, 'required', null, 'client');
  45. $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  46. /// Adding the standard "intro" and "introformat" fields
  47. $this->add_intro_editor(true, get_string('poasassignmentintro', 'poasassignment'));
  48. $mform->addElement('filemanager','poasassignmentfiles',get_string('poasassignmentfiles','poasassignment')/* ,null,$filemanager_options */);
  49. $mform->addElement('date_time_selector','availabledate',get_string('availabledate', 'poasassignment'),array('optional'=>true));
  50. $mform->setDefault('availabledate', time());
  51. $mform->addElement('date_time_selector','choicedate',get_string('choicedate', 'poasassignment'),array('optional'=>true));
  52. $mform->setDefault('choicedate', time()+2*24*3600);
  53. $mform->disabledIf('choicedate','activateindividualtasks');
  54. $ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
  55. $mform->addElement('checkbox','preventlatechoice', get_string('preventlatechoice','poasassignment'));
  56. //$mform->setDefault('preventlatechoice', $default_values['preventlatechoice']);
  57. //$mform->addElement('static','elem',$flags);
  58. $mform->addElement('checkbox','randomtasksafterchoicedate', get_string('randomtasksafterchoicedate','poasassignment'));
  59. $mform->addElement('date_time_selector','deadline',get_string('deadline', 'poasassignment'),array('optional'=>true));
  60. $mform->setDefault('deadline', time()+7*24*3600);
  61. $mform->addElement('checkbox','preventlate', get_string('preventlate','poasassignment'));
  62. //$answer = new answer;
  63. //$answer->show_options($mform);
  64. //------------------------------------------------------------------------------------
  65. /// Adding answers block
  66. global $COURSE, $CFG,$DB;
  67. $mform->addElement('header', 'answers', get_string('answers', 'poasassignment'));
  68. $mform->addElement('checkbox','severalattempts', get_string('severalattempts','poasassignment'));
  69. $mform->addHelpButton('severalattempts', 'severalattempts', 'poasassignment');
  70. $mform->addElement('checkbox','newattemptbeforegrade', get_string('newattemptbeforegrade','poasassignment'));
  71. $mform->addHelpButton('newattemptbeforegrade', 'newattemptbeforegrade', 'poasassignment');
  72. $mform->addElement('text','penalty', get_string('penalty','poasassignment'));
  73. $mform->addHelpButton('penalty', 'penalty', 'poasassignment');
  74. $mform->setDefault('penalty',0);
  75. $mform->disabledIf('penalty','severalattempts','notchecked');
  76. $mform->addElement('checkbox','notifyteachers', get_string('notifyteachers','poasassignment'));
  77. $mform->addHelpButton('notifyteachers', 'severalattempts', 'poasassignment');
  78. $mform->addElement('checkbox','notifystudents', get_string('notifystudents','poasassignment'));
  79. $mform->addHelpButton('notifystudents', 'notifystudents', 'poasassignment');
  80. $plugins=$DB->get_records('poasassignment_plugins');
  81. foreach($plugins as $plugin) {
  82. require_once($plugin->path);
  83. $poasassignmentplugin = new $plugin->name();
  84. $poasassignmentplugin->insert_plugin_in_db();
  85. $poasassignmentplugin->show_settings($mform,$this->_instance);
  86. }
  87. //------------------------------------------------------------------------------------
  88. /// Adding individual tasks block
  89. $mform->addElement('header', 'poasassignmentfieldset', get_string('poasassignmentfieldset', 'poasassignment'));
  90. $mform->addElement('checkbox','activateindividualtasks', get_string('activateindividualtasks','poasassignment'));
  91. $mform->addElement('select','howtochoosetask',get_string('howtochoosetask','poasassignment'),array(
  92. get_string('randomtask','poasassignment'),
  93. get_string('parameterchoice','poasassignment'),
  94. get_string('studentchoice','poasassignment')));
  95. $mform->disabledIf('howtochoosetask','activateindividualtasks');
  96. $mform->addElement('checkbox','secondchoice', get_string('secondchoice','poasassignment'));
  97. $mform->disabledIf('secondchoice','activateindividualtasks');
  98. $mform->addElement('select','uniqueness',get_string('uniqueness','poasassignment'),array(
  99. get_string('nouniqueness','poasassignment'),
  100. get_string('uniquewithingroup','poasassignment'),
  101. get_string('uniquewithincourse','poasassignment')));
  102. $mform->disabledIf('uniqueness','activateindividualtasks');
  103. $mform->addElement('checkbox','teacherapproval', get_string('teacherapproval','poasassignment'));
  104. $mform->disabledIf('teacherapproval','activateindividualtasks');
  105. //-------------------------------------------------------------------------------
  106. // add standard elements, common to all modules
  107. $this->standard_coursemodule_elements();
  108. //-------------------------------------------------------------------------------
  109. // add standard buttons, common to all modules
  110. $this->add_action_buttons();
  111. }
  112. function data_preprocessing(&$default_values){
  113. if (isset($default_values['flags'])){
  114. $flags = (int)$default_values['flags'];
  115. unset($default_values['flags']);
  116. $default_values['preventlatechoice']=$flags & PREVENT_LATE_CHOICE;
  117. $default_values['randomtasksafterchoicedate']=$flags & RANDOM_TASKS_AFTER_CHOICEDATE;
  118. $default_values['preventlate']=$flags & PREVENT_LATE;
  119. $default_values['severalattempts']=$flags & SEVERAL_ATTEMPTS;
  120. $default_values['notifyteachers']=$flags & NOTIFY_TEACHERS;
  121. $default_values['notifystudents']=$flags & NOTIFY_STUDENTS;
  122. $default_values['activateindividualtasks']=$flags & ACTIVATE_INDIVIDUAL_TASKS;
  123. $default_values['secondchoice']=$flags & SECOND_CHOICE;
  124. $default_values['teacherapproval']=$flags & TEACHER_APPROVAL;
  125. $default_values['newattemptbeforegrade']=$flags & ALL_ATTEMPTS_AS_ONE;
  126. }
  127. if ($this->current->instance) {
  128. $draftitemid = file_get_submitted_draft_itemid('poasassignmentfiles');
  129. //echo $this->context->id;
  130. file_prepare_draft_area($draftitemid, $this->context->id, 'mod_poasassignment', 'poasassignmentfiles', 0, array('subdirs'=>true));
  131. $default_values['poasassignmentfiles'] = $draftitemid;
  132. }
  133. }
  134. function validation($data, $files) {
  135. $errors = parent::validation($data, $files);
  136. // Check open and close times are consistent.
  137. if ($data['availabledate'] != 0 && $data['choicedate'] != 0 && $data['choicedate'] < $data['availabledate']) {
  138. $errors['choicedate'] = get_string('choicebeforeopen', 'poasassignment');
  139. }
  140. if ($data['availabledate'] != 0 && $data['deadline'] != 0 && $data['deadline'] < $data['availabledate']) {
  141. $errors['deadline'] = get_string('deadlinebeforeopen', 'poasassignment');
  142. }
  143. if ($data['choicedate'] != 0 && $data['deadline'] != 0 && $data['deadline'] < $data['choicedate']) {
  144. $errors['deadline'] = get_string('deadlinebeforechoice', 'poasassignment');
  145. }
  146. if (count($errors) == 0) {
  147. return true;
  148. } else {
  149. return $errors;
  150. }
  151. }
  152. }