[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/lti/ -> mod_form.php (source)

   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  /**
  36   * This file defines the main lti configuration form
  37   *
  38   * @package mod_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  
  49  defined('MOODLE_INTERNAL') || die;
  50  
  51  require_once($CFG->dirroot.'/course/moodleform_mod.php');
  52  require_once($CFG->dirroot.'/mod/lti/locallib.php');
  53  
  54  class mod_lti_mod_form extends moodleform_mod {
  55  
  56      public function definition() {
  57          global $DB, $PAGE, $OUTPUT, $USER, $COURSE;
  58  
  59          if ($type = optional_param('type', false, PARAM_ALPHA)) {
  60              component_callback("ltisource_$type", 'add_instance_hook');
  61          }
  62  
  63          $this->typeid = 0;
  64  
  65          $mform =& $this->_form;
  66          // Adding the "general" fieldset, where all the common settings are shown.
  67          $mform->addElement('header', 'general', get_string('general', 'form'));
  68          // Adding the standard "name" field.
  69          $mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size' => '64'));
  70          $mform->setType('name', PARAM_TEXT);
  71          $mform->addRule('name', null, 'required', null, 'client');
  72          $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  73          // Adding the optional "intro" and "introformat" pair of fields.
  74          $this->standard_intro_elements(get_string('basicltiintro', 'lti'));
  75          $mform->setAdvanced('introeditor');
  76  
  77          // Display the label to the right of the checkbox so it looks better & matches rest of the form.
  78          if ($mform->elementExists('showdescription')) {
  79              $coursedesc = $mform->getElement('showdescription');
  80              if (!empty($coursedesc)) {
  81                  $coursedesc->setText(' ' . $coursedesc->getLabel());
  82                  $coursedesc->setLabel('&nbsp');
  83              }
  84          }
  85  
  86          $mform->setAdvanced('showdescription');
  87  
  88          $mform->addElement('checkbox', 'showtitlelaunch', '&nbsp;', ' ' . get_string('display_name', 'lti'));
  89          $mform->setAdvanced('showtitlelaunch');
  90          $mform->setDefault('showtitlelaunch', true);
  91          $mform->addHelpButton('showtitlelaunch', 'display_name', 'lti');
  92  
  93          $mform->addElement('checkbox', 'showdescriptionlaunch', '&nbsp;', ' ' . get_string('display_description', 'lti'));
  94          $mform->setAdvanced('showdescriptionlaunch');
  95          $mform->addHelpButton('showdescriptionlaunch', 'display_description', 'lti');
  96  
  97          // Tool settings.
  98          $tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array());
  99          $typeid = optional_param('typeid', false, PARAM_INT);
 100          $mform->getElement('typeid')->setValue($typeid);
 101          $mform->addHelpButton('typeid', 'external_tool_type', 'lti');
 102          $toolproxy = array();
 103  
 104          foreach (lti_get_types_for_add_instance() as $id => $type) {
 105              if (!empty($type->toolproxyid)) {
 106                  $toolproxy[] = $type->id;
 107                  $attributes = array( 'globalTool' => 1, 'toolproxy' => 1);
 108                  $enabledcapabilities = explode("\n", $type->enabledcapability);
 109                  if (!in_array('Result.autocreate', $enabledcapabilities)) {
 110                      $attributes['nogrades'] = 1;
 111                  }
 112                  if (!in_array('Person.name.full', $enabledcapabilities) && !in_array('Person.name.family', $enabledcapabilities) &&
 113                      !in_array('Person.name.given', $enabledcapabilities)) {
 114                      $attributes['noname'] = 1;
 115                  }
 116                  if (!in_array('Person.email.primary', $enabledcapabilities)) {
 117                      $attributes['noemail'] = 1;
 118                  }
 119              } else if ($type->course == $COURSE->id) {
 120                  $attributes = array( 'editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain );
 121              } else if ($id != 0) {
 122                  $attributes = array( 'globalTool' => 1, 'domain' => $type->tooldomain);
 123              } else {
 124                  $attributes = array();
 125              }
 126  
 127              $tooltypes->addOption($type->name, $id, $attributes);
 128          }
 129  
 130          $mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size' => '64'));
 131          $mform->setType('toolurl', PARAM_URL);
 132          $mform->addHelpButton('toolurl', 'launch_url', 'lti');
 133          $mform->disabledIf('toolurl', 'typeid', 'neq', '0');
 134  
 135          $mform->addElement('text', 'securetoolurl', get_string('secure_launch_url', 'lti'), array('size' => '64'));
 136          $mform->setType('securetoolurl', PARAM_URL);
 137          $mform->setAdvanced('securetoolurl');
 138          $mform->addHelpButton('securetoolurl', 'secure_launch_url', 'lti');
 139          $mform->disabledIf('securetoolurl', 'typeid', 'neq', '0');
 140  
 141          $mform->addElement('hidden', 'urlmatchedtypeid', '', array( 'id' => 'id_urlmatchedtypeid' ));
 142          $mform->setType('urlmatchedtypeid', PARAM_INT);
 143  
 144          $launchoptions = array();
 145          $launchoptions[LTI_LAUNCH_CONTAINER_DEFAULT] = get_string('default', 'lti');
 146          $launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
 147          $launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
 148          $launchoptions[LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW] = get_string('existing_window', 'lti');
 149          $launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
 150  
 151          $mform->addElement('select', 'launchcontainer', get_string('launchinpopup', 'lti'), $launchoptions);
 152          $mform->setDefault('launchcontainer', LTI_LAUNCH_CONTAINER_DEFAULT);
 153          $mform->addHelpButton('launchcontainer', 'launchinpopup', 'lti');
 154          $mform->setAdvanced('launchcontainer');
 155  
 156          $mform->addElement('text', 'resourcekey', get_string('resourcekey', 'lti'));
 157          $mform->setType('resourcekey', PARAM_TEXT);
 158          $mform->setAdvanced('resourcekey');
 159          $mform->addHelpButton('resourcekey', 'resourcekey', 'lti');
 160          $mform->disabledIf('resourcekey', 'typeid', 'neq', '0');
 161  
 162          $mform->addElement('passwordunmask', 'password', get_string('password', 'lti'));
 163          $mform->setType('password', PARAM_TEXT);
 164          $mform->setAdvanced('password');
 165          $mform->addHelpButton('password', 'password', 'lti');
 166          $mform->disabledIf('password', 'typeid', 'neq', '0');
 167  
 168          $mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows' => 4, 'cols' => 60));
 169          $mform->setType('instructorcustomparameters', PARAM_TEXT);
 170          $mform->setAdvanced('instructorcustomparameters');
 171          $mform->addHelpButton('instructorcustomparameters', 'custom', 'lti');
 172  
 173          $mform->addElement('text', 'icon', get_string('icon_url', 'lti'), array('size' => '64'));
 174          $mform->setType('icon', PARAM_URL);
 175          $mform->setAdvanced('icon');
 176          $mform->addHelpButton('icon', 'icon_url', 'lti');
 177          $mform->disabledIf('icon', 'typeid', 'neq', '0');
 178  
 179          $mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size' => '64'));
 180          $mform->setType('secureicon', PARAM_URL);
 181          $mform->setAdvanced('secureicon');
 182          $mform->addHelpButton('secureicon', 'secure_icon_url', 'lti');
 183          $mform->disabledIf('secureicon', 'typeid', 'neq', '0');
 184  
 185          // Add privacy preferences fieldset where users choose whether to send their data.
 186          $mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
 187  
 188          $mform->addElement('advcheckbox', 'instructorchoicesendname', '&nbsp;', ' ' . get_string('share_name', 'lti'));
 189          $mform->setDefault('instructorchoicesendname', '1');
 190          $mform->addHelpButton('instructorchoicesendname', 'share_name', 'lti');
 191          $mform->disabledIf('instructorchoicesendname', 'typeid', 'in', $toolproxy);
 192  
 193          $mform->addElement('advcheckbox', 'instructorchoicesendemailaddr', '&nbsp;', ' ' . get_string('share_email', 'lti'));
 194          $mform->setDefault('instructorchoicesendemailaddr', '1');
 195          $mform->addHelpButton('instructorchoicesendemailaddr', 'share_email', 'lti');
 196          $mform->disabledIf('instructorchoicesendemailaddr', 'typeid', 'in', $toolproxy);
 197  
 198          $mform->addElement('advcheckbox', 'instructorchoiceacceptgrades', '&nbsp;', ' ' . get_string('accept_grades', 'lti'));
 199          $mform->setDefault('instructorchoiceacceptgrades', '1');
 200          $mform->addHelpButton('instructorchoiceacceptgrades', 'accept_grades', 'lti');
 201          $mform->disabledIf('instructorchoiceacceptgrades', 'typeid', 'in', $toolproxy);
 202  
 203          // Add standard course module grading elements.
 204          $this->standard_grading_coursemodule_elements();
 205  
 206          // Add standard elements, common to all modules.
 207          $this->standard_coursemodule_elements();
 208          $mform->setAdvanced('cmidnumber');
 209  
 210          // Add standard buttons, common to all modules.
 211          $this->add_action_buttons();
 212  
 213          $editurl = new moodle_url('/mod/lti/instructor_edit_tool_type.php',
 214                  array('sesskey' => sesskey(), 'course' => $COURSE->id));
 215          $ajaxurl = new moodle_url('/mod/lti/ajax.php');
 216  
 217          $jsinfo = (object)array(
 218                          'edit_icon_url' => (string)$OUTPUT->pix_url('t/edit'),
 219                          'add_icon_url' => (string)$OUTPUT->pix_url('t/add'),
 220                          'delete_icon_url' => (string)$OUTPUT->pix_url('t/delete'),
 221                          'green_check_icon_url' => (string)$OUTPUT->pix_url('i/valid'),
 222                          'warning_icon_url' => (string)$OUTPUT->pix_url('warning', 'lti'),
 223                          'instructor_tool_type_edit_url' => $editurl->out(false),
 224                          'ajax_url' => $ajaxurl->out(true),
 225                          'courseId' => $COURSE->id
 226                    );
 227  
 228          $module = array(
 229              'name' => 'mod_lti_edit',
 230              'fullpath' => '/mod/lti/mod_form.js',
 231              'requires' => array('base', 'io', 'querystring-stringify-simple', 'node', 'event', 'json-parse'),
 232              'strings' => array(
 233                  array('addtype', 'lti'),
 234                  array('edittype', 'lti'),
 235                  array('deletetype', 'lti'),
 236                  array('delete_confirmation', 'lti'),
 237                  array('cannot_edit', 'lti'),
 238                  array('cannot_delete', 'lti'),
 239                  array('global_tool_types', 'lti'),
 240                  array('course_tool_types', 'lti'),
 241                  array('using_tool_configuration', 'lti'),
 242                  array('using_tool_cartridge', 'lti'),
 243                  array('domain_mismatch', 'lti'),
 244                  array('custom_config', 'lti'),
 245                  array('tool_config_not_found', 'lti'),
 246                  array('tooltypeadded', 'lti'),
 247                  array('tooltypedeleted', 'lti'),
 248                  array('tooltypenotdeleted', 'lti'),
 249                  array('tooltypeupdated', 'lti'),
 250                  array('forced_help', 'lti')
 251              ),
 252          );
 253  
 254          if (!empty($typeid)) {
 255              $mform->setAdvanced('typeid');
 256              $mform->setAdvanced('toolurl');
 257          }
 258  
 259          $PAGE->requires->js_init_call('M.mod_lti.editor.init', array(json_encode($jsinfo)), true, $module);
 260      }
 261  
 262  }
 263  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1