]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6180 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 27 Jul 2023 15:37:10 +0000 (17:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 27 Jul 2023 15:37:10 +0000 (17:37 +0200)
app/Http/Controllers/Admin/Operations/Quiz/ImportOperation.php [deleted file]
app/Models/Quiz.php
resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php [deleted file]

diff --git a/app/Http/Controllers/Admin/Operations/Quiz/ImportOperation.php b/app/Http/Controllers/Admin/Operations/Quiz/ImportOperation.php
deleted file mode 100644 (file)
index 7c6168c..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Admin\Operations\Quiz;
-
-
-use App\Models\Quiz;
-use App\Models\QuizTranslation;
-use Cubist\Util\Files\Files;
-use Illuminate\Support\Facades\Route;
-use Prologue\Alerts\Facades\Alert;
-use ZipArchive;
-
-// __('!! e-Learning')
-
-trait ImportOperation
-{
-    protected function setupImportRoutes($segment, $routeName, $controller)
-    {
-        Route::match(['post'], $segment . '/import', $controller . '@import');
-    }
-
-    protected function setupImportDefaults()
-    {
-        $this->crud->addButtonFromView('top', 'import', 'quiz.import', 'end');
-    }
-
-    protected function import()
-    {
-        $files = $_FILES['file']['tmp_name'];
-
-        if (!count($files)) {
-            Alert::warning('No file were imported')->flash();
-            return;
-        }
-
-        $default = ['title' => '',
-            'translation' => '1',
-            'scorm' => '1',
-            'review' => 'always',
-            'instantReview' => '1',
-            'threshold' => '0',
-            'owner' => auth()->user()->id];
-
-        foreach (Quiz::getColors() as $name => $color) {
-            $default[$name] = $color['default'];
-        }
-
-        foreach (Quiz::getMessages() as $name => $message) {
-            $default[$name] = '';
-        }
-
-
-        $j = 0;
-        foreach ($files as $file) {
-            $z = new ZipArchive();
-            $ok = $z->open($file);
-            if ($ok !== true) {
-                Alert::warning('Unable to open ' . $file)->flash();
-                continue;
-            }
-
-
-            $data = [];
-            $datacontent = $z->getFromName('data.xml');
-            if (!$datacontent || stripos($datacontent, '<quiz') === false) {
-                Alert::warning($file . ' doesn\'t seem to be a valid quiz')->flash();
-                continue;
-            }
-            $x = simplexml_load_string($datacontent, "SimpleXMLElement", LIBXML_NOERROR | LIBXML_ERR_NONE);
-
-            // Discover translation
-            $validatetrans = $x->xpath('/quiz/translations/validateAnswer');
-            if ($validatetrans) {
-                $validatetrans = (string)$validatetrans[0];
-                $translation = QuizTranslation::where('validateAnswer', '=', $validatetrans)->first();
-                if ($translation) {
-                    $data['translation'] = $translation->id;
-                }
-            }
-            // Handle message from XML
-            foreach (Quiz::getMessages() as $name => $message) {
-                $e = $x->xpath('/quiz/' . $name);
-                if (!$e) {
-                    continue;
-                }
-                $m = (string)$e[0];
-                // We only define the message if different from the translation default
-                if (isset($translation) && $translation->$name !== $m) {
-                    $data[$name] = $m;
-                }
-            }
-
-            // Handle other attributes from XML
-            $attributes = ['title', 'review', 'thresehold'];
-            foreach (Quiz::getColors() as $name => $color) {
-                $attributes[] = $name;
-            }
-            foreach (Quiz::getActions() as $name => $action) {
-                $attributes[] = $name;
-            }
-            foreach ($attributes as $attribute => $xpath) {
-                if (is_int($attribute)) {
-                    $attribute = $xpath;
-                    $xpath = '/quiz/' . $xpath;
-                }
-                $e = $x->xpath($xpath);
-                if (!$e) {
-                    continue;
-                }
-                $data[$attribute] = (string)$e[0];
-            }
-
-            // Handle Questions
-            $xquestions = $x->xpath('/quiz/questions/question');
-            $questions = [];
-            foreach ($xquestions as $xquestion) {
-                $q = [
-                    'type' => 'multiple',
-                    'count_for_score' => true,
-                    'report_label' => '',
-                    'placeholder' => '',
-                    'min_score' => 0,
-                    'question' => (string)$xquestion->label,
-                    'explaination' => (string)$xquestion->correction,
-                    'multiple' => isset($xquestion['multiple']) ? (bool)$xquestion['multiple'] : false,
-                    'answers' => [],
-                ];
-                foreach ($xquestion->answers[0]->answer as $xanswer) {
-                    $q['answers'][] = [
-                        'answer' => (string)$xanswer,
-                        'correct' => isset($xanswer['correct']) ? (bool)$xanswer['correct'] : false,
-                    ];
-                }
-                $questions[] = $q;
-
-            }
-            $data['questions'] = $questions;
-            $data = array_merge($default, $data);
-
-            /** @var Quiz $q */
-            $q = new Quiz();
-            $q = $q->create($data);
-
-            $temp = Files::tmpdir();
-            $assets = ['logo' => 'logo.png', 'banner' => 'banner.jpg'];
-            foreach ($assets as $field => $asset) {
-                $f = $temp . '/' . $asset;
-                $c = $z->getFromName('assets/' . $asset);
-                if ($c) {
-                    file_put_contents($f, $c);
-                    $q->addMediaToField($field, $f);
-                }
-            }
-            $z->close();
-            $j++;
-        }
-
-
-        if ($j === 0) {
-            Alert::warning('No quiz were imported')->flash();
-        } else {
-            Alert::success('<b>' . $j . ' quiz(zes)</b> were imported')->flash();
-        }
-        return redirect($this->crud->route);
-    }
-}
index ef5953e5066ff1a0e2d5b654c7f37105695e7cc4..adb0707f8d9a5346e118e1843675dd45109782d4 100644 (file)
@@ -6,7 +6,6 @@ use App\Elearning\QuizCompiler;
 use App\Fields\SCORMVersion;
 use App\Http\Controllers\Admin\Operations\ChangeownerOperation;
 use App\Http\Controllers\Admin\Operations\Quiz\DownloadOperation;
-use App\Http\Controllers\Admin\Operations\Quiz\ImportOperation;
 use App\Http\Controllers\Admin\Operations\Quiz\LogOperation;
 use App\Http\Controllers\Admin\Operations\Quiz\PreviewOperation;
 use App\Http\Controllers\Admin\Operations\Quiz\ReportOperation;
@@ -43,7 +42,7 @@ class Quiz extends ToolboxModel
 
     public $registerMediaConversionsUsingModelInstance = false;
 
-    protected $_operations = [PreviewOperation::class, DownloadOperation::class, LogOperation::class, ReportOperation::class, ImportOperation::class, ChangeownerOperation::class];
+    protected $_operations = [PreviewOperation::class, DownloadOperation::class, LogOperation::class, ReportOperation::class,  ChangeownerOperation::class];
 
     use SCORMVersionTrait;
 
diff --git a/resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php b/resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php
deleted file mode 100644 (file)
index c3ec7e6..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-{{-- __('!! e-Learning') --}}
-<form method="post" enctype="multipart/form-data" action="{{$crud->route}}/import"
-      style="visibility:hidden;height:1px;position:absolute;top:0;" id="uploadimportform">
-    @csrf
-    <input type="file" name="file[]" multiple="multiple" id="uploadimport" accept="application/zip">
-</form>
-<a class="btn btn-primary" href="#" data-toggle="tooltip" title="Import" id="uploadimportbutton"><i
-        class="la la-upload"></i> {{__('Importer')}}</a>
-
-
-@push('after_scripts')
-    <script>
-        (function ($) {
-            $(function () {
-                $(document).on('click', "#uploadimportbutton", function () {
-                    $("#uploadimport").click();
-                    return false;
-                });
-
-                $(document).on('change', '#uploadimportform', function () {
-                    $("#uploadimportform").submit();
-                });
-            });
-        })(jQuery);
-    </script>
-@endpush