1: <?php
2: /**
3: * Maniaplanet Web Services SDK for PHP
4: *
5: * @see http://code.google.com/p/maniaplanet-ws-sdk/
6: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
7: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
8: * @author $Author: baptiste33@gmail.com $:
9: * @version $Revision: 113 $:
10: * @date $Date: 2012-07-11 14:56:37 +0200 (mer., 11 juil. 2012) $:
11: */
12:
13: namespace Maniaplanet\WebServices;
14:
15: /**
16: * Access to public zones data.
17: * You can either work with zones using their IDs of their full paths.
18: */
19: class Zones extends HTTPClient
20: {
21:
22: /**
23: * @param int $id A zone id
24: * @return object
25: * @throws \Maniaplanet\WebServices\Exception
26: */
27: function get($id)
28: {
29: if(!$id)
30: {
31: throw new Exception('Invalid zone id');
32: }
33: return $this->execute('GET', '/zones/id/%s/', array($id));
34: }
35:
36: /**
37: *
38: * @param string $path A valid path, eg. "World|France"
39: * @return object
40: * @throws \Maniaplanet\WebServices\Exception
41: */
42: function getByPath($path)
43: {
44: if(!$path)
45: {
46: throw new Exception('Invalid zone path');
47: }
48: return $this->execute('GET', '/zones/path/%s/', array($path));
49: }
50:
51: /**
52: *
53: * @param int $offset Offset starting from 0
54: * @param int $length Length of the response
55: * @param string $sort Sort by: 'id', 'name'
56: * @param int $order Order by 1 or -1
57: * @return array Array of zones
58: * @throws \Maniaplanet\WebServices\Exception
59: */
60: function getAll($offset = 0, $length = 10, $sort = '', $order = '')
61: {
62: return $this->execute('GET',
63: '/zones/all/?offset=%s&length=%s&sort=%s&order=%s',
64: array($offset, $length, $sort, $order));
65: }
66:
67: /**
68: *
69: * @param int $id A zone id
70: * @param int $offset Offset starting from 0
71: * @param int $length Length of the response
72: * @param string $sort Sort by: 'id', 'name'
73: * @param int $order Order by 1 or -1
74: * @return array Array of zones
75: * @throws \Maniaplanet\WebServices\Exception
76: */
77: function getChildren($id, $offset = 0, $length = 10, $sort = '', $order = '')
78: {
79: if(!$id)
80: {
81: throw new Exception('Invalid zone id');
82: }
83: return $this->execute('GET',
84: '/zones/id/%s/children/?offset=%s&length=%s&sort=%s&order=%s',
85: array($id, $offset, $length, $sort, $order));
86: }
87:
88: /**
89: *
90: * @param string $path A valid path, eg. "World|France"
91: * @param int $offset Offset starting from 0
92: * @param int $length Length of the response
93: * @param string $sort Sort by: 'id', 'name'
94: * @param int $order Order by 1 or -1
95: * @return array Array of zones
96: * @throws \Maniaplanet\WebServices\Exception
97: */
98: function getChildrenByPath($path, $offset = 0, $length = 10, $sort = '',
99: $order = '')
100: {
101: if(!$path)
102: {
103: throw new Exception('Invalid zone path');
104: }
105: return $this->execute('GET',
106: '/zones/path/%s/children/?offset=%s&length=%s&sort=%s&order=%s',
107: array($path, $offset, $length, $sort, $order));
108: }
109:
110: /**
111: *
112: * @param string $path A valid path, eg. "World|France"
113: * @return int
114: * @throws \Maniaplanet\WebServices\Exception
115: */
116: function getId($path)
117: {
118: if(!$path)
119: {
120: throw new Exception('Invalid zone path');
121: }
122: return $this->execute('GET', '/zones/path/%s/id/', array($path));
123: }
124:
125: /**
126: *
127: * @param ind $id Integer identifier of the zone
128: * @return int Number of players in this zone
129: * @throws \Maniaplanet\WebServices\Exception
130: */
131: function getPopulation($id)
132: {
133: if(!$id)
134: {
135: throw new Exception('Invalid zone id');
136: }
137: return $this->execute('GET', '/zones/id/%s/population/', array($id));
138: }
139:
140: }
141:
142: ?>