/[drupal]/contributions/modules/location/location.views.inc
ViewVC logotype

Contents of /contributions/modules/location/location.views.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.16 - (show annotations) (download) (as text)
Wed Dec 3 22:51:23 2008 UTC (11 months, 3 weeks ago) by bdragon
Branch: MAIN
CVS Tags: DRUPAL-6--3-1-RC1, DRUPAL-6--3-0, HEAD
Branch point for: DRUPAL-6--3
Changes since 1.15: +29 -14 lines
File MIME type: text/x-php
#321114, by danielnolde et al, patch by me: Reimplement and spiff up proximity search.

This involved a lot of interesting code, and quite probabaly still has some lingering bugs. I'm very happy with how it turned out, though.
1 <?php
2 // $Id: location.views.inc,v 1.15 2008/12/02 22:50:21 bdragon Exp $
3
4 /**
5 * @file
6 * Views 2 support for Location.
7 */
8
9 /*
10
11 TODO:
12 * Finish porting!
13 * Write "relationships" -- see book.views.inc, upload.views.inc, nodequeue...
14
15
16 */
17
18 /**
19 * Implementation of hook_views_handlers().
20 */
21 function location_views_handlers() {
22 return array(
23 'info' => array(
24 'path' => drupal_get_path('module', 'location') .'/handlers',
25 ),
26 'handlers' => array(
27 'location_views_handler_field_latitude' => array(
28 'parent' => 'views_handler_field',
29 ),
30 'location_views_handler_field_longitude' => array(
31 'parent' => 'location_views_handler_field_latitude',
32 ),
33 'location_views_handler_field_coordinates' => array(
34 'parent' => 'location_views_handler_field_latitude',
35 ),
36 'location_handler_field_location_country' => array(
37 'parent' => 'views_handler_field',
38 ),
39 'location_handler_filter_location_country' => array(
40 'parent' => 'views_handler_filter',
41 ),
42 'location_handler_argument_location_country' => array(
43 'parent' => 'views_handler_argument',
44 ),
45 'location_handler_field_location_province' => array(
46 'parent' => 'views_handler_field',
47 ),
48 'location_handler_filter_location_province' => array(
49 'parent' => 'views_handler_filter',
50 ),
51 'location_handler_argument_location_province' => array(
52 'parent' => 'views_handler_argument',
53 ),
54 'location_handler_field_location_address' => array(
55 'parent' => 'views_handler_field',
56 ),
57 'location_handler_field_location_street' => array(
58 'parent' => 'views_handler_field',
59 ),
60 'location_views_handler_filter_proximity' => array(
61 'parent' => 'views_handler_filter',
62 ),
63 'location_handler_field_location_distance' => array(
64 'parent' => 'views_handler_field',
65 ),
66 'location_handler_sort_location_distance' => array(
67 'parent' => 'views_handler_sort',
68 ),
69 // 'location_handler_relationship_location_distance' => array(
70 // 'parent' => 'views_handler_relationship',
71 // ),
72
73 // 'location_handler_field_location_coordinates_user' => array(
74 // 'parent' => 'views_handler_field',
75 // ),
76
77 ),
78 );
79 }
80
81 /**
82 * Implementation of hook_views_data().
83 */
84 function location_views_data() {
85 // ----------------------------------------------------------------
86 // location table -- basic table information.
87
88 // Define the base group of this table. Fields that don't
89 // have a group defined will go into this field by default.
90
91 $data['location']['table']['group'] = t('Location');
92
93 // Advertise this table as a possible base table
94 $data['location']['table']['base'] = array(
95 'field' => 'lid',
96 'title' => t('Location'),
97 'help' => t('Locations are addresses and map coordinates.'),
98 'weight' => -10,
99 );
100
101 $data['location']['table']['join'] = array(
102 // Location links to node through location_instance via lid.
103 'node' => array(
104 'left_table' => 'location_instance',
105 'left_field' => 'lid',
106 'field' => 'lid',
107 ),
108 // Location links to node_revisions through location_instance via lid.
109 'node_revisions' => array(
110 'left_table' => 'location_instance',
111 'left_field' => 'lid',
112 'field' => 'lid',
113 ),
114 // Location links to users through location_instance via lid.
115 'users' => array(
116 'left_table' => 'location_instance',
117 'left_field' => 'lid',
118 'field' => 'lid',
119 ),
120 );
121
122 // ----------------------------------------------------------------
123 // location table -- fields
124
125 // lid
126 $data['location']['lid'] = array(
127 'title' => t('Lid'),
128 'help' => t('The location ID of the location.'), // The help that appears on the UI,
129 // Information for displaying the lid
130 'field' => array(
131 'handler' => 'views_handler_field', // @@@
132 'click sortable' => TRUE,
133 ),
134 // Information for accepting a lid as an argument
135 /*
136 'argument' => array(
137 'handler' => 'views_handler_argument_node_nid',
138 'name field' => 'title', // the field to display in the summary.
139 'numeric' => TRUE,
140 'validate type' => 'nid',
141 ),
142 */
143 // Information for accepting a lid as a filter
144 'filter' => array(
145 'handler' => 'views_handler_filter_numeric',
146 'allow empty' => TRUE,
147 ),
148 // Information for sorting on a lid.
149 'sort' => array(
150 'handler' => 'views_handler_sort',
151 ),
152 );
153
154 $data['location']['name'] = array(
155 'title' => t('Name'),
156 'help' => t('The name of the selected location.'),
157 'field' => array(
158 'click sortable' => TRUE,
159 ),
160 'filter' => array(
161 'handler' => 'views_handler_filter_string',
162 ),
163 'sort' => array(
164 'handler' => 'views_handler_sort',
165 ),
166 );
167
168 // @@@ 1.x Conversion -- 'additional' => 'street', style 'additional'
169 $data['location']['street'] = array(
170 'title' => t('Street'),
171 'help' => t('The street address of the selected location.'),
172 'field' => array(
173 'handler' => 'location_handler_field_location_street',
174 'click sortable' => TRUE,
175 ),
176 'filter' => array(
177 'handler' => 'views_handler_filter_string',
178 ),
179 'sort' => array(
180 'handler' => 'views_handler_sort',
181 ),
182 );
183
184 $data['location']['city'] = array(
185 'title' => t('City'),
186 'help' => t('The city of the selected location.'),
187 'field' => array(
188 'click sortable' => TRUE,
189 ),
190 'argument' => array(
191 'handler' => 'views_handler_argument_string',
192 'empty field name' => t('Unknown'),
193 ),
194 'filter' => array(
195 'handler' => 'views_handler_filter_string',
196 ),
197 'sort' => array(
198 'handler' => 'views_handler_sort',
199 ),
200 );
201
202 // @@@ 1.x Conversion -- 'province' => 'province', style 'name'; 'province_code' => 'province', style 'code'
203 $data['location']['province'] = array(
204 'title' => t('Province'),
205 'help' => t('The province of the selected location.'),
206 'field' => array(
207 'handler' => 'location_handler_field_location_province',
208 'click sortable' => TRUE,
209 ),
210 'argument' => array(
211 'handler' => 'location_handler_argument_location_province',
212 //'name field' => 'name',
213 ),
214 'filter' => array(
215 'handler' => 'location_handler_filter_location_province',
216 ),
217 'sort' => array(
218 'handler' => 'views_handler_sort',
219 // TODO: needs handler to sort by name, not code
220 ),
221 );
222
223 $data['location']['postal_code'] = array(
224 'title' => t('Postal Code'),
225 'help' => t('The postal code of the selected location.'),
226 'field' => array(
227 'click sortable' => TRUE,
228 ),
229 'filter' => array(
230 'handler' => 'views_handler_filter_string',
231 ),
232 'sort' => array(
233 'handler' => 'views_handler_sort',
234 ),
235 );
236
237 // @@@ 1.x Conversion -- 'country' => 'country', style 'name'; 'country_code' => 'country', style 'code'.
238 $data['location']['country'] = array(
239 'title' => t('Country'),
240 'help' => t('The country of the selected location.'),
241 'field' => array(
242 'handler' => 'location_handler_field_location_country',
243 'click sortable' => TRUE,
244 ),
245 'argument' => array(
246 'handler' => 'location_handler_argument_location_country',
247 //'name field' => 'name',
248 ),
249 'filter' => array(
250 'handler' => 'location_handler_filter_location_country',
251 ),
252 'sort' => array(
253 'handler' => 'views_handler_sort',
254 // TODO: needs handler to sort by name, not code
255 ),
256 );
257
258 $data['location']['latitude'] = array(
259 'title' => t('Latitude'),
260 'help' => t('The latitude of the selected location.'),
261 'field' => array(
262 'handler' => 'location_views_handler_field_latitude',
263 'click sortable' => TRUE,
264 ),
265 'filter' => array(
266 'handler' => 'views_handler_filter_numeric',
267 ),
268 'sort' => array(
269 'handler' => 'views_handler_sort',
270 ),
271 );
272 $data['location']['longitude'] = array(
273 'title' => t('Longitude'),
274 'help' => t('The longitude of the selected location.'),
275 'field' => array(
276 'handler' => 'location_views_handler_field_longitude',
277 'click sortable' => TRUE,
278 ),
279 'filter' => array(
280 'handler' => 'views_handler_filter_numeric',
281 ),
282 'sort' => array(
283 'handler' => 'views_handler_sort',
284 ),
285 );
286 $data['location']['coordinates'] = array(
287 'title' => t('Coordinates'),
288 'help' => t("The coordinates of the selected location in 'lat, long' format."),
289 'field' => array(
290 'field' => 'latitude', // The handler adds the longitude.
291 'handler' => 'location_views_handler_field_coordinates',
292 'click sortable' => FALSE,
293 ),
294 );
295
296 $data['location']['distance'] = array(
297 'title' => t('Distance / Proximity'),
298 'help' => t("The distance from the selected location and either the current user or a specific location."),
299 'field' => array(
300 'handler' => 'location_handler_field_location_distance',
301 'click sortable' => TRUE,
302 ),
303 'sort' => array(
304 'handler' => 'location_handler_sort_location_distance',
305 ),
306 'filter' => array(
307 'handler' => 'location_views_handler_filter_proximity',
308 ),
309 // 'relationship' => array(
310 // 'handler' => 'location_handler_relationship_location_distance',
311 // ),
312 );
313
314 // $data['location']['coordinates_user'] = array(
315 // 'title' => t('Coordinates of logged-on user'),
316 // 'help' => t('This will contain the coordinates of the logged-on user.'),
317 // 'field' => array(
318 // 'handler' => 'location_handler_field_location_coordinates_user',
319 // 'click sortable' => FALSE,
320 // ),
321 // );
322
323 /*
324 'latitude' => array(
325 'name' => t('Latitude'),
326 'sortable' => TRUE,
327 ),
328 'longitude' => array(
329 'name' => t('Longitude'),
330 'sortable' => TRUE,
331 ),
332 */
333
334
335 $data['location']['address'] = array(
336 'title' => t('Address'),
337 'help' => t('The entire address block for the location.'),
338 'field' => array(
339 'field' => 'lid',
340 'handler' => 'location_handler_field_location_address',
341 ),
342 );
343
344
345 $data['location_instance']['table']['group'] = t('Location');
346
347 $data['location_instance']['table']['join'] = array(
348 'location' => array(
349 'left_field' => 'lid',
350 'field' => 'lid',
351 ),
352 'users' => array(
353 'left_field' => 'uid',
354 'field' => 'uid',
355 ),
356 'node' => array(
357 'left_field' => 'vid',
358 'field' => 'vid',
359 ),
360 'node_revisions' => array(
361 'left_field' => 'vid',
362 'field' => 'vid',
363 ),
364 );
365
366
367 // Tell the base tables about us.
368 $data['node']['table']['join']['location'] = array(
369 'left_table' => 'location_instance',
370 'left_field' => 'vid',
371 'field' => 'vid',
372 );
373 $data['node_revisions']['table']['join']['location'] = array(
374 'left_table' => 'location_instance',
375 'left_field' => 'vid',
376 'field' => 'vid',
377 );
378 $data['users']['table']['join']['location'] = array(
379 'left_table' => 'location_instance',
380 'left_field' => 'uid',
381 'field' => 'uid',
382 );
383
384 return $data;
385 }

  ViewVC Help
Powered by ViewVC 1.1.2