]> _ Git - fluidbook-toolbox.git/commitdiff
fix #3473 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 6 Mar 2020 14:57:28 +0000 (15:57 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 6 Mar 2020 14:57:28 +0000 (15:57 +0100)
app/Http/Controllers/Admin/Operations/ImportOperation.php
app/Models/Quiz.php
composer.json
composer.lock
config/backpack/base.php
resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php

index 79c4b98f59db22be0c3eafa128989948aff1e45d..ccfba2b9bbd682174df0296021239b48f1383da5 100644 (file)
@@ -3,7 +3,12 @@
 namespace App\Http\Controllers\Admin\Operations;
 
 
+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;
 
 trait ImportOperation
 {
@@ -12,12 +17,137 @@ trait ImportOperation
         Route::match(['post'], $segment . '/import', $controller . '@import');
     }
 
-    protected function setupImportDefaults(){
+    protected function setupImportDefaults()
+    {
         $this->crud->addButtonFromView('top', 'import', 'quiz.import', 'end');
     }
 
     protected function import()
     {
-    }
+        $files = $_FILES['file']['tmp_name'];
+
+        if (!count($files)) {
+            return;
+        }
+
+        $default = ['title' => '',
+            'translation' => 'en',
+            'scorm' => '1',
+            'review' => '1',
+            'threshold' => '0',
+            'owner' => auth()->user()->id];
+
+        foreach (Quiz::getColors() as $name => $color) {
+            $default[$name] = $color['value'];
+        }
+
+        foreach (Quiz::getMessages() as $name => $message) {
+            $default[$name] = '';
+        }
+
+
+        $j = 0;
+        foreach ($files as $file) {
+            $z = new ZipArchive();
+            $ok = $z->open($file);
+            if ($ok !== true) {
+                continue;
+            }
+
 
+            $data = [];
+            $datacontent = $z->getFromName('data.xml');
+            if (!$datacontent || !stristr($datacontent, '<quiz>')) {
+                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();
+                $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 = [
+                    '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 376cb9daccaabe8dcb4dfdc8cca108a968e57617..e7323b96e277cea93b5382f0fdb6ac5bf7ec81f0 100644 (file)
@@ -210,6 +210,16 @@ class Quiz extends CubistMagicAbstractModel
         return self::$_messages;
     }
 
+    public static function getColors()
+    {
+        return self::$_colors;
+    }
+
+    public static function getActions()
+    {
+        return self::$_actions;
+    }
+
     public function create(array $data)
     {
         if (!can('viewany')) {
index b40c28146a168fe3c6b377599af19adf5c0ef642..dce4071abc3d088f4a993df03b28f43568989663 100644 (file)
@@ -1,7 +1,7 @@
 {
-    "name": "cubedesigners/quizfactory",
+    "name": "fluidbook/toolbox",
     "type": "project",
-    "description": "Cubedesigners Quiz Factory",
+    "description": "Fluidbook Toolbox",
     "keywords": [
         "framework",
         "laravel"
@@ -17,7 +17,9 @@
         "php": ">=7.4",
         "cubist/cms-back": "dev-master",
         "league/csv": "^9.5",
-        "ext-tidy": "*"
+        "ext-tidy": "*",
+        "ext-zip": "*",
+        "ext-simplexml": "*"
     },
     "require-dev": {
         "facade/ignition": "^1.4",
index 122ad746544907962ee0f40eaf86113a2d1f6955..907f3e865f5e80ca71f2dac1c374704360c79541 100644 (file)
@@ -4,20 +4,20 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "7f40e4b7c7756bcc6128cbd06a2cef11",
+    "content-hash": "9f466bce11f6280d9088ae7a50e7050a",
     "packages": [
         {
             "name": "backpack/backupmanager",
-            "version": "2.0.3",
+            "version": "v2.0.4",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Laravel-Backpack/BackupManager.git",
-                "reference": "95d847b86663dbaad11c3621edffe48e1a97b3aa"
+                "reference": "f64b252bfff38d7ed689a8978cc8e32cbc1c87da"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Laravel-Backpack/BackupManager/zipball/95d847b86663dbaad11c3621edffe48e1a97b3aa",
-                "reference": "95d847b86663dbaad11c3621edffe48e1a97b3aa",
+                "url": "https://api.github.com/repos/Laravel-Backpack/BackupManager/zipball/f64b252bfff38d7ed689a8978cc8e32cbc1c87da",
+                "reference": "f64b252bfff38d7ed689a8978cc8e32cbc1c87da",
                 "shasum": ""
             },
             "require": {
@@ -25,7 +25,7 @@
                 "spatie/laravel-backup": "^6.0"
             },
             "require-dev": {
-                "phpunit/phpunit": "4.*",
+                "phpunit/phpunit": "^9.0||^7.0",
                 "scrutinizer/ocular": "~1.1"
             },
             "type": "library",
                 "tabacitu",
                 "updivision"
             ],
-            "time": "2020-01-14T12:53:18+00:00"
+            "time": "2020-03-05T10:34:42+00:00"
         },
         {
             "name": "backpack/crud",
-            "version": "4.0.44",
+            "version": "4.0.48",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Laravel-Backpack/CRUD.git",
-                "reference": "1b76b0a41e7ae0b0e1d9b200cf2a98b64deab1f7"
+                "reference": "47f65fb68e78e7b535e76a109301a269bb35fdf8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Laravel-Backpack/CRUD/zipball/1b76b0a41e7ae0b0e1d9b200cf2a98b64deab1f7",
-                "reference": "1b76b0a41e7ae0b0e1d9b200cf2a98b64deab1f7",
+                "url": "https://api.github.com/repos/Laravel-Backpack/CRUD/zipball/47f65fb68e78e7b535e76a109301a269bb35fdf8",
+                "reference": "47f65fb68e78e7b535e76a109301a269bb35fdf8",
                 "shasum": ""
             },
             "require": {
@@ -92,7 +92,8 @@
                 "laravel/helpers": "^1.1",
                 "nesbot/carbon": "^2.14",
                 "ocramius/package-versions": "^1.4",
-                "prologue/alerts": "^0.4.1"
+                "prologue/alerts": "^0.4.1",
+                "venturecraft/revisionable": "1.*"
             },
             "require-dev": {
                 "orchestra/database": "^5.0@dev|3.8.x-dev",
                 "read",
                 "update"
             ],
-            "time": "2020-03-04T15:15:16+00:00"
+            "time": "2020-03-06T08:15:38+00:00"
         },
         {
             "name": "backpack/logmanager",
-            "version": "3.0.3",
+            "version": "v3.0.4",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Laravel-Backpack/LogManager.git",
-                "reference": "7aea77e4207891fe17359cb5298a9c490713d393"
+                "reference": "06d106dec2c024b41f7883efccf9be5ea8855b80"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Laravel-Backpack/LogManager/zipball/7aea77e4207891fe17359cb5298a9c490713d393",
-                "reference": "7aea77e4207891fe17359cb5298a9c490713d393",
+                "url": "https://api.github.com/repos/Laravel-Backpack/LogManager/zipball/06d106dec2c024b41f7883efccf9be5ea8855b80",
+                "reference": "06d106dec2c024b41f7883efccf9be5ea8855b80",
                 "shasum": ""
             },
             "require": {
                 "backpack/crud": "^4.0.0"
             },
             "require-dev": {
-                "phpunit/phpunit": "4.*",
+                "phpunit/phpunit": "^9.0||^7.0",
                 "scrutinizer/ocular": "~1.1"
             },
             "type": "library",
                 "log manager",
                 "logs"
             ],
-            "time": "2020-01-14T12:56:02+00:00"
+            "time": "2020-03-05T09:57:11+00:00"
         },
         {
             "name": "backpack/permissionmanager",
-            "version": "5.0.6",
+            "version": "5.0.7",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Laravel-Backpack/PermissionManager.git",
-                "reference": "4ddfbc91c1536c3e0a7a4d0379ebfe24eb859a46"
+                "reference": "032051df0ed1b638c5afcc9bccc93c8162261f17"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Laravel-Backpack/PermissionManager/zipball/4ddfbc91c1536c3e0a7a4d0379ebfe24eb859a46",
-                "reference": "4ddfbc91c1536c3e0a7a4d0379ebfe24eb859a46",
+                "url": "https://api.github.com/repos/Laravel-Backpack/PermissionManager/zipball/032051df0ed1b638c5afcc9bccc93c8162261f17",
+                "reference": "032051df0ed1b638c5afcc9bccc93c8162261f17",
                 "shasum": ""
             },
             "require": {
                 "spatie/laravel-permission": "^3.0"
             },
             "require-dev": {
-                "phpunit/phpunit": "4.*",
+                "phpunit/phpunit": "^9.0||^7.0",
                 "scrutinizer/ocular": "~1.1"
             },
             "type": "library",
                 "updivision",
                 "users roles admin"
             ],
-            "time": "2020-01-15T15:50:58+00:00"
+            "time": "2020-03-05T07:55:03+00:00"
         },
         {
             "name": "barryvdh/laravel-debugbar",
             "source": {
                 "type": "git",
                 "url": "git://git.cubedesigners.com/cubist_cms-back.git",
-                "reference": "593264b8a54381a029e99c88f7cdf49b10691a9b"
+                "reference": "0ebab60a4cf0464f46226d118538c892955bf785"
             },
             "dist": {
                 "type": "tar",
-                "url": "https://composer.cubedesigners.com/dist/cubist/cms-back/cubist-cms-back-dev-master-506b1e.tar",
-                "reference": "593264b8a54381a029e99c88f7cdf49b10691a9b",
-                "shasum": "328edcd2927af952ab2a1cf219f3ab7ecc727cb6"
+                "url": "https://composer.cubedesigners.com/dist/cubist/cms-back/cubist-cms-back-dev-master-c05cd0.tar",
+                "reference": "0ebab60a4cf0464f46226d118538c892955bf785",
+                "shasum": "1f70525f7ab8ada118bd6b46135dc2a123005588"
             },
             "require": {
                 "backpack/backupmanager": "^2.0",
                 }
             ],
             "description": "Cubist Backpack extension",
-            "time": "2020-03-04T18:41:48+00:00"
+            "time": "2020-03-05T17:17:26+00:00"
         },
         {
             "name": "cubist/cms-front",
             "source": {
                 "type": "git",
                 "url": "git://git.cubedesigners.com/cubist_util.git",
-                "reference": "889dce97b7be538f122486165e32807d7ec332e4"
+                "reference": "d6969d9f389e215d2b042e420d8fb7372028b808"
             },
             "dist": {
                 "type": "tar",
-                "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-497846.tar",
-                "reference": "889dce97b7be538f122486165e32807d7ec332e4",
-                "shasum": "aa11551a0769d77bf2af913503597ae5d7d34cfe"
+                "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-5892da.tar",
+                "reference": "d6969d9f389e215d2b042e420d8fb7372028b808",
+                "shasum": "39216acabf0de43584e1fff02548df0b43aa05b8"
             },
             "require": {
                 "cubist/net": "dev-master",
                 }
             ],
             "description": "Utilities class",
-            "time": "2020-01-28T17:54:27+00:00"
+            "time": "2020-03-06T14:14:31+00:00"
         },
         {
             "name": "cviebrock/eloquent-sluggable",
         },
         {
             "name": "cviebrock/laravel-elasticsearch",
-            "version": "4.1.3",
+            "version": "4.2.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/cviebrock/laravel-elasticsearch.git",
-                "reference": "a4cc45d7e6e81ec9e3a93ce53d80af67e5faa472"
+                "reference": "ce8c890250df72e226dff9ee28d072361f686465"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/cviebrock/laravel-elasticsearch/zipball/a4cc45d7e6e81ec9e3a93ce53d80af67e5faa472",
-                "reference": "a4cc45d7e6e81ec9e3a93ce53d80af67e5faa472",
+                "url": "https://api.github.com/repos/cviebrock/laravel-elasticsearch/zipball/ce8c890250df72e226dff9ee28d072361f686465",
+                "reference": "ce8c890250df72e226dff9ee28d072361f686465",
                 "shasum": ""
             },
             "require": {
                 "elasticsearch/elasticsearch": "^7.0",
-                "illuminate/contracts": "~5.8.0|^6.0",
-                "illuminate/support": "~5.8.0|^6.0",
-                "php": "^7.2"
+                "illuminate/contracts": "^6.0|^7.0",
+                "illuminate/support": "^6.0|^7.0",
+                "php": "^7.2.5"
             },
             "require-dev": {
                 "limedeck/phpunit-detailed-printer": "^5.0",
-                "orchestra/testbench": "~3.8.0|~4.0",
+                "orchestra/testbench": "^4.0|^5.0",
                 "phpunit/phpunit": "^8.0"
             },
             "suggest": {
                 "laravel",
                 "search"
             ],
-            "time": "2020-02-09T23:12:47+00:00"
+            "time": "2020-03-05T02:28:17+00:00"
         },
         {
             "name": "doctrine/cache",
         },
         {
             "name": "ocramius/package-versions",
-            "version": "1.5.1",
+            "version": "1.7.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/Ocramius/PackageVersions.git",
-                "reference": "1d32342b8c1eb27353c8887c366147b4c2da673c"
+                "reference": "651c372efc914aea8223e049f85afaf65e09ba23"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/1d32342b8c1eb27353c8887c366147b4c2da673c",
-                "reference": "1d32342b8c1eb27353c8887c366147b4c2da673c",
+                "url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/651c372efc914aea8223e049f85afaf65e09ba23",
+                "reference": "651c372efc914aea8223e049f85afaf65e09ba23",
                 "shasum": ""
             },
             "require": {
-                "composer-plugin-api": "^1.0.0",
-                "php": "^7.3.0"
+                "composer-plugin-api": "^1.1.0",
+                "php": "^7.4.0"
             },
             "require-dev": {
-                "composer/composer": "^1.8.6",
-                "doctrine/coding-standard": "^6.0.0",
-                "ext-zip": "*",
-                "infection/infection": "^0.13.4",
-                "phpunit/phpunit": "^8.2.5",
-                "vimeo/psalm": "^3.4.9"
+                "composer/composer": "^1.9.3",
+                "doctrine/coding-standard": "^7.0.2",
+                "ext-zip": "^1.15.0",
+                "infection/infection": "^0.15.3",
+                "phpunit/phpunit": "^9.0.1",
+                "vimeo/psalm": "^3.9.3"
             },
             "type": "composer-plugin",
             "extra": {
                 "class": "PackageVersions\\Installer",
                 "branch-alias": {
-                    "dev-master": "1.6.x-dev"
+                    "dev-master": "1.99.x-dev"
                 }
             },
             "autoload": {
                 }
             ],
             "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
-            "time": "2019-07-17T15:49:50+00:00"
+            "time": "2020-03-06T11:34:16+00:00"
         },
         {
             "name": "opis/closure",
         },
         {
             "name": "spatie/laravel-medialibrary",
-            "version": "7.19.1",
+            "version": "7.19.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/spatie/laravel-medialibrary.git",
-                "reference": "4cbe7c03df14015b6ea17338e642b1125142b86e"
+                "reference": "944f00a8e886abcb5e2166ae17660917a086368d"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/4cbe7c03df14015b6ea17338e642b1125142b86e",
-                "reference": "4cbe7c03df14015b6ea17338e642b1125142b86e",
+                "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/944f00a8e886abcb5e2166ae17660917a086368d",
+                "reference": "944f00a8e886abcb5e2166ae17660917a086368d",
                 "shasum": ""
             },
             "require": {
                 "media",
                 "spatie"
             ],
-            "time": "2020-03-04T17:01:00+00:00"
+            "time": "2020-03-04T19:00:40+00:00"
         },
         {
             "name": "spatie/laravel-missing-page-redirector",
         },
         {
             "name": "facade/ignition",
-            "version": "1.16.0",
+            "version": "1.16.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/facade/ignition.git",
-                "reference": "37f094775814b68d0c6cc8b8ff3c3be243f20725"
+                "reference": "af05ac5ee8587395d7474ec0681c08776a2cb09d"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/facade/ignition/zipball/37f094775814b68d0c6cc8b8ff3c3be243f20725",
-                "reference": "37f094775814b68d0c6cc8b8ff3c3be243f20725",
+                "url": "https://api.github.com/repos/facade/ignition/zipball/af05ac5ee8587395d7474ec0681c08776a2cb09d",
+                "reference": "af05ac5ee8587395d7474ec0681c08776a2cb09d",
                 "shasum": ""
             },
             "require": {
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "v2.x-dev"
+                    "dev-master": "1.x-dev"
                 },
                 "laravel": {
                     "providers": [
                 "laravel",
                 "page"
             ],
-            "time": "2020-01-21T17:46:02+00:00"
+            "time": "2020-03-05T12:39:07+00:00"
         },
         {
             "name": "facade/ignition-contracts",
         },
         {
             "name": "phpspec/prophecy",
-            "version": "v1.10.2",
+            "version": "v1.10.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/phpspec/prophecy.git",
-                "reference": "b4400efc9d206e83138e2bb97ed7f5b14b831cd9"
+                "reference": "451c3cd1418cf640de218914901e51b064abb093"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/phpspec/prophecy/zipball/b4400efc9d206e83138e2bb97ed7f5b14b831cd9",
-                "reference": "b4400efc9d206e83138e2bb97ed7f5b14b831cd9",
+                "url": "https://api.github.com/repos/phpspec/prophecy/zipball/451c3cd1418cf640de218914901e51b064abb093",
+                "reference": "451c3cd1418cf640de218914901e51b064abb093",
                 "shasum": ""
             },
             "require": {
                 "spy",
                 "stub"
             ],
-            "time": "2020-01-20T15:57:02+00:00"
+            "time": "2020-03-05T15:02:03+00:00"
         },
         {
             "name": "phpunit/php-code-coverage",
     "prefer-lowest": false,
     "platform": {
         "php": ">=7.4",
-        "ext-tidy": "*"
+        "ext-tidy": "*",
+        "ext-zip": "*",
+        "ext-simplexml": "*"
     },
     "platform-dev": []
 }
index 6d8b4f00ff30cfa37e7c771c4ccd8e3bc11cab19..19e029b1ff3a7b64534ee0ad02af337adb6d1713 100644 (file)
@@ -25,7 +25,7 @@ return [
     // ----
 
     // Project name. Shown in the window title.
-    'project_name' => 'Quiz Factory',
+    'project_name' => 'Fluidbook Toolbox',
 
     // When clicking on the admin panel's top-left logo/name,
     // where should the user be redirected?
index d4b8611a636b1a1aac84e362ba5447ed5d57e217..d642525760995acc6aa2ba0c2f2aef9f0035e446 100644 (file)
@@ -1,6 +1,7 @@
 <form method="post" enctype="multipart/form-data" action="{{$crud->route}}/import"
       style="visibility:hidden;height:1px;position:absolute;top:0;" id="uploadimportform">
-    <input type="file" name="file" multiple="multiple" id="uploadimport" accept="application/zip">
+    @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="fa fa-upload"></i> Import</a>