public function H5pTincanRelayController::h5pTincanStatementRelay in Opigno TinCan API 8
Same name and namespace in other branches
- 3.x modules/opigno_tincan_activities/src/Controller/H5pTincanRelayController.php \Drupal\opigno_tincan_activities\Controller\H5pTincanRelayController::h5pTincanStatementRelay()
H5pTincanStatementRelay.
Parameters
\Symfony\Component\HttpFoundation\Request $request: Request.
Return value
object Return JsResponse object.
1 string reference to 'H5pTincanRelayController::h5pTincanStatementRelay'
- opigno_tincan_activities.routing.yml in modules/
opigno_tincan_activities/ opigno_tincan_activities.routing.yml - modules/opigno_tincan_activities/opigno_tincan_activities.routing.yml
File
- modules/
opigno_tincan_activities/ src/ Controller/ H5pTincanRelayController.php, line 27
Class
- H5pTincanRelayController
- Class H5pTincanRelayController.
Namespace
Drupal\opigno_tincan_activities\ControllerCode
public function h5pTincanStatementRelay(Request $request) {
$data = $request->request
->get('statement', '');
$data = json_decode($data, TRUE);
// Set object id.
$aid = $data['object']['definition']['extensions']['http://h5p.org/x-api/h5p-local-content-id'];
$url = Url::fromRoute('entity.opigno_activity.canonical', [
'opigno_activity' => $aid,
], [
'absolute' => TRUE,
])
->toString();
$data['object']['id'] = $url;
// Try to create and send the statement.
if (class_exists('TinCan\\Statement')) {
try {
$statement = new Statement($data);
} catch (Exception $e) {
\Drupal::logger('opigno_tincan')
->error('The following statement could not be created: <br /><pre>' . print_r($data, TRUE) . '</pre><br />This exception was raised: ' . $e
->getMessage());
return new JsonResponse(NULL, Response::HTTP_BAD_REQUEST);
}
$statement
->stamp();
// Sending statement.
OpignoTinCanApiStatements::sendStatement($statement);
}
return new JsonResponse(NULL, Response::HTTP_OK);
}