]> _ Git - fluidbook-toolbox.git/commitdiff
Merge remote-tracking branch 'origin/backpack5' into backpack5
authorsoufiane <soufiane@cubedesigners.com>
Thu, 30 Nov 2023 14:37:15 +0000 (15:37 +0100)
committersoufiane <soufiane@cubedesigners.com>
Thu, 30 Nov 2023 14:37:15 +0000 (15:37 +0100)
# Conflicts:
# app/Console/Commands/FluidbookCollection.php
# app/Console/Commands/FluidbookPackage.php
# app/Console/Commands/WorkshopMigration.php
# app/Console/Kernel.php

1  2 
app/Http/Controllers/Admin/Operations/ContentTranslate/ExcelImportOperation.php
app/Jobs/Base.php
composer.lock
public/packages/fluidbook/toolbox/css/style.less

index bb0cf55f73eefb9f771992fdd21188faef86c266,0000000000000000000000000000000000000000..0421c7f8867374d39d186b299d505af2d2ad7e10
mode 100644,000000..100644
--- /dev/null
@@@ -1,75 -1,0 +1,75 @@@
-         return redirect($this->crud->route . '/1/edit/?locale=' . $locale);
 +<?php
 +
 +namespace App\Http\Controllers\Admin\Operations\ContentTranslate;
 +
 +use App\Models\FluidbookTranslate;
 +use App\Models\Quiz;
 +use App\Models\QuizTranslation;
 +use Cubist\Util\Files\Files;
 +use Illuminate\Support\Facades\Route;
 +use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
 +use PhpOffice\PhpSpreadsheet\RichText\RichText;
 +use Prologue\Alerts\Facades\Alert;
 +// __('!! Traduction de l\'interface fluidbook')
 +trait ExcelImportOperation
 +{
 +    protected function setupExcelImportRoutes($segment, $routeName, $controller)
 +    {
 +        Route::match(['post'], $segment . '/excel/import/{locale}', $controller . '@excelImport');
 +    }
 +
 +    /**
 +     * @throws \JsonException
 +     */
 +    protected function excelImport($locale)
 +    {
 +        $file = $_FILES['file'];
 +
 +        if ($file['error']) {
 +            Alert::warning('No file were imported')->flash();
 +            return;
 +        }
 +
 +        $reader = new Xlsx();
 +        $xls = $reader->load($file['tmp_name']);
 +        $sheet = $xls->getActiveSheet();
 +
 +        $class = get_class($this->getModelInstance());
 +
 +        $existingTranslation = $class::getLocaleTranslations($locale);
 +
 +
 +        $translations = [];
 +        $count = 0;
 +        $updated = 0;
 +        foreach ($sheet->getRowIterator(2) as $row) {
 +            $ri = $row->getRowIndex();
 +            $k = $sheet->getCellByColumnAndRow(1, $ri)->getValue();
 +            if (!FluidbookTranslate::isKey($k)) {
 +                continue;
 +            }
 +
 +            $v = $sheet->getCellByColumnAndRow(4, $ri)->getValue();
 +            if($v instanceof RichText){
 +                $v=$v->getPlainText();
 +            }
 +
 +            if (!isset($existingTranslation[$k]['translation']) || $v != $existingTranslation[$k]['translation']) {
 +                $translations[$k] = $v;
 +                $updated++;
 +            }
 +            $count++;
 +        }
 +
 +
 +        if (!$count) {
 +            Alert::warning('No translation were find')->flash();
 +        } elseif (!$updated) {
 +            Alert::warning('No translation were updated')->flash();
 +        } else {
 +            $class::updateTranslation($locale, $translations);
 +            Alert::success('<b>' . $updated . ' translations</b> were updated (' . $count . ' total)')->flash();
 +        }
++        return redirect($this->crud->route . '/1/edit/?_locale=' . $locale);
 +    }
 +}
Simple merge
diff --cc composer.lock
Simple merge