/**
  * @param type $deliveryResultIdentifier lis_result_sourcedid
  * @param type $test ignored
  * @param taoResultServer_models_classes_Variable $testVariable
  * @param type $callIdTest ignored
  */
 public function storeTestVariable($deliveryResultIdentifier, $test, taoResultServer_models_classes_Variable $testVariable, $callIdTest)
 {
     if (get_class($testVariable) == "taoResultServer_models_classes_OutcomeVariable") {
         common_Logger::i("Outcome submission VariableId. (" . $testVariable->getIdentifier() . ") Result Identifier (" . $deliveryResultIdentifier . ")Service URL (" . $this->serviceUrl . ")");
         $variableIdentifier = $testVariable->getIdentifier();
         if ($variableIdentifier == LTI_OUTCOME_VARIABLE_IDENTIFIER) {
             $grade = (string) $testVariable->getValue();
             $message = taoLtiBasicOutcome_helpers_LtiBasicOutcome::buildXMLMessage($deliveryResultIdentifier, $grade, 'replaceResultRequest');
             //common_Logger::i("Preparing POX message for the outcome service :".$message."\n");
             $credentialResource = taoLti_models_classes_LtiService::singleton()->getCredential($this->consumerKey);
             //common_Logger::i("Credential for the consumerKey :". $credentialResource->getUri()."\n");
             $credentials = new tao_models_classes_oauth_Credentials($credentialResource);
             //$this->serviceUrl = "http://tao-dev/log.php";
             //Building POX raw http message
             $unSignedOutComeRequest = new common_http_Request($this->serviceUrl, 'POST', array());
             $unSignedOutComeRequest->setBody($message);
             $signingService = new tao_models_classes_oauth_Service();
             $signedRequest = $signingService->sign($unSignedOutComeRequest, $credentials, true);
             common_Logger::i("Request sent (Body)\n" . $signedRequest->getBody() . "\n");
             common_Logger::i("Request sent (Headers)\n" . serialize($signedRequest->getHeaders()) . "\n");
             common_Logger::i("Request sent (Headers)\n" . serialize($signedRequest->getParams()) . "\n");
             //Hack for moodle comaptibility, the header is ignored for the signature computation
             $signedRequest->setHeader("Content-Type", "application/xml");
             $response = $signedRequest->send();
             common_Logger::i("\nHTTP Code received: " . $response->httpCode . "\n");
             common_Logger::i("\nHTTP From: " . $response->effectiveUrl . "\n");
             common_Logger::i("\nHTTP Content received: " . $response->responseData . "\n");
             if ($response->httpCode != "200") {
                 throw new common_exception_Error("An HTTP level proble occured when sending the outcome to the service url");
             }
         }
     }
 }
 /**
  * Entrypoint of every tool
  */
 public function launch()
 {
     try {
         taoLti_models_classes_LtiService::singleton()->startLtiSession(common_http_Request::currentRequest());
         // check if cookie has been set
         if (tao_models_classes_accessControl_AclProxy::hasAccess('verifyCookie', 'CookieUtils', 'taoLti')) {
             $this->redirect(_url('verifyCookie', 'CookieUtils', 'taoLti', array('session' => session_id(), 'redirect' => _url('run', null, null, $_GET))));
         } else {
             $this->returnError(__('You are not authorized to use this system'));
         }
     } catch (common_user_auth_AuthFailedException $e) {
         common_Logger::i($e->getMessage());
         $this->returnError(__('The LTI connection could not be established'), false);
     } catch (taoLti_models_classes_LtiException $e) {
         // In regard of the IMS LTI standard, we have to show a back button that refer to the
         // launch_presentation_return_url url param. So we have to retrieve this parameter before trying to start
         // the session
         $params = common_http_Request::currentRequest()->getParams();
         if (isset($params[taoLti_models_classes_LtiLaunchData::TOOL_CONSUMER_INSTANCE_NAME])) {
             $this->setData('consumerLabel', $params[taoLti_models_classes_LtiLaunchData::TOOL_CONSUMER_INSTANCE_NAME]);
         } elseif (isset($params[taoLti_models_classes_LtiLaunchData::TOOL_CONSUMER_INSTANCE_DESCRIPTION])) {
             $this->setData('consumerLabel', $params[taoLti_models_classes_LtiLaunchData::TOOL_CONSUMER_INSTANCE_DESCRIPTION]);
         }
         if (isset($params[taoLti_models_classes_LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL])) {
             $this->setData('returnUrl', $params[taoLti_models_classes_LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL]);
         }
         common_Logger::i($e->getMessage());
         $this->returnError(__('The LTI connection could not be established'), false);
     } catch (tao_models_classes_oauth_Exception $e) {
         common_Logger::i($e->getMessage());
         $this->returnError(__('The LTI connection could not be established'), false);
     }
 }
Example #3
0
 /**
  * Returns an error page
  * 
  * Ignore the parameter returnLink as LTI session always
  * require a way for the consumer to return to his platform
  * 
  * (non-PHPdoc)
  * @see tao_actions_CommonModule::returnError()
  */
 protected function returnError($description, $returnLink = false)
 {
     if (tao_helpers_Request::isAjax()) {
         throw new common_exception_IsAjaxAction(__CLASS__ . '::' . __FUNCTION__);
     } else {
         try {
             $launchData = \taoLti_models_classes_LtiService::singleton()->getLtiSession()->getLaunchData();
             $returnUrl = $launchData->getCustomParameter(\taoLti_models_classes_LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL);
             // In regard of the IMS LTI standard, we have to show a back button that refer to the
             // launch_presentation_return_url url param. So we have to retrieve this parameter before trying to start
             // the session
             $consumerLabel = $launchData->getToolConsumerName();
             if (!is_null($consumerLabel)) {
                 $this->setData('consumerLabel', $consumerLabel);
             }
             if ($launchData->hasVariable(\taoLti_models_classes_LtiLaunchData::LAUNCH_PRESENTATION_RETURN_URL)) {
                 $this->setData('returnUrl', $launchData->getReturnUrl());
             }
         } catch (\taoLti_models_classes_LtiException $exception) {
             // no Lti Session started
         }
         if (!empty($description)) {
             $this->setData('message', $description);
         }
         $this->setView('error.tpl', 'taoLti');
     }
 }
 public function repeat()
 {
     $delivery = new \core_kernel_classes_Resource($this->getRequestParameter('delivery'));
     // is allowed?
     // is active?
     $remoteLink = \taoLti_models_classes_LtiService::singleton()->getLtiSession()->getLtiLinkResource();
     $userId = \common_session_SessionManager::getSession()->getUserUri();
     $newExecution = LTIDeliveryTool::singleton()->startDelivery($delivery, $remoteLink, $userId);
     $this->redirect(_url('runDeliveryExecution', null, null, array('deliveryExecution' => $newExecution->getIdentifier())));
 }
 /**
  * Returns an resource representing the incoming link
  * 
  * @throws common_exception_Error
  * @return core_kernel_classes_Resource
  */
 public function getLtiLinkResource()
 {
     if (is_null($this->ltiLink)) {
         $class = new core_kernel_classes_Class(CLASS_LTI_INCOMINGLINK);
         $consumer = taoLti_models_classes_LtiService::singleton()->getLtiConsumerResource($this->getLaunchData());
         // search for existing resource
         $instances = $class->searchInstances(array(PROPERTY_LTI_LINK_ID => $this->getLaunchData()->getResourceLinkID(), PROPERTY_LTI_LINK_CONSUMER => $consumer), array('like' => false, 'recursive' => false));
         if (count($instances) > 1) {
             throw new common_exception_Error('Multiple resources for link ' . $this->getLaunchData()->getResourceLinkID());
         }
         if (count($instances) == 1) {
             // use existing link
             $this->ltiLink = current($instances);
         } else {
             // spawn new link
             $this->ltiLink = $class->createInstanceWithProperties(array(PROPERTY_LTI_LINK_ID => $this->getLaunchData()->getResourceLinkID(), PROPERTY_LTI_LINK_CONSUMER => $consumer));
         }
     }
     return $this->ltiLink;
 }
 protected function getLearnerUrl(\core_kernel_classes_Resource $delivery)
 {
     $remoteLink = \taoLti_models_classes_LtiService::singleton()->getLtiSession()->getLtiLinkResource();
     $userId = \common_session_SessionManager::getSession()->getUserUri();
     $active = null;
     $executions = $this->getTool()->getLinkedDeliveryExecutions($delivery, $remoteLink, $userId);
     if (empty($executions)) {
         $active = $this->getTool()->startDelivery($delivery, $remoteLink, $userId);
         return _url('runDeliveryExecution', 'DeliveryRunner', null, array('deliveryExecution' => $active->getIdentifier()));
     } else {
         foreach ($executions as $deliveryExecution) {
             if ($deliveryExecution->getState()->getUri() == INSTANCE_DELIVERYEXEC_ACTIVE) {
                 $active = $deliveryExecution;
                 break;
             }
         }
         if (is_null($active)) {
             return _url('ltiOverview', 'DeliveryRunner', null, array('delivery' => $delivery->getUri()));
         } else {
             return _url('runDeliveryExecution', 'DeliveryRunner', null, array('deliveryExecution' => $active->getIdentifier()));
         }
     }
 }
 protected function getLearnerUrl(\core_kernel_classes_Resource $delivery)
 {
     $remoteLink = \taoLti_models_classes_LtiService::singleton()->getLtiSession()->getLtiLinkResource();
     $userId = \common_session_SessionManager::getSession()->getUserUri();
     $launchData = taoLti_models_classes_LtiService::singleton()->getLtiSession()->getLaunchData();
     if ($launchData->hasVariable(self::PARAM_FORCE_RESTART) && $launchData->getVariable(self::PARAM_FORCE_RESTART) == 'true') {
         // ignore existing executions to force restart
         $executions = array();
     } else {
         $executions = $this->getTool()->getLinkedDeliveryExecutions($delivery, $remoteLink, $userId);
     }
     if (empty($executions)) {
         $active = $this->getTool()->startDelivery($delivery, $remoteLink, $userId);
         return _url('runDeliveryExecution', 'DeliveryRunner', null, array('deliveryExecution' => $active->getIdentifier()));
     } else {
         $active = null;
         foreach ($executions as $deliveryExecution) {
             if ($deliveryExecution->getState()->getUri() == DeliveryExecution::STATE_ACTIVE) {
                 $active = $deliveryExecution;
                 break;
             }
         }
         if (is_null($active)) {
             return _url('ltiOverview', 'DeliveryRunner', null, array('delivery' => $delivery->getUri()));
         } else {
             return _url('runDeliveryExecution', 'DeliveryRunner', null, array('deliveryExecution' => $active->getIdentifier()));
         }
     }
 }
 public function __construct(taoLti_models_classes_LtiLaunchData $ltiLaunchData)
 {
     $this->ltiLaunchData = $ltiLaunchData;
     $this->userUri = taoLti_models_classes_LtiService::singleton()->findOrSpwanUser($ltiLaunchData)->getUri();
     $this->roles = $this->determinTaoRoles();
 }