PageRenderTime 69ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/tool/generator/classes/make_course_form.php

https://github.com/dongsheng/moodle
PHP | 85 lines | 30 code | 13 blank | 42 comment | 3 complexity | 7b185d0c479684681460c4c3e62d079e MD5 | raw file
Possible License(s): BSD-3-Clause, MIT, GPL-3.0, Apache-2.0, LGPL-2.1
  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. * Course form.
  18. *
  19. * @package tool_generator
  20. * @copyright 2013 The Open University
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. require_once($CFG->libdir . '/formslib.php');
  25. /**
  26. * Form with options for creating large course.
  27. *
  28. * @package tool_generator
  29. * @copyright 2013 The Open University
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31. */
  32. class tool_generator_make_course_form extends moodleform {
  33. /**
  34. * Course generation tool form definition.
  35. *
  36. * @return void
  37. */
  38. public function definition() {
  39. $mform = $this->_form;
  40. $mform->addElement('select', 'size', get_string('size', 'tool_generator'),
  41. tool_generator_course_backend::get_size_choices());
  42. $mform->setDefault('size', tool_generator_course_backend::DEFAULT_SIZE);
  43. $mform->addElement('text', 'shortname', get_string('shortnamecourse'));
  44. $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
  45. $mform->setType('shortname', PARAM_TEXT);
  46. $mform->addElement('text', 'fullname', get_string('fullnamecourse'));
  47. $mform->setType('fullname', PARAM_TEXT);
  48. $mform->addElement('editor', 'summary', get_string('coursesummary'));
  49. $mform->setType('summary', PARAM_RAW);
  50. $mform->addElement('submit', 'submit', get_string('createcourse', 'tool_generator'));
  51. }
  52. /**
  53. * Form validation.
  54. *
  55. * @param array $data
  56. * @param array $files
  57. * @return void
  58. */
  59. public function validation($data, $files) {
  60. global $DB;
  61. $errors = array();
  62. // Check course doesn't already exist.
  63. if (!empty($data['shortname'])) {
  64. // Check shortname.
  65. $error = tool_generator_course_backend::check_shortname_available($data['shortname']);
  66. if ($error) {
  67. $errors['shortname'] = $error;
  68. }
  69. }
  70. return $errors;
  71. }
  72. }