/** * Execute the request for this resource. * * @param mod_lti\local\ltiservice\response $response Response object for this request. */ public function execute($response) { $params = $this->parse_template(); $contexttype = $params['context_type']; $contextid = $params['context_id']; $vendorcode = $params['vendor_code']; $productcode = $params['product_code']; $bubble = optional_param('bubble', '', PARAM_ALPHA); $ok = !empty($contexttype) && !empty($contextid) && !empty($vendorcode) && !empty($productcode) && $this->check_tool_proxy($productcode, $response->get_request_data()); if (!$ok) { $response->set_code(401); } $contenttype = $response->get_accept(); $simpleformat = !empty($contenttype) && $contenttype == $this->formats[1]; if ($ok) { $ok = (empty($bubble) || ($bubble == 'distinct' || $bubble == 'all')) && (!$simpleformat || empty($bubble) || $bubble != 'all') && (empty($bubble) || $response->get_request_method() == 'GET'); } if (!$ok) { $response->set_code(404); } else { $systemsetting = null; $contextsettings = lti_get_tool_settings($this->get_service()->get_tool_proxy()->id, $contextid); if (!empty($bubble)) { $systemsetting = new systemsettings($this->get_service()); $systemsetting->params['tool_proxy_id'] = $productcode; $systemsettings = lti_get_tool_settings($this->get_service()->get_tool_proxy()->id); if ($bubble == 'distinct') { toolsettings::distinct_settings($systemsettings, $contextsettings, null); } } else { $systemsettings = null; } if ($response->get_request_method() == 'GET') { $json = ''; if ($simpleformat) { $response->set_content_type($this->formats[1]); $json .= "{"; } else { $response->set_content_type($this->formats[0]); $json .= "{\n \"@context\":\"http://purl.imsglobal.org/ctx/lti/v2/ToolSettings\",\n \"@graph\":[\n"; } $settings = toolsettings::settings_to_json($systemsettings, $simpleformat, 'ToolProxy', $systemsetting); $json .= $settings; $isfirst = strlen($settings) <= 0; $settings = toolsettings::settings_to_json($contextsettings, $simpleformat, 'ToolProxyBinding', $this); if (strlen($settings) > 0 && !$isfirst) { $json .= ","; } $json .= $settings; if ($simpleformat) { $json .= "\n}"; } else { $json .= "\n ]\n}"; } $response->set_body($json); } else { // PUT. $settings = null; if ($response->get_content_type() == $this->formats[0]) { $json = json_decode($response->get_request_data()); $ok = !empty($json); if ($ok) { $ok = isset($json->{"@graph"}) && is_array($json->{"@graph"}) && count($json->{"@graph"}) == 1 && $json->{"@graph"}[0]->{"@type"} == 'ToolProxyBinding'; } if ($ok) { $settings = $json->{"@graph"}[0]->custom; } } else { // Simple JSON. $json = json_decode($response->get_request_data(), true); $ok = !empty($json); if ($ok) { $ok = is_array($json); } if ($ok) { $settings = $json; } } if ($ok) { lti_set_tool_settings($settings, $this->get_service()->get_tool_proxy()->id, $contextid); } else { $response->set_code(406); } } } }
/** * This function builds the custom parameters * * @param object $toolproxy Tool proxy instance object * @param object $tool Tool instance object * @param object $instance Tool placement instance object * @param array $params LTI launch parameters * @param string $customstr Custom parameters defined for tool * @param string $instructorcustomstr Custom parameters defined for this placement * @param boolean $islti2 True if an LTI 2 tool is being launched * * @return array Custom parameters */ function lti_build_custom_parameters($toolproxy, $tool, $instance, $params, $customstr, $instructorcustomstr, $islti2) { // Concatenate the custom parameters from the administrator and the instructor // Instructor parameters are only taken into consideration if the administrator // has given permission. $custom = array(); if ($customstr) { $custom = lti_split_custom_parameters($toolproxy, $tool, $params, $customstr, $islti2); } if (!isset($typeconfig['allowinstructorcustom']) || $typeconfig['allowinstructorcustom'] != LTI_SETTING_NEVER) { if ($instructorcustomstr) { $custom = array_merge(lti_split_custom_parameters($toolproxy, $tool, $params, $instructorcustomstr, $islti2), $custom); } } if ($islti2) { $custom = array_merge(lti_split_custom_parameters($toolproxy, $tool, $params, $tool->parameter, true), $custom); $settings = lti_get_tool_settings($tool->toolproxyid); $custom = array_merge($custom, lti_get_custom_parameters($toolproxy, $tool, $params, $settings)); $settings = lti_get_tool_settings($tool->toolproxyid, $instance->course); $custom = array_merge($custom, lti_get_custom_parameters($toolproxy, $tool, $params, $settings)); $settings = lti_get_tool_settings($tool->toolproxyid, $instance->course, $instance->id); $custom = array_merge($custom, lti_get_custom_parameters($toolproxy, $tool, $params, $settings)); } return $custom; }
/** * Execute the request for this resource. * * @param mod_lti\local\ltiservice\response $response Response object for this request. */ public function execute($response) { global $DB, $COURSE; $params = $this->parse_template(); $linkid = $params['link_id']; $bubble = optional_param('bubble', '', PARAM_ALPHA); $contenttype = $response->get_accept(); $simpleformat = !empty($contenttype) && $contenttype == $this->formats[1]; $ok = (empty($bubble) || ($bubble == 'distinct' || $bubble == 'all')) && (!$simpleformat || empty($bubble) || $bubble != 'all') && (empty($bubble) || $response->get_request_method() == 'GET'); if (!$ok) { $response->set_code(406); } $systemsetting = null; $contextsetting = null; if ($ok) { $ok = !empty($linkid); if ($ok) { $lti = $DB->get_record('lti', array('id' => $linkid), 'course,typeid', MUST_EXIST); $ltitype = $DB->get_record('lti_types', array('id' => $lti->typeid)); $toolproxy = $DB->get_record('lti_tool_proxies', array('id' => $ltitype->toolproxyid)); $ok = $this->check_tool_proxy($toolproxy->guid, $response->get_request_data()); } if (!$ok) { $response->set_code(401); } } if ($ok) { $linksettings = lti_get_tool_settings($this->get_service()->get_tool_proxy()->id, $lti->course, $linkid); if (!empty($bubble)) { $contextsetting = new contextsettings($this->get_service()); if ($COURSE == 'site') { $contextsetting->params['context_type'] = 'Group'; } else { $contextsetting->params['context_type'] = 'CourseSection'; } $contextsetting->params['context_id'] = $lti->course; $contextsetting->params['vendor_code'] = $this->get_service()->get_tool_proxy()->vendorcode; $contextsetting->params['product_code'] = $this->get_service()->get_tool_proxy()->id; $contextsettings = lti_get_tool_settings($this->get_service()->get_tool_proxy()->id, $lti->course); $systemsetting = new systemsettings($this->get_service()); $systemsetting->params['tool_proxy_id'] = $this->get_service()->get_tool_proxy()->id; $systemsettings = lti_get_tool_settings($this->get_service()->get_tool_proxy()->id); if ($bubble == 'distinct') { toolsettings::distinct_settings($systemsettings, $contextsettings, $linksettings); } } else { $contextsettings = null; $systemsettings = null; } if ($response->get_request_method() == 'GET') { $json = ''; if ($simpleformat) { $response->set_content_type($this->formats[1]); $json .= "{"; } else { $response->set_content_type($this->formats[0]); $json .= "{\n \"@context\":\"http://purl.imsglobal.org/ctx/lti/v2/ToolSettings\",\n \"@graph\":[\n"; } $settings = toolsettings::settings_to_json($systemsettings, $simpleformat, 'ToolProxy', $systemsetting); $json .= $settings; $isfirst = strlen($settings) <= 0; $settings = toolsettings::settings_to_json($contextsettings, $simpleformat, 'ToolProxyBinding', $contextsetting); if (strlen($settings) > 0) { if (!$isfirst) { $json .= ","; if (!$simpleformat) { $json .= "\n"; } } $isfirst = false; } $json .= $settings; $settings = toolsettings::settings_to_json($linksettings, $simpleformat, 'LtiLink', $this); if (strlen($settings) > 0 && !$isfirst) { $json .= ","; if (!$simpleformat) { $json .= "\n"; } } $json .= $settings; if ($simpleformat) { $json .= "\n}"; } else { $json .= "\n ]\n}"; } $response->set_body($json); } else { // PUT. $settings = null; if ($response->get_content_type() == $this->formats[0]) { $json = json_decode($response->get_request_data()); $ok = !empty($json); if ($ok) { $ok = isset($json->{"@graph"}) && is_array($json->{"@graph"}) && count($json->{"@graph"}) == 1 && $json->{"@graph"}[0]->{"@type"} == 'LtiLink'; } if ($ok) { $settings = $json->{"@graph"}[0]->custom; } } else { // Simple JSON. $json = json_decode($response->get_request_data(), true); $ok = !empty($json); if ($ok) { $ok = is_array($json); } if ($ok) { $settings = $json; } } if ($ok) { lti_set_tool_settings($settings, $this->get_service()->get_tool_proxy()->id, $lti->course, $linkid); } else { $response->set_code(406); } } } }
public function execute($response) { $params = $this->parse_template(); $tpid = $params['tool_proxy_id']; $bubble = optional_param('bubble', null, PARAM_ALPHA); $ok = !empty($tpid) && $this->get_service()->check_tool_proxy($tpid, $response->get_request_data()); if (!$ok) { $response->set_code(401); } $contenttype = $response->get_accept(); $simpleformat = !is_null($contenttype) && ($contenttype == $this->formats[1]); if ($ok) { $ok = (is_null($bubble) || ((($bubble == 'distinct') || ($bubble == 'all')))) && (!$simpleformat || is_null($bubble) || ($bubble != 'all')) && (is_null($bubble) || ($response->get_request_method() == 'GET')); if (!$ok) { $response->set_code(406); } } if ($ok) { $systemsettings = lti_get_tool_settings($this->get_service()->get_tool_proxy()->id); if ($response->get_request_method() == 'GET') { $json = ''; if ($simpleformat) { $response->set_content_type($this->formats[1]); $json .= "{"; } else { $response->set_content_type($this->formats[0]); $json .= "{\n \"@context\":\"http://purl.imsglobal.org/ctx/lti/v2/ToolSettings\",\n \"@graph\":[\n"; } $json .= \ltiservice_toolsettings\service\toolsettings::settings_to_json($systemsettings, $simpleformat, 'ToolProxy', $this); if ($simpleformat) { $json .= "\n}"; } else { $json .= "\n ]\n}"; } $response->set_body($json); } else { // PUT. $settings = null; if ($response->get_content_type() == $this->formats[0]) { $json = json_decode($response->get_request_data()); $ok = !is_null($json); if ($ok) { $ok = isset($json->{"@graph"}) && is_array($json->{"@graph"}) && (count($json->{"@graph"}) == 1) && ($json->{"@graph"}[0]->{"@type"} == 'ToolProxy'); } if ($ok) { $settings = $json->{"@graph"}[0]->custom; } } else { // Simple JSON. $json = json_decode($response->get_request_data(), true); $ok = !is_null($json); if ($ok) { $ok = is_array($json); } if ($ok) { $settings = $json; } } if ($ok) { lti_set_tool_settings($settings, $this->get_service()->get_tool_proxy()->id); } else { $response->set_code(406); } } } }