Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
user.php
Aller à la documentation de ce fichier.
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 User class for the Joomla Platform
14  *
15  * @package Joomla.Platform
16  * @subpackage Openstreetmap
17  * @since 13.1
18 */
20 {
21  /**
22  * Method to get user details
23  *
24  * @return array The XML response
25  *
26  * @since 13.1
27  */
28  public function getDetails()
29  {
30  $token = $this->oauth->getToken();
31 
32  // Set parameters.
33  $parameters = array(
34  'oauth_token' => $token['key']
35  );
36 
37  // Set the API base
38  $base = 'user/details';
39 
40  // Build the request path.
41  $path = $this->getOption('api.url') . $base;
42 
43  // Send the request.
44  $response = $this->oauth->oauthRequest($path, 'GET', $parameters);
45 
46  return $response->body;
47  }
48 
49  /**
50  * Method to get preferences
51  *
52  * @return array The XML response
53  *
54  * @since 13.1
55  */
56  public function getPreferences()
57  {
58  $token = $this->oauth->getToken();
59 
60  // Set parameters.
61  $parameters = array(
62  'oauth_token' => $token['key']
63  );
64 
65  // Set the API base
66  $base = 'user/preferences';
67 
68  // Build the request path.
69  $path = $this->getOption('api.url') . $base;
70 
71  // Send the request.
72  $response = $this->oauth->oauthRequest($path, 'GET', $parameters);
73 
74  return $response->body;
75  }
76 
77  /**
78  * Method to replace user preferences
79  *
80  * @param array $preferences Array of new preferences
81  *
82  * @return array The XML response
83  *
84  * @since 13.1
85  */
86  public function replacePreferences($preferences)
87  {
88  $token = $this->oauth->getToken();
89 
90  // Set parameters.
91  $parameters = array(
92  'oauth_token' => $token['key']
93  );
94 
95  // Set the API base
96  $base = 'user/preferences';
97 
98  // Build the request path.
99  $path = $this->getOption('api.url') . $base;
100 
101  // Create a list of preferences
102  $preference_list = '';
103 
104  if (!empty($preferences))
105  {
106  foreach ($preferences as $key => $value)
107  {
108  $preference_list .= '<preference k="' . $key . '" v="' . $value . '"/>';
109  }
110  }
111 
112  $xml = '<?xml version="1.0" encoding="UTF-8"?>
113  <osm version="0.6" generator="JOpenstreetmap">
114  <preferences>'
115  . $preference_list .
116  '</preferences>
117  </osm>';
118 
119  $header['Content-Type'] = 'text/xml';
120 
121  // Send the request.
122  $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $xml, $header);
123 
124  return $response->body;
125  }
126 
127  /**
128  * Method to change user preferences
129  *
130  * @param string $key Key of the preference
131  * @param string $preference New value for preference
132  *
133  * @return array The XML response
134  *
135  * @since 13.1
136  */
137  public function changePreference($key, $preference)
138  {
139  $token = $this->oauth->getToken();
140 
141  // Set parameters.
142  $parameters = array(
143  'oauth_token' => $token['key']
144  );
145 
146  // Set the API base
147  $base = 'user/preferences/' . $key;
148 
149  // Build the request path.
150  $path = $this->getOption('api.url') . $base;
151 
152  // Send the request.
153  $response = $this->oauth->oauthRequest($path, 'PUT', $parameters, $preference);
154 
155  return $response->body;
156  }
157 }