public function OpignoScormController::scormCommit in Opigno SCORM 8
Same name and namespace in other branches
- 3.x src/Controller/OpignoScormController.php \Drupal\opigno_scorm\Controller\OpignoScormController::scormCommit()
Scorm data commit method.
1 string reference to 'OpignoScormController::scormCommit'
File
- src/
Controller/ OpignoScormController.php, line 68
Class
- OpignoScormController
- Class OpignoScormController.
Namespace
Drupal\opigno_scorm\ControllerCode
public function scormCommit($opigno_scorm_id, $opigno_scorm_sco_id) {
$data_content = $GLOBALS['request']
->getContent();
if (!empty($_POST['data'])) {
$data = json_decode($_POST['data']);
}
elseif ($data_content) {
$data = json_decode($data_content);
}
if (!empty($data)) {
if (!empty($data->cmi->interactions)) {
$_SESSION['scorm_answer_results'] = [
'opigno_scorm_id' => $opigno_scorm_id,
'opigno_scorm_sco_id' => $opigno_scorm_sco_id,
'data' => $data,
];
}
$scorm_service = \Drupal::service('opigno_scorm.scorm');
$scorm = $scorm_service
->scormLoadById($opigno_scorm_id);
\Drupal::moduleHandler()
->invokeAll('opigno_scorm_commit', [
$scorm,
$opigno_scorm_sco_id,
$data,
]);
return new JsonResponse([
'success' => 1,
]);
}
else {
return new JsonResponse([
'error' => 1,
'message' => 'no data received',
]);
}
}