devianl2 / laravel-scorm

Laravel scorm package
MIT License
38 stars 20 forks source link

save progress #16

Closed haithamrdina closed 2 years ago

haithamrdina commented 2 years ago

hi [@devianl2 there are no examples for saving progress ? if you can make an example to see how do it thanks

devianl2 commented 2 years ago

Hi @haithamrdina,

I assume you know how to receive cmi data from iframe, submit through ajax to API. I will share some code below for your reference.

1) First of all, you need to have retrieve the sco ID and sco tracking ID. (I assume you have it) 2) Submit cmi data with sco ID and sco tracking ID. 3) Use the code below to find user sco tracking. $scoTracking = ScormManager::findScoTrackingId($scoUuid, $scoTrackingUuid);

4) Update user learning with the following code:

$sco    =   ScormManager::updateScoTracking($scoUuid, $scoTracking->user_id, $this->request->input('cmiData'));

if ($sco->lesson_status ==  'completed' || $sco->lesson_status == 'passed') {
   // Any function that you want to execute as soon as user is completed the scorm.
   // It could be send a congratulation email, update user learning result, generate certificate and etc
}
haithamrdina commented 2 years ago

thanks you so much @devianl2 if u can share with me some reference to receive cmi data from iframe,

devianl2 commented 2 years ago

@haithamrdina You may refer to SCORM Run-Time Reference.

Btw, you can also refer to src/Manager/ScormManager.php (Starting from line 421)

Some sample: $scoreRaw = isset($data['cmi.core.score.raw']) ? intval($data['cmi.core.score.raw']) : null; $scoreMin = isset($data['cmi.core.score.min']) ? intval($data['cmi.core.score.min']) : null; $scoreMax = isset($data['cmi.core.score.max']) ? intval($data['cmi.core.score.max']) : null; $lessonStatus = isset($data['cmi.core.lesson_status']) ? $data['cmi.core.lesson_status'] : 'unknown'; $sessionTime = isset($data['cmi.core.session_time']) ? $data['cmi.core.session_time'] : null;

baskarcm commented 2 years ago

how to receive cmi data(lesson_location) from iframe for every current lesson?

devianl2 commented 2 years ago

how to receive cmi data(lesson_location) from iframe for every current lesson?

You can use some javascript library to capture CMI data and use postMessage to transmit the data between laravel application and frontend iframe

postMessage: https://javascript.info/cross-window-communication#postmessage

SCORM library sample: https://www.npmjs.com/package/scorm-again

zaks-zaiya commented 2 years ago

Do you have an example how to play the scorm after upload. So far Im already success on upload part. But after that, no idea how to show, play and track progress.

devianl2 commented 2 years ago

Do you have an example how to play the scorm after upload. So far Im already success on upload part. But after that, no idea how to show, play and track progress.

Hi @zaks-zaiya , that is beyond the scope of this package. But to answer your question, you need to know how to use iframe and postMessage to transmit the CMI message into API.

  1. You need to have understand the hierarchy of iframes: https://scorm.com/scorm-explained/technical-scorm/run-time/
  2. Use postMessage to parse your uploaded scorm file url and learner data into children iframe: https://javascript.info/cross-window-communication#postmessage
  3. Use frontend scorm library to parse and listen to scorm data, and use postMessage to parse scorm respond back to parent iframe: https://www.npmjs.com/package/scorm-again
  4. Any respond that is being captured by parent iframe postMessage listener will send to your POST request API (From your laravel route)

This package is mainly focus on SCORM file upload, extract, create SCO data and learner data. It does not cover frontend listener :)

If you need help on frontend iframe listener, please contact me personally (devianleong@gmail.com). I will create a simple demo for you. Just buy me a coffee :)