示例#1
0
 /**
  * Return the launch data for a given external tool.
  *
  * @param int $toolid the external tool instance id
  * @return array of warnings and launch data
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function get_tool_launch_data($toolid)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/lti/lib.php';
     $params = self::validate_parameters(self::get_tool_launch_data_parameters(), array('toolid' => $toolid));
     $warnings = array();
     // Request and permission validation.
     $lti = $DB->get_record('lti', array('id' => $params['toolid']), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($lti, 'lti');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/lti:view', $context);
     $lti->cmid = $cm->id;
     list($endpoint, $parms) = lti_get_launch_data($lti);
     $parameters = array();
     foreach ($parms as $name => $value) {
         $parameters[] = array('name' => $name, 'value' => $value);
     }
     $result = array();
     $result['endpoint'] = $endpoint;
     $result['parameters'] = $parameters;
     $result['warnings'] = $warnings;
     return $result;
 }
示例#2
0
/**
 * Launch an external tool activity.
 *
 * @param  stdClass $instance the external tool activity settings
 * @return string The HTML code containing the javascript code for the launch
 */
function lti_launch_tool($instance)
{
    list($endpoint, $parms) = lti_get_launch_data($instance);
    $debuglaunch = $instance->debuglaunch == 1;
    $content = lti_post_launch_html($parms, $endpoint, $debuglaunch);
    echo $content;
}