1
+ <?php
2
+ /**
3
+ * File that stores api calls for venue api calls
4
+ * @package apicalls
5
+ */
6
+ /**
7
+ * Allows access to the api requests relating to venues
8
+ * @package apicalls
9
+ */
10
+ class lastfmApiVenue extends lastfmApi {
11
+ /**
12
+ * Stores the config values set in the call
13
+ * @access public
14
+ * @var array
15
+ */
16
+ public $ config ;
17
+ /**
18
+ * Stores the auth variables used in all api calls
19
+ * @access private
20
+ * @var array
21
+ */
22
+ private $ auth ;
23
+ /**
24
+ * States if the user has full authentication to use api requests that modify data
25
+ * @access private
26
+ * @var boolean
27
+ */
28
+ private $ fullAuth ;
29
+
30
+ /**
31
+ * @param array $auth Passes the authentication variables
32
+ * @param array $fullAuth A boolean value stating if the user has full authentication or not
33
+ * @param array $config An array of config variables related to caching and other features
34
+ */
35
+ function __construct ($ auth , $ fullAuth , $ config ) {
36
+ $ this ->auth = $ auth ;
37
+ $ this ->fullAuth = $ fullAuth ;
38
+ $ this ->config = $ config ;
39
+ }
40
+
41
+ /**
42
+ * Get a list of upcoming events at this venue
43
+ * @param array $methodVars An array with the following required value: <i>venue</i>
44
+ * @return array
45
+ */
46
+ public function getEvents ($ methodVars ) {
47
+ if ( !empty ($ methodVars ['venue ' ]) ) {
48
+ $ vars = array (
49
+ 'method ' => 'venue.getEvents ' ,
50
+ 'api_key ' => $ this ->auth ->apiKey ,
51
+ 'venue ' => $ methodVars ['venue ' ]
52
+ );
53
+
54
+ if ( $ call = $ this ->apiGetCall ($ vars ) ) {
55
+ if ( count ($ call ->events ->event ) > 0 ) {
56
+ $ events = array ();
57
+ $ events ['venue_name ' ] = (string ) $ call ->events ['venue ' ];
58
+ $ i = 0 ;
59
+ foreach ( $ call ->events ->event as $ event ) {
60
+ $ events ['event ' ][$ i ]['id ' ] = (string ) $ event ->id ;
61
+ $ events ['event ' ][$ i ]['status ' ] = (string ) $ event ['status ' ];
62
+ $ events ['event ' ][$ i ]['title ' ] = (string ) $ event ->title ;
63
+ if ( count ($ event ->artists ->artist ) > 0 ) {
64
+ foreach ( $ event ->artists ->artist as $ artist ) {
65
+ $ events ['event ' ][$ i ]['artists ' ][] = (string ) $ artist ;
66
+ }
67
+ }
68
+ $ events ['event ' ][$ i ]['headliner ' ] = (string ) $ event ->artists ->headliner ;
69
+ $ events ['event ' ][$ i ]['venue ' ]['id ' ] = (string ) $ event ->venue ->id ;
70
+ $ events ['event ' ][$ i ]['venue ' ]['name ' ] = (string ) $ event ->venue ->name ;
71
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['city ' ] = (string ) $ event ->venue ->location ->city ;
72
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['country ' ] = (string ) $ event ->venue ->location ->country ;
73
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['street ' ] = (string ) $ event ->venue ->location ->street ;
74
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['postalcode ' ] = (string ) $ event ->venue ->location ->postalcode ;
75
+ $ geoPoints = $ event ->venue ->location ->children ('http://www.w3.org/2003/01/geo/wgs84_pos# ' );
76
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['geopoint ' ]['lat ' ] = (string ) $ geoPoints ->point ->lat ;
77
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['geopoint ' ]['long ' ] = (string ) $ geoPoints ->point ->long ;
78
+ $ events ['event ' ][$ i ]['venue ' ]['url ' ] = (string ) $ event ->venue ->url ;
79
+ $ events ['event ' ][$ i ]['startDate ' ] = (string ) strtotime ($ event ->startDate );
80
+ $ events ['event ' ][$ i ]['description ' ] = (string ) $ event ->description ;
81
+ $ events ['event ' ][$ i ]['image ' ]['small ' ] = (string ) $ event ->image [0 ];
82
+ $ events ['event ' ][$ i ]['image ' ]['medium ' ] = (string ) $ event ->image [1 ];
83
+ $ events ['event ' ][$ i ]['image ' ]['large ' ] = (string ) $ event ->image [2 ];
84
+ $ events ['event ' ][$ i ]['attendance ' ] = (string ) $ event ->attendance ;
85
+ $ events ['event ' ][$ i ]['reviews ' ] = (string ) $ event ->reviews ;
86
+ $ events ['event ' ][$ i ]['tag ' ] = (string ) $ event ->tag ;
87
+ $ events ['event ' ][$ i ]['url ' ] = (string ) $ event ->url ;
88
+ $ i ++;
89
+ }
90
+
91
+ return $ events ;
92
+ }
93
+ else {
94
+ $ this ->handleError (90 , 'There is no events for this venue ' );
95
+ return FALSE ;
96
+ }
97
+ }
98
+ else {
99
+ return FALSE ;
100
+ }
101
+ }
102
+ else {
103
+ // Give a 91 error if incorrect variables are used
104
+ $ this ->handleError (91 , 'You must include the venue variable in the call for this method ' );
105
+ return FALSE ;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Get a paginated list of all the events held at this venue in the past
111
+ * @param array $methodVars An array with the following required value: <i>venue</i> and optional values: <i>page</i>, <i>limit</i>
112
+ * @return array
113
+ */
114
+ public function getPastEvents ($ methodVars ) {
115
+ if ( !empty ($ methodVars ['venue ' ]) ) {
116
+ $ vars = array (
117
+ 'method ' => 'venue.getPastEvents ' ,
118
+ 'api_key ' => $ this ->auth ->apiKey ,
119
+ 'venue ' => $ methodVars ['venue ' ]
120
+ );
121
+ if ( !empty ($ methodVars ['limit ' ]) ) {
122
+ $ vars ['limit ' ] = $ methodVars ['limit ' ];
123
+ }
124
+ if ( !empty ($ methodVars ['page ' ]) ) {
125
+ $ vars ['page ' ] = $ methodVars ['page ' ];
126
+ }
127
+
128
+ if ( $ call = $ this ->apiGetCall ($ vars ) ) {
129
+ if ( count ($ call ->events ->event ) > 0 ) {
130
+ $ events = array ();
131
+ $ events ['venue_name ' ] = (string ) $ call ->events ['venue ' ];
132
+ $ events ['page ' ] = (string ) $ call ->events ['page ' ];
133
+ $ events ['perPage ' ] = (string ) $ call ->events ['perPage ' ];
134
+ $ events ['total ' ] = (string ) $ call ->events ['total ' ];
135
+ $ events ['totalPages ' ] = (string ) $ call ->events ['totalPages ' ];
136
+ $ i = 0 ;
137
+ foreach ( $ call ->events ->event as $ event ) {
138
+ $ events ['event ' ][$ i ]['id ' ] = (string ) $ event ->id ;
139
+ $ events ['event ' ][$ i ]['status ' ] = (string ) $ event ['status ' ];
140
+ $ events ['event ' ][$ i ]['title ' ] = (string ) $ event ->title ;
141
+ if ( count ($ event ->artists ->artist ) > 0 ) {
142
+ foreach ( $ event ->artists ->artist as $ artist ) {
143
+ $ events ['event ' ][$ i ]['artists ' ][] = (string ) $ artist ;
144
+ }
145
+ }
146
+ $ events ['event ' ][$ i ]['headliner ' ] = (string ) $ event ->artists ->headliner ;
147
+ $ events ['event ' ][$ i ]['venue ' ]['id ' ] = (string ) $ event ->venue ->id ;
148
+ $ events ['event ' ][$ i ]['venue ' ]['name ' ] = (string ) $ event ->venue ->name ;
149
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['city ' ] = (string ) $ event ->venue ->location ->city ;
150
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['country ' ] = (string ) $ event ->venue ->location ->country ;
151
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['street ' ] = (string ) $ event ->venue ->location ->street ;
152
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['postalcode ' ] = (string ) $ event ->venue ->location ->postalcode ;
153
+ $ geoPoints = $ event ->venue ->location ->children ('http://www.w3.org/2003/01/geo/wgs84_pos# ' );
154
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['geopoint ' ]['lat ' ] = (string ) $ geoPoints ->point ->lat ;
155
+ $ events ['event ' ][$ i ]['venue ' ]['location ' ]['geopoint ' ]['long ' ] = (string ) $ geoPoints ->point ->long ;
156
+ $ events ['event ' ][$ i ]['venue ' ]['url ' ] = (string ) $ event ->venue ->url ;
157
+ $ events ['event ' ][$ i ]['startDate ' ] = (string ) strtotime ($ event ->startDate );
158
+ $ events ['event ' ][$ i ]['description ' ] = (string ) $ event ->description ;
159
+ $ events ['event ' ][$ i ]['image ' ]['small ' ] = (string ) $ event ->image [0 ];
160
+ $ events ['event ' ][$ i ]['image ' ]['medium ' ] = (string ) $ event ->image [1 ];
161
+ $ events ['event ' ][$ i ]['image ' ]['large ' ] = (string ) $ event ->image [2 ];
162
+ $ events ['event ' ][$ i ]['attendance ' ] = (string ) $ event ->attendance ;
163
+ $ events ['event ' ][$ i ]['reviews ' ] = (string ) $ event ->reviews ;
164
+ $ events ['event ' ][$ i ]['tag ' ] = (string ) $ event ->tag ;
165
+ $ events ['event ' ][$ i ]['url ' ] = (string ) $ event ->url ;
166
+ $ i ++;
167
+ }
168
+
169
+ return $ events ;
170
+ }
171
+ else {
172
+ $ this ->handleError (90 , 'There is no past events for this venue ' );
173
+ return FALSE ;
174
+ }
175
+ }
176
+ else {
177
+ return FALSE ;
178
+ }
179
+ }
180
+ else {
181
+ // Give a 91 error if incorrect variables are used
182
+ $ this ->handleError (91 , 'You must include the venue variable in the call for this method ' );
183
+ return FALSE ;
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Search for a venue by venue name
189
+ * @param array $methodVars An array with the following required value: <i>venue</i> and optional values: <i>limit</i>, <i>page</i>, <i>county</i>
190
+ * @return array
191
+ */
192
+ public function search ($ methodVars ) {
193
+ // Check for required variables
194
+ if ( !empty ($ methodVars ['venue ' ]) ) {
195
+ $ vars = array (
196
+ 'method ' => 'venue.search ' ,
197
+ 'api_key ' => $ this ->auth ->apiKey ,
198
+ 'venue ' => $ methodVars ['venue ' ]
199
+ );
200
+ if ( !empty ($ methodVars ['limit ' ]) ) {
201
+ $ vars ['limit ' ] = $ methodVars ['limit ' ];
202
+ }
203
+ if ( !empty ($ methodVars ['page ' ]) ) {
204
+ $ vars ['page ' ] = $ methodVars ['page ' ];
205
+ }
206
+ if ( !empty ($ methodVars ['country ' ]) ) {
207
+ $ vars ['country ' ] = $ methodVars ['country ' ];
208
+ }
209
+
210
+ if ( $ call = $ this ->apiGetCall ($ vars ) ) {
211
+ $ opensearch = $ call ->results ->children ('http://a9.com/-/spec/opensearch/1.1/ ' );
212
+ if ( $ opensearch ->totalResults > 0 ) {
213
+ $ searchResults ['totalResults ' ] = (string ) $ opensearch ->totalResults ;
214
+ $ searchResults ['startIndex ' ] = (string ) $ opensearch ->startIndex ;
215
+ $ searchResults ['itemsPerPage ' ] = (string ) $ opensearch ->itemsPerPage ;
216
+ $ i = 0 ;
217
+ foreach ( $ call ->results ->venuematches ->venue as $ venue ) {
218
+ $ searchResults ['results ' ][$ i ]['id ' ] = (string ) $ venue ->id ;
219
+ $ searchResults ['results ' ][$ i ]['name ' ] = (string ) $ venue ->name ;
220
+ $ searchResults ['results ' ][$ i ]['location ' ]['city ' ] = (string ) $ venue ->location ->city ;
221
+ $ searchResults ['results ' ][$ i ]['location ' ]['country ' ] = (string ) $ venue ->location ->country ;
222
+ $ searchResults ['results ' ][$ i ]['location ' ]['street ' ] = (string ) $ venue ->location ->street ;
223
+ $ searchResults ['results ' ][$ i ]['location ' ]['postalcode ' ] = (string ) $ venue ->location ->postalcode ;
224
+ $ geoPoints = $ venue ->location ->children ('http://www.w3.org/2003/01/geo/wgs84_pos# ' );
225
+ $ searchResults ['results ' ][$ i ]['location ' ]['geopoint ' ]['lat ' ] = (string ) $ geoPoints ->point ->lat ;
226
+ $ searchResults ['results ' ][$ i ]['location ' ]['geopoint ' ]['long ' ] = (string ) $ geoPoints ->point ->long ;
227
+ $ searchResults ['results ' ][$ i ]['url ' ] = (string ) $ venue ->url ;
228
+ $ i ++;
229
+ }
230
+
231
+ return $ searchResults ;
232
+ }
233
+ else {
234
+ // No tagsare found
235
+ $ this ->handleError (90 , 'No results ' );
236
+ return FALSE ;
237
+ }
238
+ }
239
+ else {
240
+ return FALSE ;
241
+ }
242
+ }
243
+ else {
244
+ // Give a 91 error if incorrect variables are used
245
+ $ this ->handleError (91 , 'You must include artist varialbe in the call for this method ' );
246
+ return FALSE ;
247
+ }
248
+ }
249
+ }
250
+
251
+ ?>
0 commit comments