From: Vincent Vanwaelscappel Date: Fri, 6 Mar 2020 14:57:28 +0000 (+0100) Subject: fix #3473 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c33bb3211437e76c5476ed22019bda241e5fb3e5;p=fluidbook-toolbox.git fix #3473 @3 --- diff --git a/app/Http/Controllers/Admin/Operations/ImportOperation.php b/app/Http/Controllers/Admin/Operations/ImportOperation.php index 79c4b98f5..ccfba2b9b 100644 --- a/app/Http/Controllers/Admin/Operations/ImportOperation.php +++ b/app/Http/Controllers/Admin/Operations/ImportOperation.php @@ -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, '')) { + 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('' . $j . ' quiz(zes) were imported')->flash(); + } + return redirect($this->crud->route); + } } diff --git a/app/Models/Quiz.php b/app/Models/Quiz.php index 376cb9dac..e7323b96e 100644 --- a/app/Models/Quiz.php +++ b/app/Models/Quiz.php @@ -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')) { diff --git a/composer.json b/composer.json index b40c28146..dce4071ab 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 122ad7465..907f3e865 100644 --- a/composer.lock +++ b/composer.lock @@ -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", @@ -67,20 +67,20 @@ "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", @@ -153,27 +154,27 @@ "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", @@ -213,20 +214,20 @@ "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": { @@ -234,7 +235,7 @@ "spatie/laravel-permission": "^3.0" }, "require-dev": { - "phpunit/phpunit": "4.*", + "phpunit/phpunit": "^9.0||^7.0", "scrutinizer/ocular": "~1.1" }, "type": "library", @@ -288,7 +289,7 @@ "updivision", "users roles admin" ], - "time": "2020-01-15T15:50:58+00:00" + "time": "2020-03-05T07:55:03+00:00" }, { "name": "barryvdh/laravel-debugbar", @@ -919,13 +920,13 @@ "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", @@ -996,7 +997,7 @@ } ], "description": "Cubist Backpack extension", - "time": "2020-03-04T18:41:48+00:00" + "time": "2020-03-05T17:17:26+00:00" }, { "name": "cubist/cms-front", @@ -1244,13 +1245,13 @@ "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", @@ -1279,7 +1280,7 @@ } ], "description": "Utilities class", - "time": "2020-01-28T17:54:27+00:00" + "time": "2020-03-06T14:14:31+00:00" }, { "name": "cviebrock/eloquent-sluggable", @@ -1346,27 +1347,27 @@ }, { "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": { @@ -1406,7 +1407,7 @@ "laravel", "search" ], - "time": "2020-02-09T23:12:47+00:00" + "time": "2020-03-05T02:28:17+00:00" }, { "name": "doctrine/cache", @@ -3447,35 +3448,35 @@ }, { "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": { @@ -3494,7 +3495,7 @@ } ], "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", @@ -4773,16 +4774,16 @@ }, { "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": { @@ -4855,7 +4856,7 @@ "media", "spatie" ], - "time": "2020-03-04T17:01:00+00:00" + "time": "2020-03-04T19:00:40+00:00" }, { "name": "spatie/laravel-missing-page-redirector", @@ -7757,16 +7758,16 @@ }, { "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": { @@ -7793,7 +7794,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "v2.x-dev" + "dev-master": "1.x-dev" }, "laravel": { "providers": [ @@ -7824,7 +7825,7 @@ "laravel", "page" ], - "time": "2020-01-21T17:46:02+00:00" + "time": "2020-03-05T12:39:07+00:00" }, { "name": "facade/ignition-contracts", @@ -8731,16 +8732,16 @@ }, { "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": { @@ -8790,7 +8791,7 @@ "spy", "stub" ], - "time": "2020-01-20T15:57:02+00:00" + "time": "2020-03-05T15:02:03+00:00" }, { "name": "phpunit/php-code-coverage", @@ -10126,7 +10127,9 @@ "prefer-lowest": false, "platform": { "php": ">=7.4", - "ext-tidy": "*" + "ext-tidy": "*", + "ext-zip": "*", + "ext-simplexml": "*" }, "platform-dev": [] } diff --git a/config/backpack/base.php b/config/backpack/base.php index 6d8b4f00f..19e029b1f 100644 --- a/config/backpack/base.php +++ b/config/backpack/base.php @@ -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? diff --git a/resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php b/resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php index d4b8611a6..d64252576 100644 --- a/resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php +++ b/resources/views/vendor/backpack/crud/buttons/quiz/import.blade.php @@ -1,6 +1,7 @@ Import