shouldShowThankYou($launchData) ? $this->buildThankYouUrl() : $this->buildConsumerReturnUrl($launchData, $deliveryExecution); } /** * @param LtiLaunchData $launchData * @param DeliveryExecutionInterface $deliveryExecution * @return string * @throws \common_exception_NotFound * @throws InvalidService * @throws InvalidServiceManagerException * @throws LtiException */ protected function buildConsumerReturnUrl( LtiLaunchData $launchData, DeliveryExecutionInterface $deliveryExecution ): string { $urlParts = parse_url($launchData->getReturnUrl()); $port = empty($urlParts['port']) ? '' : (':' . $urlParts['port']); $path = $urlParts['path'] ?? ''; $queryString = $this->buildConsumerReturnUrlQuery($deliveryExecution, $urlParts); return $urlParts['scheme'] . '://' . $urlParts['host'] . $port . $path . '?' . $queryString; } /** * @param DeliveryExecutionInterface $deliveryExecution * @return array * @throws \common_exception_NotFound * @throws InvalidService * @throws InvalidServiceManagerException */ protected function getConsumerReturnParams(DeliveryExecutionInterface $deliveryExecution): array { $ltiReturnQueryParams = $this->getLtiReturnUrlQueryParams($deliveryExecution); $deliveryReturnQueryParams = $this->getDeliveryReturnQueryParams($deliveryExecution); return array_merge($ltiReturnQueryParams, $deliveryReturnQueryParams); } /** * Whenever or not to show the thank you screen * @param LtiLaunchData $launchData * @return bool */ protected function shouldShowThankYou(LtiLaunchData $launchData): bool { if (!$launchData->hasReturnUrl()) { return true; } if ($launchData->hasVariable(DeliveryTool::PARAM_SKIP_THANKYOU)) { switch ($launchData->getVariable(DeliveryTool::PARAM_SKIP_THANKYOU)) { case 'true': return false; case 'false': return true; default: $this->logWarning('Unexpected value for \'' . DeliveryTool::PARAM_SKIP_THANKYOU . '\': ' . $launchData->getVariable(DeliveryTool::PARAM_SKIP_THANKYOU)); } } return $this->getOption(self::OPTION_THANK_YOU_SCREEN); } /** * @return string */ protected function buildThankYouUrl(): string { return $this->getServiceLocator()->get(UrlHelper::class)->buildUrl('thankYou', 'DeliveryRunner', 'ltiDeliveryProvider'); } /** * @param DeliveryExecutionInterface $deliveryExecution * @param array $urlParts * @return array * @throws \common_exception_NotFound */ private function buildConsumerReturnUrlQuery(DeliveryExecutionInterface $deliveryExecution, array $urlParts): string { $urlParts['query'] = $urlParts['query'] ?? ''; parse_str($urlParts['query'], $params); return http_build_query(array_merge($params, $this->getConsumerReturnParams($deliveryExecution))); } /** * @param DeliveryExecutionInterface $deliveryExecution * @return array * @throws InvalidService * @throws InvalidServiceManagerException */ private function getLtiReturnUrlQueryParams(DeliveryExecutionInterface $deliveryExecution): array { $ltiMessage = $this->getSubService(self::OPTION_MESSAGE_FACTORY)->getLtiMessage($deliveryExecution); return ($ltiMessage instanceof LtiMessage) ? $ltiMessage->getUrlParams() : []; } /** * @param DeliveryExecutionInterface $deliveryExecution * @param $params * @return mixed * @throws \common_exception_NotFound */ private function getDeliveryReturnQueryParams(DeliveryExecutionInterface $deliveryExecution): array { $params = [ 'deliveryExecution' => $deliveryExecution->getIdentifier() ]; if ($this->getOption(self::OPTION_DELIVERY_RETURN_STATUS)) { $params['deliveryExecutionStatus'] = $deliveryExecution->getState()->getLabel(); } return $params; } }