/** * 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); } }