Skip to content

Commit d9f8a65

Browse files
Pol Dell'AieraPol Dell'Aiera
authored andcommitted
Adding getMetadata for Collection. Geez.
1 parent dd47303 commit d9f8a65

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

lib/geometry/MultiLineString.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,16 @@ public function isClosed() {
1515
}
1616
return TRUE;
1717
}
18+
19+
public function getMetadata($key, $options = array()) {
20+
foreach ($this->components as $component) {
21+
foreach ($component->metadata['providers'] as $metadata_provider) {
22+
if ($metadata_provider->provides($key)) {
23+
return $metadata_provider->get($this, $key, $options);
24+
}
25+
}
26+
return NULL;
27+
}
28+
}
1829
}
1930

lib/metadata/DurationMetadataProvider.class.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,16 @@ public function provides($key) {
99
return FALSE;
1010
}
1111

12-
public function has($target, $key) {
13-
return isset($target->metadata['metadatas'][__CLASS__]) && isset($target->metadata['metadatas'][__CLASS__][$key]) && !is_null($target->metadata['metadatas'][__CLASS__][$key]) && (in_array($key, $this->capabilities)) && ($target instanceof Collection);
14-
}
15-
1612
public function get($target, $key, $options) {
1713

1814
if ($target instanceof MultiLineString) {
19-
20-
if ($key == 'duration') {
21-
$duration = 0;
22-
foreach ($target->components as $component) {
23-
$duration += $component->getMetadata('duration');
24-
}
25-
return $duration;
15+
$duration = 0;
16+
foreach ($target->components as $component) {
17+
$duration += $component->getMetadata($key, $options);
2618
}
19+
return $duration;
2720
}
2821

29-
3022
if ($target instanceof LineString) {
3123
if ($key == 'duration') {
3224
$point_a = $target->startPoint();

lib/metadata/ElevationMetadataProvider.class.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ public function provides($key) {
99
return FALSE;
1010
}
1111

12-
public function has($target, $key) {
13-
return isset($target->metadata['metadatas'][__CLASS__]) && isset($target->metadata['metadatas'][__CLASS__][$key]) && !is_null($target->metadata['metadatas'][__CLASS__][$key]) && ($key === 'ele') && ($target instanceof Point);
14-
}
15-
1612
public function get($target, $key, $options) {
17-
if ($this->has($target, $key)) {
13+
if ($this->provides($key)) {
1814
return $target->metadata['metadatas'][__CLASS__][$key];
1915
}
2016
}

lib/metadata/MetadataProvider.class.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
interface MetadataProvider
44
{
55
public function provides($key);
6-
public function has($target, $key);
76
public function set($target, $key, $value);
87
public function get($target, $key, $options);
98
public function id();

0 commit comments

Comments
 (0)