public function redirect($url, $statusCode = 302)
 {
     $context = Context::getInstance();
     header(HTTPToolkit::statusCodeHeader($statusCode));
     header(HTTPToolkit::locationHeader($url));
     throw new InterruptedActionException('Interrupted action after a redirection', $context->getModuleName(), $context->getActionName());
 }
예제 #2
0
 public function send()
 {
     $params = [];
     if ($this->exception instanceof \tao_models_classes_AccessDeniedException) {
         $params = ['redirect' => $this->exception->getDeniedRequest()->getRequestURI(), 'msg' => $this->exception->getUserMessage()];
     }
     /* @var $urlRouteService \oat\tao\model\mvc\DefaultUrlService */
     $urlRouteService = $this->getServiceLocator()->get('tao/urlroute');
     header(\HTTPToolkit::locationHeader($urlRouteService->getLoginUrl($params)));
     return;
 }
예제 #3
0
 protected function returnJson($data, $httpStatus = 200)
 {
     header(HTTPToolkit::statusCodeHeader($httpStatus));
     Context::getInstance()->getResponse()->setContentHeader('application/json');
     echo json_encode($data);
 }
 private function dispatchError(Exception $e, $httpStatus, $message = '', $trace = '')
 {
     // Set relevant HTTP header.
     header(HTTPToolkit::statusCodeHeader($httpStatus));
     if (tao_helpers_Request::isAjax()) {
         new common_AjaxResponse(array("success" => false, "type" => 'Exception', "data" => array('ExceptionType' => get_class($e)), "message" => $message));
     } else {
         require_once Template::getTemplate("error/error{$httpStatus}.tpl", 'tao');
     }
 }
예제 #5
0
 /**
  * Provides the definition data and the state for a particular item
  */
 public function getItem()
 {
     $code = 200;
     $itemRef = $this->getRequestParameter('itemDefinition');
     try {
         $serviceContext = $this->getServiceContext();
         $stateId = $this->getStateId();
         $itemState = $this->runnerService->getItemState($serviceContext, $stateId);
         if (!count($itemState)) {
             $itemState = new stdClass();
         }
         // TODO: make a better implementation
         // As the rubric blocs are nested at the section level, it could be interesting to send these
         // rubric blocs only once per section
         if (count($serviceContext->getTestSession()->getRoute()->current()->getRubricBlockRefs())) {
             $rubrics = $this->runnerService->getRubrics($serviceContext);
         } else {
             $rubrics = null;
         }
         $itemData = $this->runnerService->getItemData($serviceContext, $itemRef);
         $baseUrl = $this->runnerService->getItemPublicUrl($serviceContext, $itemRef);
         if (is_string($itemData)) {
             $response = '{' . '"success":true,' . '"token":"' . $this->getCsrf()->getCsrfToken() . '",' . '"baseUrl":"' . $baseUrl . '",' . '"itemData":' . $itemData . ',' . '"itemState":' . json_encode($itemState) . ',' . '"rubrics":' . json_encode($rubrics) . '}';
         } else {
             $response = ['success' => true, 'itemData' => $itemData, 'itemState' => $itemState, 'baseUrl' => $baseUrl, 'rubrics' => $rubrics];
         }
         $this->runnerService->startTimer($serviceContext);
     } catch (common_Exception $e) {
         $response = $this->getErrorResponse($e);
         $code = $this->getErrorCode($e);
     }
     if (is_string($response)) {
         header(HTTPToolkit::statusCodeHeader($code));
         Context::getInstance()->getResponse()->setContentHeader('application/json');
         echo $response;
     } else {
         $this->returnJson($response, $code);
     }
 }