diff options
author | devianl2 <devianleong@gmail.com> | 2022-02-13 21:07:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-13 21:07:28 +0800 |
commit | 4a71aee0ab56a8450f5791554d06f544f6be1157 (patch) | |
tree | f899aaab754cf6708a823e33179b7167b3a6b079 | |
parent | 88d7940d4db9519c046f8c5375ef092da1daab35 (diff) | |
parent | 4a36318e1ba5b5d50afe0a7991168df26945f52d (diff) |
Merge pull request #11 from KhaledLela/handle_publish_translations3.0.2
Handle publish translations for scorm runtime exceptions handler
-rw-r--r-- | README.md | 52 | ||||
-rw-r--r-- | database/migrations/create_scorm_tables.php.stub | 6 | ||||
-rw-r--r-- | resources/lang/en-US/scorm.php | 18 | ||||
-rw-r--r-- | src/ScormServiceProvider.php | 25 |
4 files changed, 87 insertions, 14 deletions
@@ -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,53 @@ update SCORM config under config/scorm ..... ] ``` +***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** +``` +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 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(); }); diff --git a/resources/lang/en-US/scorm.php b/resources/lang/en-US/scorm.php new file mode 100644 index 0000000..07a2c93 --- /dev/null +++ b/resources/lang/en-US/scorm.php @@ -0,0 +1,18 @@ +<?php +return [ + // SCORM archive messages + 'invalid_scorm_archive_message' => '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.', + '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(); } } |