Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing QGIS Project with PHP XMLReader instead of DOM #4819

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
80da873
\Lizmap\App\XmlTools Docstring
rldhont Nov 3, 2023
e7ad3fb
Enhancing \Lizmap\App\XmlTools to get \XMLReader object
rldhont Nov 3, 2023
1bb5e58
Create QgisProjectParser to try parsing with \XMLReader
rldhont Oct 25, 2023
7cbf8ba
QgisProjectParser -> Lizmap\Project\Qgis\Parser
rldhont Sep 20, 2024
1da3129
Lizmap\Project\Qgis\BaseQgisObject class
rldhont Nov 8, 2023
c159383
Lizmap\Project\Qgis\BaseQgisXmlObject class
rldhont Nov 16, 2023
7db941d
New Lizmap\Project\Qgis\SpatialRefSys for QGIS Spatial Reference Syst…
rldhont Nov 7, 2023
87b8db9
New Lizmap\Project\Qgis\ProjectGuiProperties for QGIS Project Gui Pro…
rldhont Nov 8, 2023
59dcddf
New Lizmap\Project\Qgis\ProjectVariables for QGIS Project Variables
rldhont Nov 10, 2023
ad59f20
New Lizmap\Project\Qgis\ProjectProperties for QGIS Project Properties
rldhont Nov 8, 2023
f91944b
new Lizmap\Project\Qgis\LayerTree* classes
rldhont Nov 16, 2023
079a13c
new Lizmap\Project\Qgis\Layout\* classes
rldhont Nov 30, 2023
57c62d2
new Lizmap\Project\Qgis\Layer\* classes
rldhont Oct 15, 2024
e400ab2
new Lizmap\Project\Qgis\ProjectVisibilityPreset and ProjectVisibility…
rldhont Nov 30, 2023
03038a0
New Lizmap\Project\Qgis\ProjectRelation for QGIS Project Relation
rldhont Mar 22, 2024
0359e6b
New Lizmap\Project\Qgis\Layer\EditWidget\* classes and Project\Qgis\L…
rldhont Dec 4, 2023
23ed90c
Lizmap\Project\Qgis\Layer\VectorLayerField parsing EditWidget
rldhont Mar 23, 2024
d9f9160
Lizmap\Project\Qgis\Layer\VectorLayer methods toKeyArray and getFormC…
rldhont Oct 15, 2024
dc9a9d5
New Lizmap\Project\Qgis\ProjectInfo for QGIS Project Info
rldhont Mar 22, 2024
077db5b
Lint QgisProject
rldhont Sep 18, 2024
99ee286
PHP: move getLayersWithLabels method form Project to ProjectConfig
rldhont Sep 27, 2024
2a1fb00
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::readXmlProject
rldhont Sep 18, 2024
936a7ce
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::getPrintTemplates
rldhont Sep 18, 2024
7b27487
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::readLocateByLayer
rldhont Sep 18, 2024
cda52d0
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::readEditionLayers
rldhont Sep 18, 2024
398a561
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::readEditionForms
rldhont Sep 18, 2024
5c539a0
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::readAttributeLa…
rldhont Sep 18, 2024
5100023
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::setShortNames
rldhont Sep 18, 2024
800ff94
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::setLayerOpacity
rldhont Sep 18, 2024
c3844d7
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::unsetPropAfterRead
rldhont Sep 18, 2024
ec597a4
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::setLayerGroupData
rldhont Sep 18, 2024
61a64f5
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::setLayerShowFea…
rldhont Sep 18, 2024
224cd38
Lint Lizmap\Project\Project readLayersOrder method
rldhont Sep 20, 2024
7df0495
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::readLayersOrder
rldhont Sep 20, 2024
e753980
Using Lizmap\Project\Qgis\ProjectInfo in QgisProject::readLayersLabel…
rldhont Sep 29, 2024
747896b
Tests PHP: QgisProject does not use DOM
rldhont Sep 29, 2024
0fb744d
Lint QgisProject after changes
rldhont Oct 1, 2024
dcebf27
QgisProject remove unnecessary methods
rldhont Oct 1, 2024
25c327b
QgisProject remove code in setPropertiesAfterRead methods
rldhont Oct 4, 2024
1df2155
QgisProject remove code in read methods
rldhont Oct 4, 2024
deacc52
QgisProject deprecated methods
rldhont Oct 4, 2024
84015eb
Update Print component
rldhont Oct 8, 2024
2f9b83a
Update legacy switcher layers actions
rldhont Oct 8, 2024
a52fb3f
Update feature toolbar
rldhont Oct 8, 2024
e51ed9a
Tests e2e webdav: relative path
rldhont Oct 14, 2024
90de9b9
new Lizmap\Project\Qgis\Layer\RasterLayer* classes
rldhont Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/src/components/FeatureToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ export default class FeatureToolbar extends HTMLElement {
this._layouts = mainLizmap.config?.layouts;

mainLizmap.config?.printTemplates.map((template, index) => {
if (this._layerId === template?.atlas?.coverageLayer && template?.atlas?.enabled === '1') {
if (this._layerId === template?.atlas?.coverageLayer
&& (template?.atlas?.enabled === '1' || template?.atlas?.enabled === true)) {
// Lizmap >= 3.7
if (mainLizmap.config?.layouts?.list) {
if (mainLizmap.config?.layouts?.list?.[index]?.enabled) {
Expand Down
2 changes: 1 addition & 1 deletion assets/src/components/Print.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Print extends HTMLElement {
// Filtering printTemplates by atlas enabled
// and since 3.7 by layout enabled
mainLizmap.config?.printTemplates.map((template, index) => {
if (template?.atlas?.enabled === '0'){
if (template?.atlas?.enabled === '0' || template?.atlas?.enabled === false){
// Lizmap >= 3.7
if (layouts?.list) {
if(layouts.list?.[index]?.enabled){
Expand Down
25 changes: 25 additions & 0 deletions assets/src/legacy/attributeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,31 @@ var lizAttributeTable = function() {
&& config.attributeLayers[aName]['attributetableconfig']
&& !$.isEmptyObject(config.attributeLayers[aName]['attributetableconfig']['columns'])
){
if (!('column' in config.attributeLayers[aName]['attributetableconfig']['columns'])) {
var atc = config.attributeLayers[aName]['attributetableconfig']['columns'];
if(atc.length == 0){
return colToReturn;
}
var lizcols = columns.slice(0, firstDisplayedColIndex);
var newcolumns = [];
for (var x in atc) {
var colx = atc[x];
// Do nothing if the item does not reference a field
if (colx.type != 'field') {
continue;
}
for (const column of columns) {
if (!('data' in column)) {
continue;
}
if (colx.name == column.data) {
newcolumns.push(column);
}
}
}
colToReturn['columns'] = lizcols.concat(newcolumns);
return colToReturn;
}
var atc = config.attributeLayers[aName]['attributetableconfig']['columns']['column'];
if(atc.length == 0){
return colToReturn;
Expand Down
2 changes: 1 addition & 1 deletion assets/src/legacy/switcher-layers-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ var lizLayerActionButtons = function() {
}

layerOrGroup.checked = true;
layerOrGroup.expanded = layerParams?.expanded === "1";
layerOrGroup.expanded = layerParams?.expanded === "1" || layerParams?.expanded === true;

// `symbologyChildren` is empty for some time if the theme switches
// the layer style from simple to categorized.
Expand Down
95 changes: 82 additions & 13 deletions lizmap/modules/lizmap/lib/App/XmlTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

class XmlTools
{
/*
* Interprets a string of XML into an object
/**
* Interprets a string of XML into an object.
*
* @param string $xml_str a well-formed XML string
*
* @return SimpleXmlElement|string an object of class SimpleXMLElement with properties
* containing the data held within the XML document, or
* a string containing the error message.
* @return \SimpleXmlElement|string an object of class SimpleXMLElement with properties
* containing the data held within the XML document, or
* a string containing the error message
*/
public static function xmlFromString($xml_str)
{
Expand All @@ -34,14 +34,14 @@ public static function xmlFromString($xml_str)
return $xml;
}

/*
* Interprets an XML file into an object
/**
* Interprets an XML file into an object.
*
* @param string $xml_path the path to the xml file
*
* @return SimpleXmlElement|string an object of class SimpleXMLElement with properties
* containing the data held within the XML document, or
* a string containing the error message.
* @return \SimpleXmlElement|string an object of class SimpleXMLElement with properties
* containing the data held within the XML document, or
* a string containing the error message
*/
public static function xmlFromFile($xml_path)
{
Expand All @@ -54,12 +54,12 @@ public static function xmlFromFile($xml_path)
return $xml;
}

/*
* Get XML error message
/**
* Get XML error message.
*
* Build an error message based on LibXMLError object
*
* @return string the error message.
* @return string the error message
*/
private static function xmlErrorMsg()
{
Expand Down Expand Up @@ -89,7 +89,76 @@ private static function xmlErrorMsg()
$msg .= 'Column: '.$error->column.' ';
$msg .= trim($error->message);
}
// Clear libxml error buffer
libxml_clear_errors();

return $msg;
}

/**
* Interprets a string of XML into an XML Pull parser.
* It acts as a cursor going forward on the document stream and stopping at each node on the way.
*
* @param string $xml_str a well-formed XML string
*
* @return \XMLReader an object of class XMLReader with properties at the root document element
* containing the data held within the XML document
*/
public static function xmlReaderFromString($xml_str)
{
$oXml = new \XMLReader();
// Set XML
if (!$oXml->XML($xml_str)) {
throw new \Exception(self::xmlErrorMsg());
}

// Read until we are at the root document element
while ($oXml->read()) {
if ($oXml->nodeType == \XMLReader::ELEMENT
&& $oXml->depth == 0) {
break;
}
}

$errorMsg = self::xmlErrorMsg();
if ($errorMsg !== '') {
throw new \Exception($errorMsg);
}

return $oXml;
}

/**
* Interprets an XML file into an XML pull parser.
* It acts as a cursor going forward on the document stream and stopping at each node on the way.
*
* @param string $xml_path the path to the xml file
*
* @return \XMLReader an object of class XMLReader with properties at the root document element
* containing the data held within the XML document
*/
public static function xmlReaderFromFile($xml_path)
{
$oXml = new \XMLReader();

// Open file
if (!$oXml->open($xml_path)) {
throw new \Exception(self::xmlErrorMsg());
}

// Read until we are at the root document element
while ($oXml->read()) {
if ($oXml->nodeType == \XMLReader::ELEMENT
&& $oXml->depth == 0) {
break;
}
}

$errorMsg = self::xmlErrorMsg();
if ($errorMsg !== '') {
throw new \Exception($errorMsg);
}

return $oXml;
}
}
35 changes: 2 additions & 33 deletions lizmap/modules/lizmap/lib/Project/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,36 +261,7 @@ protected function readProject()
*/
protected function getLayersWithLabels()
{
// Keep a list of layer ids for which to replace the code by labels
$layersWithLabeledFields = array();

// Attribute layers
foreach ($this->cfg->getAttributeLayers() as $key => $config) {
if ($config->hideLayer == 'True') {
continue;
}
$layersWithLabeledFields[] = $config->layerId;
}

// Dataviz layers
foreach ($this->cfg->getDatavizLayers() as $o => $config) {
$layerId = $config->layerId;
if (array_key_exists($layerId, $layersWithLabeledFields)) {
continue;
}
$layersWithLabeledFields[] = $config->layerId;
}

// Form filter layers
foreach ($this->cfg->getFormFilterLayers() as $o => $config) {
$layerId = $config->layerId;
if (array_key_exists($layerId, $layersWithLabeledFields)) {
continue;
}
$layersWithLabeledFields[] = $config->layerId;
}

return $layersWithLabeledFields;
return $this->cfg->getLayersWithLabels();
}

public function getQgisPath()
Expand Down Expand Up @@ -1756,13 +1727,11 @@ protected function readAttributeLayers(QgisProject $xml, ProjectConfig $cfg)
}

/**
* @param \SimpleXMLElement $xml
*
* @return int[]
*/
protected function readLayersOrder(QgisProject $xml)
{
return $this->qgis->readLayersOrder($xml, $this->getLayers());
return $xml->readLayersOrder($this->cfg->getLayers());
}

/**
Expand Down
43 changes: 43 additions & 0 deletions lizmap/modules/lizmap/lib/Project/ProjectConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,49 @@ public function getDatavizLayers()
return $this->datavizLayers;
}

/**
* List of the layers configured in the tools
* Attribute table, form filter & dataviz.
*
* We use this list to find all the fields for which
* we need to replace the code by their corresponding labels
*
* @return array<string> Array of layer ids
*/
public function getLayersWithLabels()
{
// Keep a list of layer ids for which to replace the code by labels
$layersWithLabeledFields = array();

// Attribute layers
foreach ($this->getAttributeLayers() as $key => $config) {
if ($config->hideLayer == 'True') {
continue;
}
$layersWithLabeledFields[] = $config->layerId;
}

// Dataviz layers
foreach ($this->getDatavizLayers() as $o => $config) {
$layerId = $config->layerId;
if (array_key_exists($layerId, $layersWithLabeledFields)) {
continue;
}
$layersWithLabeledFields[] = $config->layerId;
}

// Form filter layers
foreach ($this->getFormFilterLayers() as $o => $config) {
$layerId = $config->layerId;
if (array_key_exists($layerId, $layersWithLabeledFields)) {
continue;
}
$layersWithLabeledFields[] = $config->layerId;
}

return $layersWithLabeledFields;
}

/** Get the HTML template built from the Drag and drop layout
* and override the original datavizTemplate configuration option.
*
Expand Down
Loading
Loading