PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/feedback/edit_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 203 lines | 126 code | 36 blank | 41 comment | 10 complexity | cf135aaa29f65c7eb47dfe5edbc11a91 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. * prints the forms to choose an item-typ to create items and to choose a template to use
  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->libdir.'/formslib.php');
  28. class feedback_edit_add_question_form extends moodleform {
  29. public function definition() {
  30. $mform = $this->_form;
  31. //headline
  32. $mform->addElement('header', 'general', get_string('content'));
  33. // visible elements
  34. $feedback_names_options = feedback_load_feedback_items_options();
  35. $attributes = 'onChange="M.core_formchangechecker.set_form_submitted(); this.form.submit()"';
  36. $mform->addElement('select', 'typ', '', $feedback_names_options, $attributes);
  37. // hidden elements
  38. $mform->addElement('hidden', 'cmid');
  39. $mform->setType('cmid', PARAM_INT);
  40. $mform->addElement('hidden', 'position');
  41. $mform->setType('position', PARAM_INT);
  42. // buttons
  43. $mform->addElement('submit', 'add_item', get_string('add_item', 'feedback'), array('class' => 'hiddenifjs'));
  44. }
  45. }
  46. class feedback_edit_use_template_form extends moodleform {
  47. private $feedbackdata;
  48. public function definition() {
  49. $this->feedbackdata = new stdClass();
  50. //this function can not be called, because not all data are available at this time
  51. //I use set_form_elements instead
  52. }
  53. //this function set the data used in set_form_elements()
  54. //in this form the only value have to set is course
  55. //eg: array('course' => $course)
  56. public function set_feedbackdata($data) {
  57. if (is_array($data)) {
  58. if (!isset($this->feedbackdata)) {
  59. $this->feedbackdata = new stdClass();
  60. }
  61. foreach ($data as $key => $val) {
  62. $this->feedbackdata->{$key} = $val;
  63. }
  64. }
  65. }
  66. //here the elements will be set
  67. //this function have to be called manually
  68. //the advantage is that the data are already set
  69. public function set_form_elements() {
  70. $mform =& $this->_form;
  71. $elementgroup = array();
  72. //headline
  73. $mform->addElement('header', 'using_templates', get_string('using_templates', 'feedback'));
  74. // hidden elements
  75. $mform->addElement('hidden', 'id');
  76. $mform->setType('id', PARAM_INT);
  77. // visible elements
  78. $templates_options = array();
  79. $owntemplates = feedback_get_template_list($this->feedbackdata->course, 'own');
  80. $publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
  81. $options = array();
  82. if ($owntemplates or $publictemplates) {
  83. $options[''] = array('' => get_string('choose'));
  84. if ($owntemplates) {
  85. $courseoptions = array();
  86. foreach ($owntemplates as $template) {
  87. $courseoptions[$template->id] = $template->name;
  88. }
  89. $options[get_string('course')] = $courseoptions;
  90. }
  91. if ($publictemplates) {
  92. $publicoptions = array();
  93. foreach ($publictemplates as $template) {
  94. $publicoptions[$template->id] = $template->name;
  95. }
  96. $options[get_string('public', 'feedback')] = $publicoptions;
  97. }
  98. $attributes = 'onChange="M.core_formchangechecker.set_form_submitted(); this.form.submit()"';
  99. $elementgroup[] = $mform->createElement('selectgroups',
  100. 'templateid',
  101. '',
  102. $options,
  103. $attributes);
  104. $elementgroup[] = $mform->createElement('submit',
  105. 'use_template',
  106. get_string('use_this_template', 'feedback'));
  107. $mform->addGroup($elementgroup, 'elementgroup', '', array(' '), false);
  108. } else {
  109. $mform->addElement('static', 'info', get_string('no_templates_available_yet', 'feedback'));
  110. }
  111. }
  112. }
  113. class feedback_edit_create_template_form extends moodleform {
  114. private $feedbackdata;
  115. public function definition() {
  116. }
  117. public function data_preprocessing(&$default_values) {
  118. $default_values['templatename'] = '';
  119. }
  120. public function set_feedbackdata($data) {
  121. if (is_array($data)) {
  122. if (!isset($this->feedbackdata)) {
  123. $this->feedbackdata = new stdClass();
  124. }
  125. foreach ($data as $key => $val) {
  126. $this->feedbackdata->{$key} = $val;
  127. }
  128. }
  129. }
  130. public function set_form_elements() {
  131. $mform =& $this->_form;
  132. // hidden elements
  133. $mform->addElement('hidden', 'id');
  134. $mform->setType('id', PARAM_INT);
  135. $mform->addElement('hidden', 'do_show');
  136. $mform->setType('do_show', PARAM_INT);
  137. $mform->addElement('hidden', 'savetemplate', 1);
  138. $mform->setType('savetemplate', PARAM_INT);
  139. //headline
  140. $mform->addElement('header', 'creating_templates', get_string('creating_templates', 'feedback'));
  141. // visible elements
  142. $elementgroup = array();
  143. $elementgroup[] = $mform->createElement('static',
  144. 'templatenamelabel',
  145. get_string('name', 'feedback'));
  146. $elementgroup[] = $mform->createElement('text',
  147. 'templatename',
  148. get_string('name', 'feedback'),
  149. array('size'=>'40', 'maxlength'=>'200'));
  150. if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) {
  151. $elementgroup[] = $mform->createElement('checkbox',
  152. 'ispublic',
  153. get_string('public', 'feedback'),
  154. get_string('public', 'feedback'));
  155. }
  156. // buttons
  157. $elementgroup[] = $mform->createElement('submit',
  158. 'create_template',
  159. get_string('save_as_new_template', 'feedback'));
  160. $mform->addGroup($elementgroup,
  161. 'elementgroup',
  162. get_string('name', 'feedback'),
  163. array(' '),
  164. false);
  165. $mform->setType('templatename', PARAM_TEXT);
  166. }
  167. }