diff --git a/app/controllers/resources/location.php b/app/controllers/resources/location.php index 9275a0f2cfc703b137120b12eb651715ea5f36ed..c22fb3775ea39b7126fd5a827418c52da5ffda1f 100644 --- a/app/controllers/resources/location.php +++ b/app/controllers/resources/location.php @@ -132,7 +132,7 @@ class Resources_LocationController extends AuthenticatedController if (!ResourceManager::userHasGlobalPermission(User::findCurrent(), 'admin')) { throw new AccessDeniedException(); } - + $this->next_action = Request::get('next_action'); $this->categories = ResourceCategory::findByClass_name('Location'); @@ -171,21 +171,25 @@ class Resources_LocationController extends AuthenticatedController $this->category_id = Request::get('category_id'); $this->name = ''; $this->description = ''; - $this->latitude = '0.0'; - $this->longitude = '0.0'; - $this->altitude = '0.0'; + $this->latitude = ''; + $this->longitude = ''; + $this->altitude = ''; $this->sort_position = ''; if ($mode == 'edit') { //Set data from the location object: $this->name = $this->location->name; $this->description = $this->location->description; - $position_data = ResourceManager::getPositionArray( - $this->location->getPropertyObject('geo_coordinates') - ); - $this->latitude = $position_data[0]; - $this->longitude = $position_data[1]; - $this->altitude = $position_data[2]; + $geo_coordinates = $this->location->getPropertyObject('geo_coordinates'); + + if ($geo_coordinates) { + $position_data = ResourceManager::getPositionArray( + $this->location->getPropertyObject('geo_coordinates') + ); + $this->latitude = $position_data[0]; + $this->longitude = $position_data[1]; + $this->altitude = $position_data[2]; + } $this->sort_position = $this->location->sort_position; } } @@ -233,7 +237,6 @@ class Resources_LocationController extends AuthenticatedController $this->altitude = Request::float('geo_coordinates_altitude'); $this->osm_link = Request::get('geo_coordinates_osm_link'); $this->property_data = Request::getArray('properties'); - if ($GLOBALS['perm']->have_perm('root')) { $this->sort_position = Request::get('sort_position'); } @@ -262,22 +265,30 @@ class Resources_LocationController extends AuthenticatedController } //data conversion: - + $user = User::findCurrent(); $position_string = ''; - if ($this->latitude >= 0.0) { + if ($this->latitude > 0.0) { $position_string .= '+'; + $position_string .= number_format($this->latitude, 7); } - $position_string .= number_format($this->latitude, 7); - if ($this->longitude >= 0.0) { + if ($this->longitude > 0.0) { $position_string .= '+'; + $position_string .= number_format($this->longitude, 7); } - $position_string .= number_format($this->longitude, 7); - if ($this->altitude >= 0.0) { + if ($this->altitude > 0.0) { $position_string .= '+'; + $position_string .= number_format($this->altitude, 7); + } + if ($position_string) { + $position_string .= 'CRSWGS_84/'; + if ($this->location->isPropertyEditable('geo_coordinates', $user)) { + $this->location->geo_coordinates = $position_string; + } elseif ($this->location->geo_coordinates !== $position_string) { + $unchanged_properties[] = $this->location->getPropertyObject('geo_coordinates'); + } } - $position_string .= number_format($this->altitude, 7) . 'CRSWGS_84/'; //store data: if ($mode == 'add') { @@ -290,7 +301,7 @@ class Resources_LocationController extends AuthenticatedController if ($GLOBALS['perm']->have_perm('root')) { $this->location->sort_position = $this->sort_position; } - + if ($this->location->isDirty()) { $successfully_stored = $this->location->store(); } else { @@ -301,15 +312,8 @@ class Resources_LocationController extends AuthenticatedController $this->location->sort_position = $this->sort_position; } - $user = User::findCurrent(); - $unchanged_properties = []; - if ($this->location->isPropertyEditable('geo_coordinates', $user)) { - $this->location->geo_coordinates = $position_string; - } elseif ($this->location->geo_coordinates != $position_string) { - $unchanged_properties[] = $this->location->getPropertyObject('geo_coordinates'); - } - + $failed_properties = $this->location->setPropertiesById( $this->property_data, $user diff --git a/lib/models/resources/Resource.class.php b/lib/models/resources/Resource.class.php index d07d068564d166f61d4260a29b698fbba3b7aced..c7c5b77a4c23860119bce227186813fbea3a28cb 100644 --- a/lib/models/resources/Resource.class.php +++ b/lib/models/resources/Resource.class.php @@ -1432,6 +1432,9 @@ class Resource extends SimpleORMap implements StudipItem public function getPropertyObject(string $name) { if (!$this->propertyExists($name)) { + if ($name === 'geo_coordinates') { + return null; + } //A property with the name $name does not exist for this //resource object. If it is a defined property //we can still try to create it: @@ -1443,16 +1446,12 @@ class Resource extends SimpleORMap implements StudipItem ); $property->store(); - - if ($name === 'geo_coordinates' && $property->state === '+0.0000000+0.0000000+0.0000000CRSWGS_84/') { - return null; - } return $property; } else { return null; } } - $property = ResourceProperty::findOneBySql( + return ResourceProperty::findOneBySql( "INNER JOIN resource_property_definitions rpd ON resource_properties.property_id = rpd.property_id WHERE resource_properties.resource_id = :resource_id @@ -1462,11 +1461,6 @@ class Resource extends SimpleORMap implements StudipItem 'name' => $name ] ); - - if ($name === 'geo_coordinates' && $property->state === '+0.0000000+0.0000000+0.0000000CRSWGS_84/') { - return null; - } - return $property; } /** diff --git a/lib/models/resources/ResourcePropertyDefinition.class.php b/lib/models/resources/ResourcePropertyDefinition.class.php index 878baf80e9904ff136d66af1148054d4516c46ea..1d5833026aa5a28e9ef58c85e9c80f5f43688569 100644 --- a/lib/models/resources/ResourcePropertyDefinition.class.php +++ b/lib/models/resources/ResourcePropertyDefinition.class.php @@ -48,7 +48,7 @@ class ResourcePropertyDefinition extends SimpleORMap * are always in a format as specified by the ISO-6709 * string representation. */ - const CRSWGS84_REGEX = '/[+-]{1}[0-9]{1,3}\.[0-9]{1,10}[+-]{1}[0-9]{1,3}\.[0-9]{1,10}[+-]{1}[0-9]{1,5}\.[0-9]{1,10}CRSWGS_84\/$/'; + const CRSWGS84_REGEX = '/[+-]\d{1,3}\.\d{1,10}[+-]\d{1,3}\.\d{1,10}[+-]\d{1,5}\.\d{1,10}CRSWGS_84\/$/'; protected static function configure($config = []) { diff --git a/lib/resources/ResourceManager.class.php b/lib/resources/ResourceManager.class.php index bb1cca4a3128cf028a4fb559bba5f849aceabfaa..e0d946676179c0bb45ed2987db2e5e8823d5f0bf 100644 --- a/lib/resources/ResourceManager.class.php +++ b/lib/resources/ResourceManager.class.php @@ -564,14 +564,11 @@ class ResourceManager //- altitude: up to 5 digits, decimal point, 1 to 10 digits for fraction //before the decimal point. After the decimal point, //In that case it is a coordinate format we can parse: - if(!preg_match( ResourcePropertyDefinition::CRSWGS84_REGEX, $coordinate_string )) { - throw new ResourcePropertyStateException( - _('Die Positionsangabe kann nicht umgewandelt werden, da sie ungültige Daten enthält!') - ); + PageLayout::postError(_('Die Positionsangabe kann nicht umgewandelt werden, da sie ungültige Daten enthält!')); } //With the first split we separate the numbers in the coordinate string. @@ -590,7 +587,7 @@ class ResourceManager //with decimal separators. $coordinate_signs = preg_split( - '/\.[0-9]{1,10}/', + '/\.\d{1,10}/', $coordinate_string, -1, PREG_SPLIT_NO_EMPTY @@ -690,6 +687,7 @@ class ResourceManager ) { $coordinate_parts = []; + $string = ''; try { $coordinate_parts = self::getPositionArray($property); } catch (ResourcePropertyDefinitionException $e) { diff --git a/templates/resources/position_attribute_form_part.php b/templates/resources/position_attribute_form_part.php index 553e0afcb3bffdefb33e3e529825adeb57babc8f..d08630fb5ca905114a56a8596453b9ede77284df 100644 --- a/templates/resources/position_attribute_form_part.php +++ b/templates/resources/position_attribute_form_part.php @@ -4,7 +4,7 @@ <?= _('Breitengrad: ') ?> <input type="text" maxlength="13" name="<?= htmlReady($property_name) ?>_latitude" - value="<?= number_format(floatval($latitude), 7) ?>" + value="<?= $latitude? number_format(floatval($latitude), 7) : ''?>" class="resource-position-property-number-field"> </label> @@ -12,14 +12,14 @@ <?= _('Längengrad: ') ?> <input type="text" maxlength="13" name="<?= htmlReady($property_name) ?>_longitude" - value="<?= number_format(floatval($longitude), 7) ?>" + value="<?= $longitude ? number_format(floatval($longitude), 7) : '' ?>" class="resource-position-property-number-field"> </label> <label> <?= _('Höhenangabe (Meter): ') ?> <input type="text" maxlength="5" name="<?= htmlReady($property_name) ?>_altitude" - value="<?= number_format(floatval($altitude), 1) ?>" + value="<?= $altitude ? number_format(floatval($altitude), 1) : ''?>" class="resource-position-property-number-field"> </label> </div>