Source for file changesets.php

Documentation is available at changesets.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Openstreetmap
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die();
  11.  
  12. /**
  13.  * Openstreetmap API Changesets class for the Joomla Platform
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Openstreetmap
  17.  * @since       13.1
  18.  */
  19. {
  20.     /**
  21.      * Method to create a changeset
  22.      *
  23.      * @param   array  $changesets  Array which contains changeset data
  24.      *
  25.      * @return  array  The XML response
  26.      *
  27.      * @since   13.1
  28.      */
  29.     public function createChangeset($changesets=array())
  30.     {
  31.         $token $this->oauth->getToken();
  32.  
  33.         // Set parameters.
  34.         $parameters array(
  35.             'oauth_token' => $token['key'],
  36.             'oauth_token_secret' => $token['secret']
  37.         );
  38.  
  39.         // Set the API base
  40.         $base 'changeset/create';
  41.  
  42.         // Build the request path.
  43.         $path $this->getOption('api.url'$base;
  44.  
  45.         $xml '<?xml version="1.0" encoding="UTF-8"?>
  46.             <osm version="0.6" generator="JOpenstreetmap">';
  47.  
  48.         if (!empty($changesets))
  49.         {
  50.             // Create Changeset element for every changeset
  51.             foreach ($changesets as $tags)
  52.             {
  53.                 $xml .= '<changeset>';
  54.  
  55.                 if (!empty($tags))
  56.                 {
  57.                     // Create a list of tags for each changeset
  58.                     foreach ($tags as $key => $value)
  59.                     {
  60.                         $xml .= '<tag k="' $key '" v="' $value '"/>';
  61.                     }
  62.                 }
  63.  
  64.                 $xml .= '</changeset>';
  65.             }
  66.         }
  67.  
  68.         $xml .= '</osm>';
  69.  
  70.         $header['Content-Type''text/xml';
  71.  
  72.         // Send the request.
  73.         $response $this->oauth->oauthRequest($path'PUT'$parameters$xml$header);
  74.  
  75.         return $response->body;
  76.     }
  77.  
  78.     /**
  79.      * Method to read a changeset
  80.      *
  81.      * @param   integer  $id  identifier of the changeset
  82.      *
  83.      * @return  array  The XML response about a changeset
  84.      *
  85.      * @since   13.1
  86.      */
  87.     public function readChangeset($id)
  88.     {
  89.         // Set the API base
  90.         $base 'changeset/' $id;
  91.  
  92.         // Build the request path.
  93.         $path $this->getOption('api.url'$base;
  94.  
  95.         // Send the request.
  96.         $xml_string $this->sendRequest($path);
  97.  
  98.         return $xml_string->changeset;
  99.     }
  100.  
  101.     /**
  102.      * Method to update a changeset
  103.      *
  104.      * @param   integer  $id    Identifier of the changeset
  105.      * @param   array    $tags  Array of tags to update
  106.      *
  107.      * @return  array  The XML response of updated changeset
  108.      *
  109.      * @since   13.1
  110.      */
  111.     public function updateChangeset($id$tags array())
  112.     {
  113.         $token $this->oauth->getToken();
  114.  
  115.         // Set parameters.
  116.         $parameters array(
  117.             'oauth_token' => $token['key']
  118.         );
  119.  
  120.         // Set the API base
  121.         $base 'changeset/' $id;
  122.  
  123.         // Build the request path.
  124.         $path $this->getOption('api.url'$base;
  125.  
  126.         // Create a list of tags to update changeset
  127.         $tag_list '';
  128.  
  129.         if (!empty($tags))
  130.         {
  131.             foreach ($tags as $key => $value)
  132.             {
  133.                 $tag_list .= '<tag k="' $key '" v="' $value '"/>';
  134.             }
  135.         }
  136.  
  137.         $xml '<?xml version="1.0" encoding="UTF-8"?>
  138.                 <osm version="0.6" generator="JOpenstreetmap">
  139.                 <changeset>'
  140.                 . $tag_list .
  141.                 '</changeset>
  142.                 </osm>';
  143.  
  144.         $header['Content-Type''text/xml';
  145.  
  146.         // Send the request.
  147.         $response $this->oauth->oauthRequest($path'PUT'$parameters$xml$header);
  148.  
  149.         $xml_string simplexml_load_string($response->body);
  150.  
  151.         return $xml_string->changeset;
  152.     }
  153.  
  154.     /**
  155.      * Method to close a changeset
  156.      *
  157.      * @param   integer  $id  identifier of the changeset
  158.      *
  159.      * @return  void 
  160.      *
  161.      * @since   13.1
  162.      */
  163.     public function closeChangeset($id)
  164.     {
  165.         $token $this->oauth->getToken();
  166.  
  167.         // Set parameters.
  168.         $parameters array(
  169.             'oauth_token' => $token['key']
  170.         );
  171.  
  172.         // Set the API base
  173.         $base 'changeset/' $id '/close';
  174.  
  175.         // Build the request path.
  176.         $path $this->getOption('api.url'$base;
  177.  
  178.         $header['format''text/xml';
  179.  
  180.         // Send the request.
  181.         $this->oauth->oauthRequest($path'PUT'$parameters$header);
  182.     }
  183.  
  184.     /**
  185.      * Method to download a changeset
  186.      *
  187.      * @param   integer  $id  Identifier of the changeset
  188.      *
  189.      * @return  array  The XML response of requested changeset
  190.      *
  191.      * @since   13.1
  192.      */
  193.     public function downloadChangeset($id)
  194.     {
  195.         // Set the API base
  196.         $base 'changeset/' $id '/download';
  197.  
  198.         // Build the request path.
  199.         $path $this->getOption('api.url'$base;
  200.  
  201.         // Send the request.
  202.         $xml_string $this->sendRequest($path);
  203.  
  204.         return $xml_string->create;
  205.     }
  206.  
  207.     /**
  208.      * Method to expand the bounding box of a changeset
  209.      *
  210.      * @param   integer  $id     Identifier of the changeset
  211.      * @param   array    $nodes  List of lat lon about nodes
  212.      *
  213.      * @return  array  The XML response of changed changeset
  214.      *
  215.      * @since   13.1
  216.      */
  217.     public function expandBBoxChangeset($id$nodes)
  218.     {
  219.         $token $this->oauth->getToken();
  220.  
  221.         // Set parameters.
  222.         $parameters array(
  223.             'oauth_token' => $token['key']
  224.         );
  225.  
  226.         // Set the API base
  227.         $base 'changeset/' $id '/expand_bbox';
  228.  
  229.         // Build the request path.
  230.         $path $this->getOption('api.url'$base;
  231.  
  232.         // Create a list of tags to update changeset
  233.         $node_list '';
  234.  
  235.         if (!empty($nodes))
  236.         {
  237.             foreach ($nodes as $node)
  238.             {
  239.                 $node_list .= '<node lat="' $node[0'" lon="' $node[1'"/>';
  240.             }
  241.         }
  242.  
  243.         $xml '<?xml version="1.0" encoding="UTF-8"?>
  244.                 <osm version="0.6" generator="JOpenstreetmap">
  245.                 <changeset>'
  246.                 . $node_list .
  247.                 '</changeset>
  248.             </osm>';
  249.  
  250.         $header['Content-Type''text/xml';
  251.  
  252.         // Send the request.
  253.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  254.  
  255.         $xml_string simplexml_load_string($response->body);
  256.  
  257.         return $xml_string->changeset;
  258.     }
  259.  
  260.     /**
  261.      * Method to query on changesets
  262.      *
  263.      * @param   string  $param  Parameters for query
  264.      *
  265.      * @return  array  The XML response
  266.      *
  267.      * @since   13.1
  268.      */
  269.     public function queryChangeset($param)
  270.     {
  271.         // Set the API base
  272.         $base 'changesets/' $param;
  273.  
  274.         // Build the request path.
  275.         $path $this->getOption('api.url'$base;
  276.  
  277.         // Send the request.
  278.         $xml_string $this->sendRequest($path);
  279.  
  280.         return $xml_string->osm;
  281.     }
  282.  
  283.     /**
  284.      * Method to upload a diff to a changeset
  285.      *
  286.      * @param   string   $xml  Diff data to upload
  287.      * @param   integer  $id   Identifier of the changeset
  288.      *
  289.      * @return  array  The XML response of result
  290.      *
  291.      * @since   13.1
  292.      */
  293.     public function diffUploadChangeset($xml$id)
  294.     {
  295.         $token $this->oauth->getToken();
  296.  
  297.         // Set parameters.
  298.         $parameters array(
  299.             'oauth_token' => $token['key']
  300.         );
  301.  
  302.         // Set the API base
  303.         $base 'changeset/' $id '/upload';
  304.  
  305.         // Build the request path.
  306.         $path $this->getOption('api.url'$base;
  307.  
  308.         $header['Content-Type''text/xml';
  309.  
  310.         // Send the request.
  311.         $response $this->oauth->oauthRequest($path'POST'$parameters$xml$header);
  312.  
  313.         $xml_string simplexml_load_string($response->body);
  314.  
  315.         return $xml_string->diffResult;
  316.     }
  317. }

Documentation generated on Tue, 19 Nov 2013 14:55:39 +0100 by phpDocumentor 1.4.3