PageRenderTime 66ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/lti/mod_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 265 lines | 135 code | 42 blank | 88 comment | 9 complexity | 559ae3ccf5c13af39f29bd27cf0755be 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. // This file is part of BasicLTI4Moodle
  18. //
  19. // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)
  20. // consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web
  21. // based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI
  22. // specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS
  23. // are already supporting or going to support BasicLTI. This project Implements the consumer
  24. // for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.
  25. // BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem
  26. // at the GESSI research group at UPC.
  27. // SimpleLTI consumer for Moodle is an implementation of the early specification of LTI
  28. // by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a
  29. // Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.
  30. //
  31. // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis
  32. // of the Universitat Politecnica de Catalunya http://www.upc.edu
  33. // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu
  34. /**
  35. * This file defines the main lti configuration form
  36. *
  37. * @package mod
  38. * @subpackage lti
  39. * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
  40. * marc.alier@upc.edu
  41. * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
  42. * @author Marc Alier
  43. * @author Jordi Piguillem
  44. * @author Nikolas Galanis
  45. * @author Chris Scribner
  46. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  47. */
  48. defined('MOODLE_INTERNAL') || die;
  49. require_once($CFG->dirroot.'/course/moodleform_mod.php');
  50. require_once($CFG->dirroot.'/mod/lti/locallib.php');
  51. class mod_lti_mod_form extends moodleform_mod {
  52. public function definition() {
  53. global $DB, $PAGE, $OUTPUT, $USER, $COURSE;
  54. if ($type = optional_param('type', false, PARAM_ALPHA)) {
  55. component_callback("ltisource_$type", 'add_instance_hook');
  56. }
  57. $this->typeid = 0;
  58. $mform =& $this->_form;
  59. //-------------------------------------------------------------------------------
  60. // Adding the "general" fieldset, where all the common settings are shown
  61. $mform->addElement('header', 'general', get_string('general', 'form'));
  62. // Adding the standard "name" field
  63. $mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size'=>'64'));
  64. $mform->setType('name', PARAM_TEXT);
  65. $mform->addRule('name', null, 'required', null, 'client');
  66. $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  67. // Adding the optional "intro" and "introformat" pair of fields
  68. $this->add_intro_editor(false, get_string('basicltiintro', 'lti'));
  69. $mform->setAdvanced('introeditor');
  70. // Display the label to the right of the checkbox so it looks better & matches rest of the form
  71. $coursedesc = $mform->getElement('showdescription');
  72. if(!empty($coursedesc)){
  73. $coursedesc->setText(' ' . $coursedesc->getLabel());
  74. $coursedesc->setLabel('&nbsp');
  75. }
  76. $mform->setAdvanced('showdescription');
  77. $mform->addElement('checkbox', 'showtitlelaunch', '&nbsp;', ' ' . get_string('display_name', 'lti'));
  78. $mform->setAdvanced('showtitlelaunch');
  79. $mform->setDefault('showtitlelaunch', true);
  80. $mform->addHelpButton('showtitlelaunch', 'display_name', 'lti');
  81. $mform->addElement('checkbox', 'showdescriptionlaunch', '&nbsp;', ' ' . get_string('display_description', 'lti'));
  82. $mform->setAdvanced('showdescriptionlaunch');
  83. $mform->addHelpButton('showdescriptionlaunch', 'display_description', 'lti');
  84. // Tool settings
  85. $tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array());
  86. $mform->addHelpButton('typeid', 'external_tool_type', 'lti');
  87. foreach (lti_get_types_for_add_instance() as $id => $type) {
  88. if ($type->course == $COURSE->id) {
  89. $attributes = array( 'editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain );
  90. } else if ($id != 0) {
  91. $attributes = array( 'globalTool' => 1, 'domain' => $type->tooldomain);
  92. } else {
  93. $attributes = array();
  94. }
  95. $tooltypes->addOption($type->name, $id, $attributes);
  96. }
  97. $mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size'=>'64'));
  98. $mform->setType('toolurl', PARAM_TEXT);
  99. $mform->addHelpButton('toolurl', 'launch_url', 'lti');
  100. $mform->addElement('text', 'securetoolurl', get_string('secure_launch_url', 'lti'), array('size'=>'64'));
  101. $mform->setType('securetoolurl', PARAM_TEXT);
  102. $mform->setAdvanced('securetoolurl');
  103. $mform->addHelpButton('securetoolurl', 'secure_launch_url', 'lti');
  104. $mform->addElement('hidden', 'urlmatchedtypeid', '', array( 'id' => 'id_urlmatchedtypeid' ));
  105. $mform->setType('urlmatchedtypeid', PARAM_INT);
  106. $launchoptions=array();
  107. $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti');
  108. $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
  109. $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
  110. $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
  111. $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions);
  112. $mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT);
  113. $mform->addHelpButton('launchcontainer', 'launchinpopup', 'lti');
  114. $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti'));
  115. $mform->setType('resourcekey', PARAM_TEXT);
  116. $mform->setAdvanced('resourcekey');
  117. $mform->addHelpButton('resourcekey', 'resourcekey', 'lti');
  118. $mform->addElement('passwordunmask', 'password', get_string('password', 'lti'));
  119. $mform->setType('password', PARAM_TEXT);
  120. $mform->setAdvanced('password');
  121. $mform->addHelpButton('password', 'password', 'lti');
  122. $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows'=>4, 'cols'=>60));
  123. $mform->setType('instructorcustomparameters', PARAM_TEXT);
  124. $mform->setAdvanced('instructorcustomparameters');
  125. $mform->addHelpButton('instructorcustomparameters', 'custom', 'lti');
  126. $mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size'=>'64'));
  127. $mform->setType('icon', PARAM_TEXT);
  128. $mform->setAdvanced('icon');
  129. $mform->addHelpButton('icon', 'icon_url', 'lti');
  130. $mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size'=>'64'));
  131. $mform->setType('secureicon', PARAM_TEXT);
  132. $mform->setAdvanced('secureicon');
  133. $mform->addHelpButton('secureicon', 'secure_icon_url', 'lti');
  134. //-------------------------------------------------------------------------------
  135. // Add privacy preferences fieldset where users choose whether to send their data
  136. $mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
  137. $mform->addElement('advcheckbox', 'instructorchoicesendname', '&nbsp;', ' ' . get_string('share_name', 'lti'));
  138. $mform->setDefault('instructorchoicesendname', '1');
  139. $mform->addHelpButton('instructorchoicesendname', 'share_name', 'lti');
  140. $mform->addElement('advcheckbox', 'instructorchoicesendemailaddr', '&nbsp;', ' ' . get_string('share_email', 'lti'));
  141. $mform->setDefault('instructorchoicesendemailaddr', '1');
  142. $mform->addHelpButton('instructorchoicesendemailaddr', 'share_email', 'lti');
  143. $mform->addElement('advcheckbox', 'instructorchoiceacceptgrades', '&nbsp;', ' ' . get_string('accept_grades', 'lti'));
  144. $mform->setDefault('instructorchoiceacceptgrades', '1');
  145. $mform->addHelpButton('instructorchoiceacceptgrades', 'accept_grades', 'lti');
  146. //$mform->addElement('checkbox', 'instructorchoiceallowroster', '&nbsp;', ' ' . get_string('share_roster', 'lti'));
  147. //$mform->setDefault('instructorchoiceallowroster', '1');
  148. //$mform->addHelpButton('instructorchoiceallowroster', 'share_roster', 'lti');
  149. //-------------------------------------------------------------------------------
  150. /**
  151. $debugoptions=array();
  152. $debugoptions[0] = get_string('debuglaunchoff', 'lti');
  153. $debugoptions[1] = get_string('debuglaunchon', 'lti');
  154. $mform->addElement('select', 'debuglaunch', get_string('debuglaunch', 'lti'), $debugoptions);
  155. if (isset($this->typeconfig['debuglaunch'])) {
  156. if ($this->typeconfig['debuglaunch'] == 0) {
  157. $mform->setDefault('debuglaunch', '0');
  158. } else if ($this->typeconfig['debuglaunch'] == 1) {
  159. $mform->setDefault('debuglaunch', '1');
  160. }
  161. }
  162. */
  163. //-------------------------------------------------------------------------------
  164. // add standard elements, common to all modules
  165. $this->standard_coursemodule_elements();
  166. $mform->setAdvanced('cmidnumber');
  167. //-------------------------------------------------------------------------------
  168. // add standard buttons, common to all modules
  169. $this->add_action_buttons();
  170. $editurl = new moodle_url('/mod/lti/instructor_edit_tool_type.php',
  171. array('sesskey' => sesskey(), 'course' => $COURSE->id));
  172. $ajaxurl = new moodle_url('/mod/lti/ajax.php');
  173. $jsinfo = (object)array(
  174. 'edit_icon_url' => (string)$OUTPUT->pix_url('t/edit'),
  175. 'add_icon_url' => (string)$OUTPUT->pix_url('t/add'),
  176. 'delete_icon_url' => (string)$OUTPUT->pix_url('t/delete'),
  177. 'green_check_icon_url' => (string)$OUTPUT->pix_url('i/valid'),
  178. 'warning_icon_url' => (string)$OUTPUT->pix_url('warning', 'lti'),
  179. 'instructor_tool_type_edit_url' => $editurl->out(false),
  180. 'ajax_url' => $ajaxurl->out(true),
  181. 'courseId' => $COURSE->id
  182. );
  183. $module = array(
  184. 'name' => 'mod_lti_edit',
  185. 'fullpath' => '/mod/lti/mod_form.js',
  186. 'requires' => array('base', 'io', 'querystring-stringify-simple', 'node', 'event', 'json-parse'),
  187. 'strings' => array(
  188. array('addtype', 'lti'),
  189. array('edittype', 'lti'),
  190. array('deletetype', 'lti'),
  191. array('delete_confirmation', 'lti'),
  192. array('cannot_edit', 'lti'),
  193. array('cannot_delete', 'lti'),
  194. array('global_tool_types', 'lti'),
  195. array('course_tool_types', 'lti'),
  196. array('using_tool_configuration', 'lti'),
  197. array('domain_mismatch', 'lti'),
  198. array('custom_config', 'lti'),
  199. array('tool_config_not_found', 'lti'),
  200. array('forced_help', 'lti')
  201. ),
  202. );
  203. $PAGE->requires->js_init_call('M.mod_lti.editor.init', array(json_encode($jsinfo)), true, $module);
  204. }
  205. /**
  206. * Make fields editable or non-editable depending on the administrator choices
  207. * @see moodleform_mod::definition_after_data()
  208. */
  209. public function definition_after_data() {
  210. parent::definition_after_data();
  211. //$mform =& $this->_form;
  212. }
  213. /**
  214. * Function overwritten to change default values using
  215. * global configuration
  216. *
  217. * @param array $default_values passed by reference
  218. */
  219. public function data_preprocessing(&$default_values) {
  220. }
  221. }