Skip to content

Commit

Permalink
ajout gestion translate
Browse files Browse the repository at this point in the history
  • Loading branch information
stephaned-exatech committed Sep 3, 2020
1 parent 925f6f5 commit 14b951a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions routes/laravel-h5p.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
Route::get('ajax/finish', 'Djoudi\LaravelH5p\Http\Controllers\AjaxController@finish')->name('h5p.ajax.finish');
Route::post('ajax/content-user-data', 'Djoudi\LaravelH5p\Http\Controllers\AjaxController@contentUserData')->name('h5p.ajax.content-user-data');
Route::get('ajax/content-user-data', 'Djoudi\LaravelH5p\Http\Controllers\AjaxController@contentUserData')->name('h5p.ajax.content-user-data');
Route::post('ajax/translations', 'Djoudi\LaravelH5p\Http\Controllers\AjaxController@getTranslations')->name('h5p.ajax.translation');

Route::get('h5p/embed/{id}', 'Djoudi\LaravelH5p\Http\Controllers\EmbedController')->name('h5p.embed');
Route::get('h5p/export/{id}', 'Djoudi\LaravelH5p\Http\Controllers\DownloadController')->name('h5p.export');
Expand Down
18 changes: 17 additions & 1 deletion src/LaravelH5p/Http/Controllers/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Djoudi\LaravelH5p\Http\Controllers;

use DB;
use App\Http\Controllers\Controller;
use Djoudi\LaravelH5p\Events\H5pEvent;
use Djoudi\LaravelH5p\LaravelH5p;
Expand Down Expand Up @@ -71,6 +72,21 @@ public function files(Request $request)
$editor->ajax->action(H5PEditorEndpoints::FILES, $request->get('_token'), $request->get('contentId'));
}

public function getTranslations(Request $request){
$res = [];
$language = $request->language;
$lib = str_replace(' ', '.',$request->libraries[0]);
$lib = explode(".", $lib);
$library = DB::select('SELECT hl.id FROM h5p_libraries hl WHERE hl.name = ? AND hl.major_version = ? AND hl.minor_version = ?', [$lib[0].'.'.$lib[1], $lib[2], $lib[3]]);
$library_id = $library[0]->id;

$contents = DB::select('SELECT hll.translation FROM h5p_libraries_languages hll WHERE hll.library_id = ? AND hll.language_code = ?', [$library_id, $language]);
$translation = $contents[0]->translation;

$res['data'][$request->libraries[0]][] = $translation;
return $res;
}

public function __invoke(Request $request)
{
return response()->json($request->all());
Expand Down Expand Up @@ -212,7 +228,7 @@ public function finish(Request $request)
$json = json_decode($contents);
if(isset($json->interactiveVideo)){
foreach($json->interactiveVideo->assets->interactions as $interaction){
if($interaction->libraryTitle == 'Multiple Choice'){
if(isset($interaction->libraryTitle) && $interaction->libraryTitle == 'Multiple Choice'){
$interaction->action->subContentId;

$child = \Djoudi\LaravelH5p\Eloquents\H5pResult::firstOrCreate(['content_id' => $h5p_id, 'subcontent_id' => $interaction->action->subContentId, 'user_id' => $user_id], ['opened'=>now(), 'score'=>0, 'max_score'=>1]);
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelH5p/Storages/EditorStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function alterLibraryFiles(&$files, $libraries)
}

public function getAvailableLanguages($machineName, $majorVersion, $minorVersion){
return ['en'];
return ['en', 'fr'];
}

public function getLanguage($machineName, $majorVersion, $minorVersion, $language)
Expand Down

0 comments on commit 14b951a

Please sign in to comment.