PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/quiz/addrandomform.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 94 lines | 41 code | 22 blank | 31 comment | 4 complexity | 7961d793969123e86d76e00152044b7a 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. * Defines the Moodle forum used to add random questions to the quiz.
  18. *
  19. * @package mod
  20. * @subpackage quiz
  21. * @copyright 2008 Olli Savolainen
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once($CFG->libdir.'/formslib.php');
  26. /**
  27. * The add random questions form.
  28. *
  29. * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31. */
  32. class quiz_add_random_form extends moodleform {
  33. protected function definition() {
  34. global $CFG, $DB;
  35. $mform =& $this->_form;
  36. $contexts = $this->_customdata;
  37. $usablecontexts = $contexts->having_cap('moodle/question:useall');
  38. // Random from existing category section.
  39. $mform->addElement('header', 'categoryheader',
  40. get_string('randomfromexistingcategory', 'quiz'));
  41. $mform->addElement('questioncategory', 'category', get_string('category'),
  42. array('contexts' => $usablecontexts, 'top' => false));
  43. $mform->addElement('checkbox', 'includesubcategories', '', get_string('recurse', 'quiz'));
  44. $mform->addElement('submit', 'existingcategory', get_string('addrandomquestion', 'quiz'));
  45. // Random from a new category section.
  46. $mform->addElement('header', 'categoryheader',
  47. get_string('randomquestionusinganewcategory', 'quiz'));
  48. $mform->addElement('text', 'name', get_string('name'), 'maxlength="254" size="50"');
  49. $mform->setType('name', PARAM_TEXT);
  50. $mform->addElement('questioncategory', 'parent', get_string('parentcategory', 'question'),
  51. array('contexts' => $usablecontexts, 'top' => true));
  52. $mform->addHelpButton('parent', 'parentcategory', 'question');
  53. $mform->addElement('submit', 'newcategory',
  54. get_string('createcategoryandaddrandomquestion', 'quiz'));
  55. // Submit buttons.
  56. $mform->addElement('cancel');
  57. $mform->closeHeaderBefore('cancel');
  58. $mform->addElement('hidden', 'addonpage', 0, 'id="rform_qpage"');
  59. $mform->setType('addonpage', PARAM_SEQUENCE);
  60. $mform->addElement('hidden', 'cmid', 0);
  61. $mform->setType('cmid', PARAM_INT);
  62. $mform->addElement('hidden', 'returnurl', 0);
  63. $mform->setType('returnurl', PARAM_LOCALURL);
  64. }
  65. public function validation($fromform, $files) {
  66. $errors = parent::validation($fromform, $files);
  67. if (!empty($fromform['newcategory']) && trim($fromform['name']) == '') {
  68. $errors['name'] = get_string('categorynamecantbeblank', 'question');
  69. }
  70. return $errors;
  71. }
  72. }