Skip to content
Snippets Groups Projects
Commit 53b19ab4 authored by David Siegfried's avatar David Siegfried Committed by Jan-Hendrik Willms
Browse files

no default values are saved for geo-coordinates, closes #871

Closes #871, #1055, and #1046

Merge request studip/studip!607
parent 9c0379da
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -1428,6 +1428,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:
......@@ -1439,16 +1442,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
......@@ -1458,11 +1457,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;
}
/**
......
......@@ -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 = [])
{
......
......@@ -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) {
......
......@@ -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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment