/**
  * Either displays the currently associated delivery
  * or calls selectDelivery in order to allow the user to select a delivery
  * 
  * Only accessible to LTI instructors
  */
 public function configureDelivery()
 {
     $compiledDelivery = LTIDeliveryTool::singleton()->getDeliveryFromLink();
     if (is_null($compiledDelivery)) {
         $this->selectDelivery();
     } else {
         $this->redirect(_url('showDelivery', null, null, array('uri' => $compiledDelivery->getUri())));
     }
 }
 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())));
 }
 /**
  * Displays the LTI link for the consumer with respect to the currently selected delviery
  * at tdelviery level, checks if the delviery is related to a resultserver cofnigured with the correct outcome service impelmentation
  * @author patrick <*****@*****.**>
  */
 public function index()
 {
     $feedBackMessage = '';
     //checks the constraint for the results handling, depends on taoResultServer, taoLtiBasicOutcome
     $selectedDelivery = new core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri')));
     try {
         $resultServer = $selectedDelivery->getUniquePropertyValue(new core_kernel_classes_Property(TAO_DELIVERY_RESULTSERVER_PROP));
     } catch (Exception $e) {
         $feedBackMessage = __("The delivery is not associated to a Result server storage policy");
     }
     $this->setData('launchUrl', LTIDeliveryTool::singleton()->getLaunchUrl(array('delivery' => $selectedDelivery->getUri())));
     if (!empty($feedBackMessage)) {
         $this->setData('warning', $feedBackMessage);
     }
     $class = new core_kernel_classes_Class(CLASS_LTI_CONSUMER);
     $this->setData('consumers', $class->getInstances());
     $this->setData('deliveryLabel', $selectedDelivery->getLabel());
     $this->setView('linkManagement.tpl', 'ltiDeliveryProvider');
 }
 public function deliveriesByProctor()
 {
     $deliveryData = array();
     if (\common_ext_ExtensionsManager::singleton()->isInstalled('ltiDeliveryProvider')) {
         /** @var DeliveryService $service */
         $service = $this->getServiceManager()->get(DeliveryService::CONFIG_ID);
         $deliveries = $service->getAccessibleDeliveries();
         if (!empty($deliveries)) {
             try {
                 $dataStore = new \tao_models_classes_oauth_DataStore();
                 $test_consumer = $dataStore->lookup_consumer('proctoring_key');
             } catch (\tao_models_classes_oauth_Exception $e) {
                 $secret = uniqid('proctoring_');
                 \taoLti_models_classes_ConsumerService::singleton()->getRootClass()->createInstanceWithProperties(array(RDFS_LABEL => 'proctoring', PROPERTY_OAUTH_KEY => 'proctoring_key', PROPERTY_OAUTH_SECRET => $secret));
                 $test_consumer = new \OAuthConsumer('proctoring_key', $secret);
             }
             $session = \common_session_SessionManager::getSession();
             $ltiData = array('lti_message_type' => 'basic-lti-launch-request', 'lti_version' => 'LTI-1p0', 'resource_link_id' => rand(0, 9999999), 'resource_link_title' => 'Launch Title', 'resource_link_label' => 'Launch label', 'context_title' => 'Launch Title', 'context_label' => 'Launch label', 'user_id' => $session->getUserUri(), 'roles' => 'Learner', 'lis_person_name_full' => $session->getUserLabel(), 'tool_consumer_info_product_family_code' => PRODUCT_NAME, 'tool_consumer_info_version' => TAO_VERSION, 'custom_skip_thankyou' => 'true', 'launch_presentation_return_url' => _url('logout', 'Main', 'tao'));
             $hmac_method = new \OAuthSignatureMethod_HMAC_SHA1();
             $test_token = new \OAuthToken($test_consumer, '');
             foreach ($deliveries as $delivery) {
                 $launchUrl = LTIDeliveryTool::singleton()->getLaunchUrl(array('delivery' => $delivery->getUri()));
                 $acc_req = \OAuthRequest::from_consumer_and_token($test_consumer, $test_token, 'GET', $launchUrl, $ltiData);
                 $acc_req->sign_request($hmac_method, $test_consumer, $test_token);
                 $deliveryData[] = array('id' => $delivery->getUri(), 'label' => $delivery->getLabel(), 'url' => $acc_req->to_url(), 'text' => __('Test'));
             }
         }
     }
     $this->setData('title', __('Available Deliveries'));
     if (\tao_helpers_Request::isAjax()) {
         $this->returnJson(array('list' => $deliveryData));
     } else {
         try {
             $testCenter = $this->getCurrentTestCenter();
             $this->composeView('diagnostic-deliveries', array('list' => $deliveryData), array(BreadcrumbsHelper::testCenters(), BreadcrumbsHelper::testCenter($testCenter, TestCenterHelper::getTestCenters()), BreadcrumbsHelper::diagnostics($testCenter, array(BreadcrumbsHelper::deliveries($testCenter))), BreadcrumbsHelper::deliveriesByProctor($testCenter)));
         } catch (\common_Exception $e) {
             $this->composeView('diagnostic-deliveries', array('list' => $deliveryData), array(BreadcrumbsHelper::testCenters()));
         }
     }
 }
 /**
  * return a LTI link URI from a valid delivery id
  * @author Christophe GARCIA <*****@*****.**>
  */
 public function getUrl()
 {
     try {
         if ($this->getRequestMethod() != \Request::HTTP_GET) {
             throw new \common_exception_NotImplemented('Only GET method is accepted to request this service.');
         }
         if (!$this->hasRequestParameter('deliveryId')) {
             $this->returnFailure(new \common_exception_MissingParameter('At least one mandatory parameter was required but found missing in your request'));
         }
         $selectedDelivery = new \core_kernel_classes_Resource($this->getRequestParameter('deliveryId'));
         if (!$selectedDelivery->isInstanceOf(new \core_kernel_classes_Class(TAO_DELIVERY_CLASS))) {
             $this->returnFailure(new \common_exception_NotFound('Delivery not found'));
         }
         try {
             $selectedDelivery->getUniquePropertyValue(new \core_kernel_classes_Property(\TAO_DELIVERY_RESULTSERVER_PROP));
         } catch (Exception $e) {
             $this->returnFailure(new \common_exception_BadRequest('The delivery is not associated to a Result server storage policy'));
         }
         $this->returnSuccess(LTIDeliveryTool::singleton()->getLaunchUrl(array('delivery' => $selectedDelivery->getUri())));
     } catch (Exception $ex) {
         $this->returnFailure($ex);
     }
 }
 /**
  * Returns the delivery associated with the current link
  * either from url or from the remote_link if configured
  * returns null if none found
  *
  * @return core_kernel_classes_Resource
  */
 private function getDelivery()
 {
     $returnValue = null;
     //passed as aprameter
     if ($this->hasRequestParameter('delivery')) {
         $returnValue = new core_kernel_classes_Resource($this->getRequestParameter('delivery'));
     } else {
         $launchData = taoLti_models_classes_LtiService::singleton()->getLtiSession()->getLaunchData();
         $deliveryUri = $launchData->getCustomParameter('delivery');
         if (!is_null($deliveryUri)) {
             $returnValue = new core_kernel_classes_Resource($deliveryUri);
         } else {
             // stored in link
             $returnValue = LTIDeliveryTool::singleton()->getDeliveryFromLink();
         }
     }
     return $returnValue;
 }