From 157d77625644a97742f6953df6a42476c5387e2c Mon Sep 17 00:00:00 2001 From: Sam Light Date: Fri, 9 Sep 2022 15:28:41 +0100 Subject: Moved controller out of http folder. No need to nest! --- src/Controllers/ScormPlayerController.php | 119 ++++++++++++++++++++++++ src/Http/Controllers/ScormPlayerController.php | 121 ------------------------- 2 files changed, 119 insertions(+), 121 deletions(-) create mode 100644 src/Controllers/ScormPlayerController.php delete mode 100644 src/Http/Controllers/ScormPlayerController.php diff --git a/src/Controllers/ScormPlayerController.php b/src/Controllers/ScormPlayerController.php new file mode 100644 index 0000000..e7f3971 --- /dev/null +++ b/src/Controllers/ScormPlayerController.php @@ -0,0 +1,119 @@ +query('sco'); + $sco = $module->scos()->findOrFail($sco); + + $route_data = ['sco' => $sco]; + $scorm_api_data = [ + 'routes' => [ + 'load' => route('scorm-player.scorm.load', $route_data), + ], + ]; + + $js_uri = route('scorm-player.javascript', [ + 'version' => substr(md5(filemtime(self::JS_PATH)), 10, 8) + ]); + + return view('scorm-player::player', compact( + 'sco', + 'scorm_api_data', + 'js_uri' + )); + } + + public function serveModule(string $uuid, string $path) + { + $path = Storage::disk(config('scorm.disk'))->path("{$uuid}/{$path}"); + $mime = MimeType::from($path); + + try { + return response()->file($path, [ + 'content-type' => $mime, + ]); + } + catch(FileNotFoundException $e) { + abort(404); + } + } + + public function scormLoad(ScormSco $sco) + { + $user = Auth::user(); + + $tracking = ScormScoTracking::where([ + 'sco_id' => $sco->id, + 'user_id' => $user->id, + ])->first(); + + if(!$tracking) { + $tracking = new ScormScoTracking([ + 'uuid' => Str::uuid(), + 'progression' => 0, + ]); + $tracking->user()->associate($user); + $tracking->sco_id = $sco->id; + $tracking->save(); + } + + $commit_url = route('scorm-player.scorm.commit', [ + 'tracking' => $tracking->id, + ]); + + $scorm_entry = route('scorm-player.serve', [ + 'uuid' => $sco->scorm->uuid, + 'path' => $sco->entry_url, + ]); + + return [ + 'tracking_id' => $tracking->id, + 'tracking' => $tracking->getCMIData(), + 'entry_url' => $scorm_entry, + 'commit_url' => $commit_url, + ]; + } + + public function scormCommit(Request $request, ScormScoTracking $tracking) + { + $data = $request->all(); + + $tracking->setCMIData($data); + + return [ + 'result' => true, + ]; + } + + public function jsSource(Request $request) + { + return response()->file(self::JS_PATH, [ + 'Content-Type' => 'application/javascript', + ]); + } + +} diff --git a/src/Http/Controllers/ScormPlayerController.php b/src/Http/Controllers/ScormPlayerController.php deleted file mode 100644 index 179e78f..0000000 --- a/src/Http/Controllers/ScormPlayerController.php +++ /dev/null @@ -1,121 +0,0 @@ -query('sco'); - $sco = $module->scos()->findOrFail($sco); - - $route_data = ['sco' => $sco]; - $scorm_api_data = [ - 'routes' => [ - 'load' => route('scorm-player.scorm.load', $route_data), - ], - ]; - - $js_uri = route('scorm-player.javascript', [ - 'version' => substr(md5(filemtime(self::JS_PATH)), 10, 8) - ]); - - return view('scorm-player::player', compact( - 'sco', - 'scorm_api_data', - 'js_uri' - )); - } - - public function serveModule(string $uuid, string $path) - { - $path = Storage::disk(config('scorm.disk'))->path("{$uuid}/{$path}"); - $mime = MimeType::from($path); - - try { - return response()->file($path, [ - 'content-type' => $mime, - ]); - } - catch(FileNotFoundException $e) { - abort(404); - } - } - - public function scormLoad(ScormSco $sco) - { - $user = Auth::user(); - - $tracking = ScormScoTracking::where([ - 'sco_id' => $sco->id, - 'user_id' => $user->id, - ])->first(); - - if(!$tracking) { - $tracking = new ScormScoTracking([ - 'uuid' => Str::uuid(), - 'progression' => 0, - ]); - $tracking->user()->associate($user); - $tracking->sco_id = $sco->id; - $tracking->save(); - } - - $commit_url = route('scorm-player.scorm.commit', [ - 'tracking' => $tracking->id, - ]); - - $scorm_entry = route('scorm-player.serve', [ - 'uuid' => $sco->scorm->uuid, - 'path' => $sco->entry_url, - ]); - - return [ - 'tracking_id' => $tracking->id, - 'tracking' => $tracking->getCMIData(), - 'entry_url' => $scorm_entry, - 'commit_url' => $commit_url, - ]; - } - - public function scormCommit(Request $request, ScormScoTracking $tracking) - { - $data = $request->all(); - - $tracking->setCMIData($data); - - return [ - 'result' => true, - ]; - } - - public function jsSource(Request $request) - { - return response()->file(self::JS_PATH, [ - 'Content-Type' => 'application/javascript', - //'Cache-Control' => $cacheControl, - //'ETag' => $etag, - ]); - } - -} -- cgit v1.2.3