--- /dev/null
+<?php
+
+namespace App\Http\Controllers\Admin\Operations\Tools;
+// __('!! Outils')
+use App\Models\FluidbookReference;
+use Cubist\Backpack\Magic\Fields\Checkbox;
+use Cubist\Backpack\Magic\Fields\Code;
+use Cubist\Backpack\Magic\Fields\Integer;
+use Cubist\Backpack\Magic\Fields\SelectFromArray;
+use Cubist\Backpack\Magic\Fields\StandardFile;
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\Form;
+use Cubist\Excel\ExcelToArray;
+use Exception;
+use PhpOffice\PhpSpreadsheet\Reader\Csv;
+use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
+
+trait FluidbookReferencesURL
+{
+ use BaseTool;
+
+ protected static $_db = ['10doigts' => '10 doigts',
+ 'ascocelda' => 'Asco & Celda',
+ 'wesco' => 'Wesco',
+ 'mopec' => 'Mopec',
+ 'intex' => 'Intex',
+ 'grosfillex' => 'Grosfillex'];
+
+ public function fluidbookrefurl()
+ {
+ ksort(self::$_db);
+
+ $form = new Form(backpack_url('tools/dofluidbookrefurl'));
+ $form->setEnctype('multipart/form-data');
+ $form->setTitle(__('Importer une base de données de références Fluidbook'));
+ $form->setSubmitLabel(__('Importer'));
+ $form->setSubmitIcon('las la-link');
+ $form->addField('file', StandardFile::class, __('Base de données'), ['accept' => '.xlsx;.csv', 'hint' => __('Feuille Excel ou CSV contenant deux colonnes.') . ' ' . __('Colonne A : Référence') . ', ' . __('Colonne B : URL')]);
+ $form->addField('type', SelectFromArray::class, __('Importer dans'), ['default' => '10doigts', 'allows_null' => false, 'options' => self::$_db]);
+
+ return view('tools.form', ['form' => $form]);
+
+ }
+
+
+ public function dofluidbookrefurl()
+ {
+ global $core;
+
+
+ $file = request()->file('file');
+ $type = request('type');
+ if (!isset(self::$_db[$type])) {
+ abort(404, 'DB type not found');
+ }
+
+ if (strtolower($file->getClientOriginalExtension()) === 'xlsx') {
+ $reader = new Xlsx();
+ } else if (strtolower($file->getClientOriginalExtension()) === 'csv') {
+ $reader = new Csv();
+ $reader->setDelimiter(';');
+ }
+ $xls = $reader->load($file->getPathname());
+ $sheet = $xls->getSheet(0);
+ $maxRow = $sheet->getHighestRow('A');
+
+ $updated = 0;
+
+ $add = [];
+
+ for ($i = 1; $i <= $maxRow; $i++) {
+ $acell = $sheet->getCell('A' . $i);
+ $bcell = $sheet->getCell('B' . $i);
+ $ref = trim($acell->getOldCalculatedValue()) ?: trim($acell->getFormattedValue());
+ $url = trim($bcell->getOldCalculatedValue()) ?: trim($bcell->getFormattedValue());
+
+ if ($url == '' || $ref == '') {
+ continue;
+ }
+
+ $fref = self::_formatWsReferenceRef($ref, $type);
+ $furl = self::_formatWsReferenceUrl($url, $type);
+
+ $add[$fref] = $furl;
+ }
+
+ FluidbookReference::withoutGlobalScopes()->whereIn('ref', array_keys($add))->whereType($type)->forceDelete();
+
+ foreach ($add as $fref => $furl) {
+ $i = new FluidbookReference(['ref' => $fref, 'url' => $furl, 'type' => $type]);
+ $i->saveQuietly();
+ $updated++;
+ }
+ return $this->_success(__(':updated liens insérés ou mis à jour', ['updated' => $updated]));
+ }
+
+ public static function _formatWsReferenceRef($ref, $type)
+ {
+ if ($type === '10doigts') {
+ if (stripos($ref, 'ic') === 0) {
+ return 'C' . substr($ref, 2);
+ }
+ }
+ return $ref;
+ }
+
+ public static function _formatWsReferenceUrl($url, $type)
+ {
+ return $url;
+ }
+
+}
use App\Http\Controllers\Admin\Operations\Tools\FluidbookBranchCreate;
use App\Http\Controllers\Admin\Operations\Tools\FluidbookBranchRemove;
use App\Http\Controllers\Admin\Operations\Tools\FluidbookCopyLinks;
+use App\Http\Controllers\Admin\Operations\Tools\FluidbookReferencesURL;
use App\Http\Controllers\Admin\Operations\Tools\GitReposCreate;
use App\Http\Controllers\Admin\Operations\Tools\ImagesResizer;
use App\Http\Controllers\Admin\Operations\Tools\JSON2Excel;
-use App\Http\Controllers\Admin\Operations\Tools\PDF2SVGOperation;
use App\Http\Controllers\Admin\Operations\Tools\SVGCleaner;
use App\Http\Controllers\Admin\Operations\Tools\TextToSpeech;
use App\Http\Controllers\Controller;
use ImagesResizer;
use FluidbookCopyLinks;
use SVGCleaner;
+ use FluidbookReferencesURL;
+
protected function index($tool, $args = '')
{
--- /dev/null
+<?php
+
+namespace App\Models;
+
+use App\Models\Base\ToolboxModel;
+use Cubist\Backpack\Magic\Fields\Text;
+use Cubist\Backpack\Magic\Fields\URL;
+
+class FluidbookReference extends ToolboxModel
+{
+ protected $table = 'fluidbook_reference_url';
+ protected $_options = ['name' => 'fluidbook-reference-url',
+ 'singular' => 'référence',
+ 'plural' => 'références'];
+
+ static $_permissionBase = 'fluidbook-reference-url';
+
+ public function setFields()
+ {
+ parent::setFields();
+ $this->addField('ref', Text::class, __("Référence"));
+ $this->addField('type', Text::class, __("Type"));
+ $this->addField('url', URL::class, __('URL'));
+ }
+}