getServiceContext(); $itemRef = ($this->hasRequestParameter('itemDefinition')) ? $this->getRequestParameter('itemDefinition') : null; if (!is_null($itemRef)) { $event = new ItemOfflineEvent($serviceContext->getTestSession(), $itemRef); $this->getServiceLocator()->get(EventManager::SERVICE_ID)->trigger($event); return true; } return false; } /** * TestRunnerAction constructor. * * Construct the action with required $name and $timestamp * Parameters is optional * * @param $name * @param $timestamp * @param array $parameters */ public function __construct($name, $timestamp, array $parameters = []) { $this->name = $name; $this->timestamp = $timestamp; $this->parameters = $parameters; } /** * Check if $name exists in parameters array * * @param $name * @return bool */ public function hasRequestParameter($name) { return isset($this->parameters[$name]); } /** * Get action input parameters * * @return mixed */ public function getRequestParameters() { return $this->parameters; } /** * Check get the $name from parameters array, false if does not exist * * @param $name * @return bool|mixed */ public function getRequestParameter($name) { return $this->hasRequestParameter($name) ? $this->parameters[$name] : false; } /** * For RunnerToolStates * * @param $name * @return bool|mixed */ public function getRawRequestParameter($name) { return $this->getRequestParameter($name); } /** * Get the timestamp of current action in seconds * * @return double $time */ public function getTime() { return $this->time; } /** * Set the timestamp of current action in seconds * * @param double $time */ public function setTime($time) { $this->time = $time; } /** * Get the name of current action * * @return mixed */ public function getName() { return $this->name; } /** * Get the timestamp of current action * * @return integer */ public function getTimestamp() { return $this->timestamp; } /** * Provide the required fields for current action * * @return array */ protected function getRequiredFields() { return ['testDefinition', 'testCompilation', 'serviceCallId']; } /** * Validate the class parameters against the getRequiredFields method * * @throws \common_exception_InconsistentData */ public function validate() { $requiredFields = array_unique($this->getRequiredFields()); $isValid = ($requiredFields == array_unique(array_intersect($requiredFields, array_keys($this->parameters)))); if (!$isValid) { throw new \common_exception_InconsistentData('Some parameters are missing. Required parameters are : ' . implode(', ', $requiredFields)); } } /** * Gets an error response object * * @param Exception [$e] Optional exception from which extract the error context * @return array */ protected function getErrorResponse($e = null) { $response = [ 'success' => false, 'type' => 'error', ]; if ($e) { if ($e instanceof \Exception) { $response['type'] = 'exception'; $response['code'] = $e->getCode(); } if ($e instanceof \common_exception_UserReadableException) { $response['message'] = $e->getUserMessage(); } else { $response['message'] = __('An error occurred!'); } switch (true) { case $e instanceof QtiRunnerClosedException: case $e instanceof QtiRunnerPausedException: if ($this->serviceContext) { $messageService = $this->getServiceLocator()->get(QtiRunnerMessageService::SERVICE_ID); $response['message'] = __($messageService->getStateMessage($this->getServiceContext()->getTestSession())); } $response['type'] = 'TestState'; break; case $e instanceof \tao_models_classes_FileNotFoundException: $response['type'] = 'FileNotFound'; $response['message'] = __('File not found'); break; case $e instanceof \common_exception_Unauthorized: $response['code'] = 403; break; } } return $response; } }