/** * Perform the result of an action. * * This function may redirect the user to another URL rather than returning a value. * * @return string Output to be displayed (redirection, or display HTML or message) */ private function result() { // TODO: Call $this->onError(); hook // FIXME: Should be executed when exception is caught if (false) { // If not valid, return an error message to the tool consumer if a return URL is provided if (!empty($this->returnUrl)) { $error_url = $this->returnUrl; if (strpos($error_url, '?') === false) { $error_url .= '?'; } else { $error_url .= '&'; } if ($this->debugMode && !is_null($this->reason)) { $error_url .= 'lti_errormsg=' . urlencode("Debug error: {$this->reason}"); } else { $error_url .= 'lti_errormsg=' . urlencode($this->message); if (!is_null($this->reason)) { $error_url .= '<i_errorlog=' . urlencode("Debug error: {$this->reason}"); } } if (!is_null($this->consumer) && isset($_POST['lti_message_type']) && $_POST['lti_message_type'] === 'ContentItemSelectionRequest') { $form_params = []; if (isset($_POST['data'])) { $form_params['data'] = $_POST['data']; } $version = isset($_POST['lti_version']) ? $_POST['lti_version'] : ToolProvider::LTI_VERSION1; $form_params = $this->consumer->signParameters($error_url, 'ContentItemSelection', $version, $form_params); $page = ToolProvider::sendForm($error_url, $form_params); echo $page; } else { header("Location: {$error_url}"); } exit; } else { if (!is_null($this->errorOutput)) { echo $this->errorOutput; } else { if ($this->debugMode && !empty($this->reason)) { echo "Debug error: {$this->reason}"; } else { echo "Error: {$this->message}"; } } } } else { if (!is_null($this->redirectUrl)) { header("Location: {$this->redirectUrl}"); exit; } else { if (!is_null($this->output)) { echo $this->output; } } } }
/** * Send a service request to the tool consumer. * * @param string $type GuzzleClient type value * @param string $url URL to send request to * @param array $params Associative array of parameter values to be passed * * @return boolean True if the request successfully obtained a response */ private function doService($type, $url, $params) { $ok = false; if (!empty($url)) { $params = $this->consumer->signParameters($url, $type, $this->consumer->ltiVersion, $params); // Connect to tool consumer $response = ClientFactory::make()->send($url, 'POST', $params); // Parse XML response if ($response->isSuccessful()) { $response = $response->getWrappedResponse(); try { $extDoc = new DOMDocument(); $extDoc->loadXML((string) $response->getBody()); $this->extNodes = $this->domNodeToArray($extDoc->documentElement); if (isset($this->extNodes['statusinfo']['codemajor']) && $this->extNodes['statusinfo']['codemajor'] == 'Success') { $ok = true; } } catch (Exception $e) { } } } return $ok; }