Skip to content

Commit

Permalink
Edition
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Dec 25, 2024
1 parent dfcf7de commit 9c0d4be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
15 changes: 4 additions & 11 deletions lizmap/modules/lizmap/classes/qgisVectorLayer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down
29 changes: 26 additions & 3 deletions lizmap/modules/lizmap/controllers/edition.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @license Mozilla Public License : http://www.mozilla.org/MPL/
*/

use GuzzleHttp\Psr7;
use Lizmap\Form;

class editionCtrl extends jController
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9c0d4be

Please sign in to comment.