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

/mod/feedback/mod_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 200 lines | 125 code | 41 blank | 34 comment | 12 complexity | d7a16d7758b65b8b4a0190f175e3c0ef MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  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. * print the form to add or edit a feedback-instance
  18. *
  19. * @author Andreas Grabs
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  21. * @package feedback
  22. */
  23. //It must be included from a Moodle page
  24. if (!defined('MOODLE_INTERNAL')) {
  25. die('Direct access to this script is forbidden.');
  26. }
  27. require_once($CFG->dirroot.'/course/moodleform_mod.php');
  28. class mod_feedback_mod_form extends moodleform_mod {
  29. public function definition() {
  30. global $CFG, $DB;
  31. $editoroptions = feedback_get_editor_options();
  32. $mform =& $this->_form;
  33. //-------------------------------------------------------------------------------
  34. $mform->addElement('header', 'general', get_string('general', 'form'));
  35. $mform->addElement('text', 'name', get_string('name', 'feedback'), array('size'=>'64'));
  36. $mform->setType('name', PARAM_TEXT);
  37. $mform->addRule('name', null, 'required', null, 'client');
  38. $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  39. $this->add_intro_editor(true, get_string('description', 'feedback'));
  40. //-------------------------------------------------------------------------------
  41. $mform->addElement('header', 'timinghdr', get_string('availability'));
  42. $mform->addElement('date_time_selector', 'timeopen', get_string('feedbackopen', 'feedback'),
  43. array('optional' => true));
  44. $mform->addElement('date_time_selector', 'timeclose', get_string('feedbackclose', 'feedback'),
  45. array('optional' => true));
  46. //-------------------------------------------------------------------------------
  47. $mform->addElement('header', 'feedbackhdr', get_string('questionandsubmission', 'feedback'));
  48. $options=array();
  49. $options[1] = get_string('anonymous', 'feedback');
  50. $options[2] = get_string('non_anonymous', 'feedback');
  51. $mform->addElement('select',
  52. 'anonymous',
  53. get_string('anonymous_edit', 'feedback'),
  54. $options);
  55. // check if there is existing responses to this feedback
  56. if (is_numeric($this->_instance) AND
  57. $this->_instance AND
  58. $feedback = $DB->get_record("feedback", array("id"=>$this->_instance))) {
  59. $completed_feedback_count = feedback_get_completeds_group_count($feedback);
  60. } else {
  61. $completed_feedback_count = false;
  62. }
  63. if ($completed_feedback_count) {
  64. $multiple_submit_value = $feedback->multiple_submit ? get_string('yes') : get_string('no');
  65. $mform->addElement('text',
  66. 'multiple_submit_static',
  67. get_string('multiplesubmit', 'feedback'),
  68. array('size'=>'4',
  69. 'disabled'=>'disabled',
  70. 'value'=>$multiple_submit_value));
  71. $mform->setType('multiple_submit_static', PARAM_RAW);
  72. $mform->addElement('hidden', 'multiple_submit', '');
  73. $mform->setType('multiple_submit', PARAM_INT);
  74. $mform->addHelpButton('multiple_submit_static', 'multiplesubmit', 'feedback');
  75. } else {
  76. $mform->addElement('selectyesno',
  77. 'multiple_submit',
  78. get_string('multiplesubmit', 'feedback'));
  79. $mform->addHelpButton('multiple_submit', 'multiplesubmit', 'feedback');
  80. }
  81. $mform->addElement('selectyesno', 'email_notification', get_string('email_notification', 'feedback'));
  82. $mform->addHelpButton('email_notification', 'email_notification', 'feedback');
  83. $mform->addElement('selectyesno', 'autonumbering', get_string('autonumbering', 'feedback'));
  84. $mform->addHelpButton('autonumbering', 'autonumbering', 'feedback');
  85. //-------------------------------------------------------------------------------
  86. $mform->addElement('header', 'aftersubmithdr', get_string('after_submit', 'feedback'));
  87. $mform->addElement('selectyesno', 'publish_stats', get_string('show_analysepage_after_submit', 'feedback'));
  88. $mform->addElement('editor',
  89. 'page_after_submit_editor',
  90. get_string("page_after_submit", "feedback"),
  91. null,
  92. $editoroptions);
  93. $mform->setType('page_after_submit_editor', PARAM_RAW);
  94. $mform->addElement('text',
  95. 'site_after_submit',
  96. get_string('url_for_continue', 'feedback'),
  97. array('size'=>'64', 'maxlength'=>'255'));
  98. $mform->setType('site_after_submit', PARAM_TEXT);
  99. $mform->addHelpButton('site_after_submit', 'url_for_continue', 'feedback');
  100. //-------------------------------------------------------------------------------
  101. $this->standard_coursemodule_elements();
  102. //-------------------------------------------------------------------------------
  103. // buttons
  104. $this->add_action_buttons();
  105. }
  106. public function data_preprocessing(&$default_values) {
  107. $editoroptions = feedback_get_editor_options();
  108. if ($this->current->instance) {
  109. // editing an existing feedback - let us prepare the added editor elements (intro done automatically)
  110. $draftitemid = file_get_submitted_draft_itemid('page_after_submit');
  111. $default_values['page_after_submit_editor']['text'] =
  112. file_prepare_draft_area($draftitemid, $this->context->id,
  113. 'mod_feedback', 'page_after_submit', false,
  114. $editoroptions,
  115. $default_values['page_after_submit']);
  116. $default_values['page_after_submit_editor']['format'] = $default_values['page_after_submitformat'];
  117. $default_values['page_after_submit_editor']['itemid'] = $draftitemid;
  118. } else {
  119. // adding a new feedback instance
  120. $draftitemid = file_get_submitted_draft_itemid('page_after_submit_editor');
  121. // no context yet, itemid not used
  122. file_prepare_draft_area($draftitemid, null, 'mod_feedback', 'page_after_submit', false);
  123. $default_values['page_after_submit_editor']['text'] = '';
  124. $default_values['page_after_submit_editor']['format'] = editors_get_preferred_format();
  125. $default_values['page_after_submit_editor']['itemid'] = $draftitemid;
  126. }
  127. }
  128. public function get_data() {
  129. $data = parent::get_data();
  130. if ($data) {
  131. $data->page_after_submitformat = $data->page_after_submit_editor['format'];
  132. $data->page_after_submit = $data->page_after_submit_editor['text'];
  133. if (!empty($data->completionunlocked)) {
  134. // Turn off completion settings if the checkboxes aren't ticked
  135. $autocompletion = !empty($data->completion) &&
  136. $data->completion == COMPLETION_TRACKING_AUTOMATIC;
  137. if (!$autocompletion || empty($data->completionsubmit)) {
  138. $data->completionsubmit=0;
  139. }
  140. }
  141. }
  142. return $data;
  143. }
  144. public function validation($data, $files) {
  145. $errors = parent::validation($data, $files);
  146. return $errors;
  147. }
  148. public function add_completion_rules() {
  149. $mform =& $this->_form;
  150. $mform->addElement('checkbox',
  151. 'completionsubmit',
  152. '',
  153. get_string('completionsubmit', 'feedback'));
  154. return array('completionsubmit');
  155. }
  156. public function completion_rule_enabled($data) {
  157. return !empty($data['completionsubmit']);
  158. }
  159. }