dmBridge PHP API
UNLVSpatialXMLOutputV1.php
00001 <?php
00002 #
00003 # UNLVSpatial: a dmBridge module for spatial content
00004 #
00005 # Copyright © 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00013 class UNLVSpatialXMLRepresentationV1 extends DMXMLRepresentationV1 implements DMHTTPRepresentationTransformer {
00014 
00022    public function transformObject(DMObject $obj) {
00023       // build the XML structure, but don't return it
00024       parent::transformObject($obj);
00025 
00026       // add dmObject/bounds elements
00027       $lat_n = $this->dxml->createElement("latN", $obj->getSpatialNorthLat());
00028       $lat_s = $this->dxml->createElement("latS", $obj->getSpatialSouthLat());
00029       $long_w = $this->dxml->createElement("longW", $obj->getSpatialWestLong());
00030       $long_e = $this->dxml->createElement("longE", $obj->getSpatialEastLong());
00031       $bounds = $this->dxml->createElement("bounds");
00032       $bounds->appendChild($lat_n);
00033       $bounds->appendChild($lat_s);
00034       $bounds->appendChild($long_w);
00035       $bounds->appendChild($long_e);
00036       $this->dxml->documentElement->getElementsByTagName('dmObject')->item(0)
00037             ->appendChild($bounds);
00038       return $this->output();
00039    }
00040 
00041 
00046    public function transformSpatialResults(UNLVSpatialQuery $query) {
00047       $uri = clone DMHTTPRequest::getCurrent()->getURI();
00048       $uri->unsetQuery();
00049       $uri->setParams("api/1/schema/xml/spatial_objects_list.xsd");
00050       $this->addSchemaAtURI($uri);
00051 
00052       // results
00053       $results = $this->dxml->createElement('results');
00054       $results->setAttribute('page', $query->getPage());
00055       $results->setAttribute('perPage', $query->getNumResultsPerPage());
00056       $results->setAttribute('numPages', $query->getNumPages());
00057       $results->setAttribute('total', $query->getNumResults());
00058 
00059       foreach ($query->getSearchResults() as $obj) {
00060          $objnode = $this->dxml->createElement('dmObject');
00061          $objnode->setAttribute('alias', $obj->getCollection()->getAlias());
00062          $objnode->setAttribute('pointer', $obj->getPtr());
00063          $objnode->setAttribute('xlink:type', 'simple');
00064          $objnode->setAttribute('xlink:href', $obj->getURI());
00065 
00066          $bounds = $this->dxml->createElement("bounds");
00067          $lat_n = $this->dxml->createElement("northLat", $obj->getSpatialNorthLat());
00068          $lat_s = $this->dxml->createElement("southLat", $obj->getSpatialSouthLat());
00069          $long_w = $this->dxml->createElement("westLong", $obj->getSpatialWestLong());
00070          $long_e = $this->dxml->createElement("eastLong", $obj->getSpatialEastLong());
00071          $bounds->appendChild($lat_n);
00072          $bounds->appendChild($lat_s);
00073          $bounds->appendChild($long_w);
00074          $bounds->appendChild($long_e);
00075          $objnode->appendChild($bounds);
00076 
00077          $results->appendChild($objnode);
00078       }
00079       $this->dxml->documentElement->appendChild($results);
00080 
00081       return $this->output();
00082    }
00083 
00084 }
00085 
 All Data Structures Functions Variables