PageRenderTime 88ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/lti/register_form.php

https://bitbucket.org/moodle/moodle
PHP | 118 lines | 53 code | 24 blank | 41 comment | 1 complexity | a52a3ca51de4c63ac1f5ee7bf62a69a3 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-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. * This file defines the main tool registration configuration form
  18. *
  19. * @package mod_lti
  20. * @copyright 2014 Vital Source Technologies http://vitalsource.com
  21. * @author Stephen Vickers
  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. require_once($CFG->dirroot.'/mod/lti/locallib.php');
  27. /**
  28. * The mod_lti_register_types_form class.
  29. *
  30. * @package mod_lti
  31. * @since Moodle 2.8
  32. * @copyright 2014 Vital Source Technologies http://vitalsource.com
  33. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34. */
  35. class mod_lti_register_types_form extends moodleform {
  36. /**
  37. * Set up the form definition.
  38. */
  39. public function definition() {
  40. global $CFG;
  41. $mform =& $this->_form;
  42. $mform->addElement('header', 'setup', get_string('registration_options', 'lti'));
  43. // Tool Provider name.
  44. $strrequired = get_string('required');
  45. $mform->addElement('text', 'lti_registrationname', get_string('registrationname', 'lti'));
  46. $mform->setType('lti_registrationname', PARAM_TEXT);
  47. $mform->addHelpButton('lti_registrationname', 'registrationname', 'lti');
  48. $mform->addRule('lti_registrationname', $strrequired, 'required', null, 'client');
  49. // Registration URL.
  50. $mform->addElement('text', 'lti_registrationurl', get_string('registrationurl', 'lti'), array('size' => '64'));
  51. $mform->setType('lti_registrationurl', PARAM_URL);
  52. $mform->addHelpButton('lti_registrationurl', 'registrationurl', 'lti');
  53. $mform->addRule('lti_registrationurl', $strrequired, 'required', null, 'client');
  54. // LTI Capabilities.
  55. $options = array_keys(lti_get_capabilities());
  56. natcasesort($options);
  57. $attributes = array( 'multiple' => 1, 'size' => min(count($options), 10) );
  58. $mform->addElement('select', 'lti_capabilities', get_string('capabilities', 'lti'),
  59. array_combine($options, $options), $attributes);
  60. $mform->setType('lti_capabilities', PARAM_TEXT);
  61. $mform->addHelpButton('lti_capabilities', 'capabilities', 'lti');
  62. $mform->addRule('lti_capabilities', $strrequired, 'required', null, 'client');
  63. // LTI Services.
  64. $services = lti_get_services();
  65. $options = array();
  66. foreach ($services as $service) {
  67. $options[$service->get_id()] = $service->get_name();
  68. }
  69. $attributes = array( 'multiple' => 1, 'size' => min(count($options), 10) );
  70. $mform->addElement('select', 'lti_services', get_string('services', 'lti'), $options, $attributes);
  71. $mform->setType('lti_services', PARAM_TEXT);
  72. $mform->addHelpButton('lti_services', 'services', 'lti');
  73. $mform->addRule('lti_services', $strrequired, 'required', null, 'client');
  74. $mform->addElement('hidden', 'toolproxyid');
  75. $mform->setType('toolproxyid', PARAM_INT);
  76. $tab = optional_param('tab', '', PARAM_ALPHAEXT);
  77. $mform->addElement('hidden', 'tab', $tab);
  78. $mform->setType('tab', PARAM_ALPHAEXT);
  79. $courseid = optional_param('course', 1, PARAM_INT);
  80. $mform->addElement('hidden', 'course', $courseid);
  81. $mform->setType('course', PARAM_INT);
  82. // Add standard buttons, common to all modules.
  83. $this->add_action_buttons();
  84. }
  85. /**
  86. * Set up rules for disabling fields.
  87. */
  88. public function disable_fields() {
  89. $mform =& $this->_form;
  90. $mform->disabledIf('lti_registrationurl', null);
  91. $mform->disabledIf('lti_capabilities', null);
  92. $mform->disabledIf('lti_services', null);
  93. }
  94. }