From 5eba0307dbdd15d1a215419ff9fd3e3f96f99f0e Mon Sep 17 00:00:00 2001 From: Khaled Lela Date: Fri, 11 Feb 2022 20:30:36 +0200 Subject: handle publish scorm runtime exception msg key as translation under resources/lang/en-US/scorm.php --- resources/lang/en-US/scorm.php | 17 +++++++++++++++++ src/ScormServiceProvider.php | 25 +++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 resources/lang/en-US/scorm.php diff --git a/resources/lang/en-US/scorm.php b/resources/lang/en-US/scorm.php new file mode 100644 index 0000000..9eb1c89 --- /dev/null +++ b/resources/lang/en-US/scorm.php @@ -0,0 +1,17 @@ + 'Invalid SCORM version.', + 'no_sco_in_scorm_archive_message' => 'No items in SCORM archive.', + 'invalid_scorm_data' => 'Invalid SCORM data.', + 'cannot_load_imsmanifest_message' => 'Can not load SCORM manifest.', + 'invalid_scorm_manifest_identifier' => 'Invalid SCORM manifest identifier.', + 'scorm_disk_not_define' => 'SCORM disk not define', + + // SCORM Items/Children messages** + 'default_organization_not_found_message' => 'SCORM item default organization not found.', + 'no_organization_found_message' => 'No organization found.', + 'sco_with_no_identifier_message' => 'SCORM item without identifier.', + 'sco_resource_without_href_message' => 'SCORM item resource without entry link.', + 'sco_without_resource_message' => 'SCORM item without resource.' +]; diff --git a/src/ScormServiceProvider.php b/src/ScormServiceProvider.php index 1806775..b50adc4 100644 --- a/src/ScormServiceProvider.php +++ b/src/ScormServiceProvider.php @@ -13,7 +13,7 @@ class ScormServiceProvider extends ServiceProvider { public function register() { - $this->app->bind('scorm-manager', function($app) { + $this->app->bind('scorm-manager', function ($app) { return new ScormManager(); }); } @@ -23,19 +23,24 @@ class ScormServiceProvider extends ServiceProvider $this->offerPublishing(); } - protected function offerPublishing() { + protected function offerPublishing() + { // function not available and 'publish' not relevant in Lumen - if (! function_exists('config_path')) { + if (!function_exists('config_path')) { return; } $this->publishes([ - __DIR__.'/../config/scorm.php' => config_path('scorm.php'), + __DIR__ . '/../config/scorm.php' => config_path('scorm.php'), ], 'config'); $this->publishes([ - __DIR__.'/../database/migrations/create_scorm_tables.php.stub' => $this->getMigrationFileName('create_scorm_tables.php'), + __DIR__ . '/../database/migrations/create_scorm_tables.php.stub' => $this->getMigrationFileName('create_scorm_tables.php'), ], 'migrations'); + + $this->publishes([ + __DIR__ . '/../resources/lang/en-US/scorm.php' => resource_path('lang/en-US/scorm.php'), + ]); } /** @@ -49,14 +54,14 @@ class ScormServiceProvider extends ServiceProvider $filesystem = $this->app->make(Filesystem::class); - return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) + return Collection::make($this->app->databasePath() . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR) ->flatMap(function ($path) use ($filesystem) { - return $filesystem->glob($path.'*_create_scorm_tables.php'); - })->push($this->app->databasePath()."/migrations/{$timestamp}_create_scorm_tables.php") + return $filesystem->glob($path . '*_create_scorm_tables.php'); + })->push($this->app->databasePath() . "/migrations/{$timestamp}_create_scorm_tables.php") ->flatMap(function ($path) use ($filesystem, $migrationFileName) { - return $filesystem->glob($path.'*_'.$migrationFileName); + return $filesystem->glob($path . '*_' . $migrationFileName); }) - ->push($this->app->databasePath()."/migrations/{$timestamp}_{$migrationFileName}") + ->push($this->app->databasePath() . "/migrations/{$timestamp}_{$migrationFileName}") ->first(); } } -- cgit v1.2.3 From 7e58d0fda2b0db301e59703a652f5caf40f4718a Mon Sep 17 00:00:00 2001 From: Khaled Lela Date: Fri, 11 Feb 2022 20:31:17 +0200 Subject: update readme with translation part and usage example. --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b0dd5a2..2bef150 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ php artisan migrate ``` ## Step 5 (Optional): -update SCORM config under config/scorm +***Update SCORM config under `config/scorm`*** - update scorm table names. - update SCORM disk and configure disk @see config/filesystems.php ``` @@ -71,3 +71,55 @@ update SCORM config under config/scorm ..... ] ``` +***Update SCORM transaltions under `resources/lang/en-US`*** +- SCORM runtime errors exceptions handler, *(Check next example)* +- Copy and translate error msg with key for other locale as you wish. + +*After finishing don't forget to run `php artisan config:cache`* + + + + +## Step 6 (Optional): + +**Usage** +``` +class ScormController extends BaseController +{ + /** @var ScormManager $scormManager */ + private $scormManager; + /** + * ScormController constructor. + * @param ScormManager $scormManager + */ + public function __construct(ScormManager $scormManager) + { + $this->scormManager = $scormManager; + } + + public function show($id) + { + $item = ScormModel::with('scos')->findOrFail($id); + // response helper function from base controller reponse json. + return $this->respond($item); + } + + public function store(ScormRequest $request) + { + try { + $scorm = $this->scormManager->uploadScormArchive($request->file('file')); + // handle scorm runtime error msg + } catch (InvalidScormArchiveException | StorageNotFoundException $ex) { + return $this->respondCouldNotCreateResource(trans('scorm.' . $ex->getMessage())); + } + + // response helper function from base controller reponse json. + return $this->respond(ScormModel::with('scos')->whereUuid($scorm['uuid'])->first()); + } + + public function saveProgress(Request $request) + { + // TODO save user progress... + } +} +``` \ No newline at end of file -- cgit v1.2.3 From 591a429c110f89a8506b24632dd97f7ad20a6434 Mon Sep 17 00:00:00 2001 From: Khaled Lela Date: Fri, 11 Feb 2022 20:34:13 +0200 Subject: add extra scorm error translation key --- resources/lang/en-US/scorm.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/lang/en-US/scorm.php b/resources/lang/en-US/scorm.php index 9eb1c89..07a2c93 100644 --- a/resources/lang/en-US/scorm.php +++ b/resources/lang/en-US/scorm.php @@ -1,6 +1,7 @@ 'Invalid SCORM archive.', 'invalid_scorm_version_message' => 'Invalid SCORM version.', 'no_sco_in_scorm_archive_message' => 'No items in SCORM archive.', 'invalid_scorm_data' => 'Invalid SCORM data.', @@ -8,7 +9,7 @@ return [ 'invalid_scorm_manifest_identifier' => 'Invalid SCORM manifest identifier.', 'scorm_disk_not_define' => 'SCORM disk not define', - // SCORM Items/Children messages** + // SCORM Items/Children messages 'default_organization_not_found_message' => 'SCORM item default organization not found.', 'no_organization_found_message' => 'No organization found.', 'sco_with_no_identifier_message' => 'SCORM item without identifier.', -- cgit v1.2.3 From 616c2bc6baab2a72fc516abd8e7f1fc1dec1b56b Mon Sep 17 00:00:00 2001 From: Khaled Lela Date: Fri, 11 Feb 2022 20:42:19 +0200 Subject: update readme, typo fix --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 2bef150..fe02045 100644 --- a/README.md +++ b/README.md @@ -71,15 +71,13 @@ php artisan migrate ..... ] ``` -***Update SCORM transaltions under `resources/lang/en-US`*** +***Update SCORM translations under `resources/lang/en-US/scorm.php`*** - SCORM runtime errors exceptions handler, *(Check next example)* - Copy and translate error msg with key for other locale as you wish. *After finishing don't forget to run `php artisan config:cache`* - - ## Step 6 (Optional): **Usage** -- cgit v1.2.3 From 4a36318e1ba5b5d50afe0a7991168df26945f52d Mon Sep 17 00:00:00 2001 From: Khaled Lela Date: Sat, 12 Feb 2022 15:30:07 +0200 Subject: update scrom tables with missing columns --- database/migrations/create_scorm_tables.php.stub | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/database/migrations/create_scorm_tables.php.stub b/database/migrations/create_scorm_tables.php.stub index 6a136b3..cc9dc38 100644 --- a/database/migrations/create_scorm_tables.php.stub +++ b/database/migrations/create_scorm_tables.php.stub @@ -23,12 +23,12 @@ class CreateScormTables extends Migration Schema::create($tableNames['scorm_table'], function (Blueprint $table) { $table->bigIncrements('id'); $table->morphs('resource'); - $table->string('version'); - $table->string('hash_name'); + $table->string('title'); $table->string('origin_file')->nullable(); - $table->string('origin_file_mime')->nullable(); + $table->string('version'); $table->double('ratio')->nullable(); $table->string('uuid'); + $table->string('entry_url')->nullable(); $table->timestamps(); }); -- cgit v1.2.3