Permalink
Browse files

Interface with notes/comments better.

  • Loading branch information...
kenguest committed Jan 9, 2014
1 parent 3d58cb8 commit 946efc56999df9ccf216030d47499e27584203c8
@@ -357,6 +357,25 @@ public function getWay($wayID, $version = null)
return $way;
}
+ /**
+ * getWayFull
+ *
+ * @param mixed $wayID
+ * @param mixed $version
+ * @return void
+ * @fixme: append '/full' to request URL, check returned xml/object makese sense
+ * @note: do a similary getRelationFull method also
+ */
+ public function getWayFull($wayID, $version = null)
+ {
+ $way = $this->getTransport()->getObject('way', $wayID, $version);
+ if ($way !== false) {
+ $way->setTransport($this->getTransport());
+ $way->setConfig($this->getConfig());
+ }
+ return $way;
+ }
+
/**
* Return an array of specified ways.
*
@@ -0,0 +1,104 @@
+<?php
+/**
+ * Comment.php
+ * 30-Dec-2013
+ *
+ * PHP Version 5
+ *
+ * @category Services
+ * @package Services_OpenStreetMap
+ * @author Ken Guest <kguest@php.net>
+ * @license BSD http://www.opensource.org/licenses/bsd-license.php
+ * @version Release: @package_version@
+ * @link Comment.php
+ */
+
+/**
+ * Services_OpenStreetMap_Comment
+ *
+ * @category Services
+ * @package Services_OpenStreetMap
+ * @author Ken Guest <kguest@php.net>
+ * @license BSD http://www.opensource.org/licenses/bsd-license.php
+ * @link Comment.php
+ */
+class Services_OpenStreetMap_Comment extends Services_OpenStreetMap_Object
+{
+ /**
+ * What type of object this is.
+ *
+ * @var string
+ */
+ protected $type = 'comment';
+
+ /**
+ * Retrieve the action of the note ('opened' etc)
+ *
+ * @return string
+ */
+ public function getAction()
+ {
+ return $this->obj[0]->action;
+ }
+
+ /**
+ * Retrieve time-stamp of when note was created.
+ *
+ * @return int
+ */
+ public function getDate()
+ {
+ return $this->obj[0]->date;
+ }
+
+ /**
+ * Text entry for this comment.
+ *
+ * @return string
+ */
+ public function getText()
+ {
+ return $this->obj[0]->text;
+ }
+
+ /**
+ * Html entry for this comment.
+ *
+ * @return string
+ */
+ public function getHtml()
+ {
+ return $this->obj[0]->html;
+ }
+
+ /**
+ * setXml
+ *
+ * @param SimpleXMLElement $xml OSM XML
+ *
+ * @return Services_OpenStreetMap_Comment
+ */
+ public function setXml(SimpleXMLElement $xml)
+ {
+ $this->xml = $xml->saveXml();
+ $obj = $xml->xpath('//' . $this->getType());
+ $kids = array();
+ foreach ($obj[0]->children() as $child) {
+ $key = (string) $child->attributes()->k;
+ if ($key != '') {
+ $this->tags[$key] = (string) $child->attributes()->v;
+ }
+ $name = (string) $child->getName();
+ $kids[$name] = (string) $child;
+ }
+ $this->tags = $kids;
+ if (isset($kids['id'])) {
+ $this->setId($kids['id']);
+ }
+# var_dump($this->tags);
+ $this->obj = $obj;
+ return $this;
+ }
+}
+// vim:set et ts=4 sw=4:
+?>
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Comments.php
+ * 30-Dec-2013
+ *
+ * PHP Version 5
+ *
+ * @category Services
+ * @package Services_OpenStreetMap
+ * @author Ken Guest <kguest@php.net>
+ * @license BSD http://www.opensource.org/licenses/bsd-license.php
+ * @link Comments.php
+ */
+
+/**
+ * Services_OpenStreetMap_Comments
+ *
+ * @category Services
+ * @package Services_OpenStreetMap
+ * @author Ken Guest <kguest@php.net>
+ * @license BSD http://www.opensource.org/licenses/bsd-license.php
+ * @link Comments.php
+ */
+class Services_OpenStreetMap_Comments extends Services_OpenStreetMap_Objects
+{
+ /**
+ * type
+ *
+ * @return string type
+ */
+ public function getType()
+ {
+ return 'comment';
+ }
+
+ public function __construct(array $array = array())
+ {
+ $this->objects = $array;
+ }
+}
+
+?>
@@ -108,7 +108,7 @@ public function getCloseUrl()
*/
public function getComments()
{
- return $this->obj[0]->comments;
+ return $this->comments;
}
/**
@@ -196,25 +196,19 @@ public function setXml(SimpleXMLElement $xml)
if ($name == 'comments') {
$comments = array();
foreach ($child->children() as $gchild) {
- $comment = array();
- foreach ($gchild->children() as $ggchild) {
- $ggname = (string) $ggchild->getName();
- $ggvalue = (string) $ggchild;
- $comment[$ggname] = $ggvalue;
- }
+ $gname = (string) $gchild->getName();
+ $comment = new Services_OpenStreetMap_Comment;
+ $comment->setXml($gchild);
$comments[] = $comment;
}
- $kids['comments'] = $comments;
+ $kids[] = $comments;
+ } elseif ($name == 'id') {
+ $this->setId((double) $child);
- } else {
- $kids[$name] = (string) $child;
}
}
+ $this->comments = new Services_OpenStreetMap_Comments($comments);
$this->tags = $kids;
- if (isset($kids['id'])) {
- $this->setId($kids['id']);
- var_dump($this->getId());
- }
$this->obj = $obj;
return $this;
}
@@ -0,0 +1,56 @@
+<?php
+/**
+ * example1_savetolocalfile.php
+ * 22-Nov-2009
+ *
+ * PHP Version 5
+ *
+ * @category Services
+ * @package Services_OpenStreetMap
+ * @author Ken Guest <kguest@php.net>
+ * @license BSD http://www.opensource.org/licenses/bsd-license.php
+ * @version Release: @package_version@
+ * @link example12_notes.php
+ */
+
+$version = '@package_version@';
+if (strstr($version, 'package_version')) {
+ set_include_path(dirname(dirname(__FILE__)) . ':' . get_include_path());
+}
+
+require_once 'Services/OpenStreetMap.php';
+
+$osm = new Services_OpenStreetMap(array('verbose' => true));
+
+try {
+ $osm->getConfig()->setServer('http://api.openstreetmap.org/');
+} catch (Exception $ex) {
+ var_dump($ex->getMessage());
+ // Fall back to default server...so carry on.
+}
+
+$notes = $osm->getNotesByBbox(
+ -8.24724502663969, 52.8482419135407, -8.17416147865479, 52.8995782553221
+);
+echo $notes;
+foreach ($notes as $note) {
+ echo 'ID: ', $note->getId(), "\n";
+ echo 'LAT/LON: ', $note->getLat(), "/", $note->getLon(), "\n";
+ echo 'STATUS: ', $note->getStatus(), "\n";
+ echo 'CREATED: ', strftime("%c %T", $note->getDateCreated()), "\n";
+ echo 'URL: ', $note->getUrl(), "\n";
+ echo 'COMMENT URL: ', $note->getCommentUrl(), "\n";
+ echo 'CLOSE URL: ', $note->getCloseUrl(), "\n";
+
+ echo "\n\nComments:\n";
+ $comments = $note->getComments();
+ foreach($comments as $comment) {
+ echo 'Action: ', $comment->getAction(), "\n";
+ echo 'Date: ', $comment->getDate(), "\n";
+ echo $comment->getText(), "\n";
+ echo $comment->getHtml(), "\n";
+ }
+}
+
+// vim:set et ts=4 sw=4:
+?>
View
@@ -194,6 +194,37 @@ public function testGetNotesByBBoxSetLimitAndClosed()
"bbox=$minlon,$minlat,$maxlon,$maxlat&limit=200&closed=14"
);
}
+
+ public function testa()
+ {
+ $mock = new HTTP_Request2_Adapter_Mock();
+ $mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb'));
+ $mock->addResponse(fopen(__DIR__ . '/responses/get_notes.xml', 'rb'));
+
+ $server = 'http://api06.dev.openstreetmap.org/';
+ $config = array(
+ 'adapter' => $mock,
+ 'server' => $server,
+ );
+ $osm = new Services_OpenStreetMap($config);
+
+
+ $minlon = "-8.2456593";
+ $minlat = "52.8488977";
+ $maxlon = "-8.1751247";
+ $maxlat = "52.8839662";
+
+ $notes = $osm->getNotesByBbox(
+ $minlon, $minlat, $maxlon, $maxlat, 200, 14
+ );
+ $note = $notes[0];
+ $this->assertInstanceOf('Services_OpenStreetMap_Notes', $notes);
+ $this->assertInstanceOf('Services_OpenStreetMap_Note', $note);
+ $comments = $note->getComments();
+ $comment = $comments[0];
+ $this->assertInstanceOf('Services_OpenStreetMap_Comment', $comment);
+ $this->assertInstanceOf('Services_OpenStreetMap_Comments', $comments);
+ }
}
?>

0 comments on commit 946efc5

Please sign in to comment.