@@ -210,6 +210,19 @@ public function __construct($layer, $form, $featureId, $loginFilteredOverride, A
210
210
$ form ->getContainer ()->privateData = array_merge ($ form ->getContainer ()->privateData , $ privateData );
211
211
}
212
212
213
+ /**
214
+ * Log a Form message.
215
+ *
216
+ * @param mixed $message The message to log
217
+ * @param string $cat The category of the logged message
218
+ */
219
+ protected function logMessage ($ message , $ cat = 'default ' ): void
220
+ {
221
+ $ project = $ this ->layer ->getProject ();
222
+ $ prefix = 'Error in form ' .$ project ->getRepository ()->getKey ().' / ' .$ project ->getKey ().' / ' .$ this ->layer ->getName ().': ' ;
223
+ $ this ->appContext ->logMessage ($ prefix .$ message , $ cat );
224
+ }
225
+
213
226
/**
214
227
* Get the default value of a QGIS field, if this is
215
228
* a simple raw value.
@@ -708,9 +721,23 @@ public function check($feature = null)
708
721
709
722
// Evaluate constraint expressions
710
723
if (count ($ constraintExpressions ) > 0 ) {
724
+
725
+ // build geom
726
+ $ geom = null ;
727
+ if ($ geometryColumn != '' ) {
728
+ // from wkt to geom
729
+ $ wkt = trim ($ form ->getData ($ values [$ geometryColumn ]));
730
+ if ($ wkt && \lizmapWkt::check ($ wkt )) {
731
+ $ geom = \lizmapWkt::parse ($ wkt );
732
+ if ($ geom === null ) {
733
+ $ this ->logMessage ('Parsing WKT failed: " ' .$ wkt .'". ' , 'lizmapadmin ' );
734
+ }
735
+ }
736
+ }
737
+
711
738
$ form_feature = array (
712
739
'type ' => 'Feature ' ,
713
- 'geometry ' => null ,
740
+ 'geometry ' => $ geom ,
714
741
'properties ' => $ values ,
715
742
);
716
743
$ results = $ this ->evaluateExpression ($ constraintExpressions , $ form_feature );
@@ -879,14 +906,14 @@ public function saveToDb($feature = null, $modifiedControls = array())
879
906
if ($ insertAction ) {
880
907
// For insertion, one field has to be set
881
908
// FIXME missing context
882
- $ this ->appContext -> logMessage ('Error in form, SQL cannot be constructed: no fields available for insert ! ' , 'lizmapadmin ' );
909
+ $ this ->logMessage ('SQL cannot be constructed: no fields available for insert. ' , 'lizmapadmin ' );
883
910
$ this ->form ->setErrorOn ($ geometryColumn , \jLocale::get ('view~edition.message.error.save ' ).' ' .\jLocale::get ('view~edition.message.error.save.fields ' ));
884
911
885
912
// do not throw an exception to let the user update the form
886
913
throw new \Exception ($ this ->appContext ->getLocale ('view~edition.link.error.sql ' ));
887
914
}
888
915
// For update, nothing has changed so nothing to do except close form
889
- $ this ->appContext -> logMessage ('SQL cannot be constructed: no fields available for update ! ' , 'lizmapadmin ' );
916
+ $ this ->logMessage ('SQL cannot be constructed: no fields available for update. ' , 'lizmapadmin ' );
890
917
891
918
return true ;
892
919
}
@@ -951,7 +978,7 @@ public function saveToDb($feature = null, $modifiedControls = array())
951
978
} catch (\Exception $ e ) {
952
979
// Need to catch Exception if operation on remote storage fails
953
980
$ form ->setErrorOn ($ ref , $ e ->getMessage ());
954
- $ this ->appContext -> logMessage ($ e ->getMessage (), 'lizmapadmin ' );
981
+ $ this ->logMessage ($ e ->getMessage (), 'lizmapadmin ' );
955
982
$ this ->appContext ->logException ($ e , 'lizmapadmin ' );
956
983
957
984
return false ;
@@ -999,7 +1026,7 @@ public function saveToDb($feature = null, $modifiedControls = array())
999
1026
return $ pkVal ;
1000
1027
} catch (\Exception $ e ) {
1001
1028
$ form ->setErrorOn ($ geometryColumn , $ this ->appContext ->getLocale ('view~edition.message.error.save ' ));
1002
- $ this ->appContext -> logMessage ('An error has been raised when saving form data edition to db : ' , 'lizmapadmin ' );
1029
+ $ this ->logMessage ('An error has been raised when saving form data edition to the database. ' , 'lizmapadmin ' );
1003
1030
$ this ->appContext ->logException ($ e , 'lizmapadmin ' );
1004
1031
1005
1032
return false ;
@@ -1462,7 +1489,7 @@ protected function fillControlFromUniqueValues($fieldName, $formControl)
1462
1489
if (array_key_exists ('notNull ' , $ formControl ->uniqueValuesData )
1463
1490
&& $ formControl ->uniqueValuesData ['notNull ' ]
1464
1491
) {
1465
- $ this ->appContext -> logMessage ('notNull ' .$ formControl ->uniqueValuesData ['notNull ' ], 'lizmapadmin ' );
1492
+ $ this ->logMessage ('notNull ' .$ formControl ->uniqueValuesData ['notNull ' ], 'lizmapadmin ' );
1466
1493
$ formControl ->ctrl ->required = true ;
1467
1494
}
1468
1495
// combobox
@@ -1496,7 +1523,7 @@ private function fillControlFromValueRelationLayer($fieldName, $formControl)
1496
1523
if (array_key_exists ('notNull ' , $ formControl ->valueRelationData )
1497
1524
and $ formControl ->valueRelationData ['notNull ' ]
1498
1525
) {
1499
- \jLog:: log ('notNull ' .$ formControl ->valueRelationData ['notNull ' ], 'lizmapadmin ' );
1526
+ $ this -> logMessage ('notNull ' .$ formControl ->valueRelationData ['notNull ' ], 'lizmapadmin ' );
1500
1527
$ formControl ->ctrl ->required = true ;
1501
1528
}
1502
1529
// combobox
0 commit comments