From 9c0d4be990564491202238b983c93322d00eba66 Mon Sep 17 00:00:00 2001 From: rldhont Date: Wed, 25 Dec 2024 18:59:09 +0100 Subject: [PATCH] Edition --- .../lizmap/classes/qgisVectorLayer.class.php | 15 +++------- .../lizmap/controllers/edition.classic.php | 29 +++++++++++++++++-- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php b/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php index c09ebd3ba6..7d9ebf042f 100644 --- a/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php +++ b/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php @@ -1248,20 +1248,13 @@ public function editableFeatures() return $restricted_empty_data; } - // Get data - $wfsData = $result->getBodyAsString(); - - // Check data: if there is no data returned by WFS, the user has not access to it - if (!$wfsData) { - return $restricted_empty_data; - } - - // Get data from layer - $wfsData = json_decode($wfsData); + // Features as iterator + $featureStream = Psr7\StreamWrapper::getResource($result->getBodyAsStream()); + $features = \JsonMachine\Items::fromStream($featureStream, array('pointer' => '/features')); return array( 'status' => 'restricted', - 'features' => $wfsData->features, + 'features' => $features, ); } diff --git a/lizmap/modules/lizmap/controllers/edition.classic.php b/lizmap/modules/lizmap/controllers/edition.classic.php index 5b4f02c681..580632284e 100644 --- a/lizmap/modules/lizmap/controllers/edition.classic.php +++ b/lizmap/modules/lizmap/controllers/edition.classic.php @@ -10,6 +10,7 @@ * @license Mozilla Public License : http://www.mozilla.org/MPL/ */ +use GuzzleHttp\Psr7; use Lizmap\Form; class editionCtrl extends jController @@ -1457,9 +1458,31 @@ public function editableFeatures() return $rep; } - $rep->data['success'] = true; - $rep->data['message'] = 'Success'; - $rep->data = array_merge($rep->data, $layer->editableFeatures()); + /** @var jResponseBinary $rep */ + $rep = $this->getResponse('binary'); + + $rep->outputFileName = 'editableFeatures.json'; + $rep->doDownload = false; + + $editableFeatures = $layer->editableFeatures(); + + $rep->setContentCallback(function () use ($editableFeatures) { + $output = Psr7\Utils::streamFor(fopen('php://output', 'w+')); + $input = Psr7\Utils::streamFor(function () use ($editableFeatures) { + $data = array(); + $data['success'] = true; + $data['message'] = 'Success'; + $data['status'] = $editableFeatures['status']; + + yield trim(json_encode($data, JSON_PRETTY_PRINT), '}').', "features": ['; + foreach ($editableFeatures['features'] as $feat) { + yield json_encode($feat); + } + + yield ']}'; + }); + Psr7\Utils::copyToStream($input, $output); + }); return $rep; }