#153714 by Magnus: Imported translation to localization server and removed CVS file.
[project/views.git] / modules / user.views.inc
CommitLineData
cffc1056 1<?php
a4b4d7ab
EM
2//$Id$
3/**
4 * @file
5 * Provide views data and handlers for user.module
6 */
7
8/**
9 * @defgroup views_user_module user.module handlers
10 *
11 * @{
12 */
13
14/**
15 * Implementation of hook_views_data()
16 */
cffc1056 17function user_views_data() {
83076935
EM
18 // ----------------------------------------------------------------
19 // users table
20
a4b4d7ab
EM
21 // Define the base group of this table. Fields that don't
22 // have a group defined will go into this field by default.
23 $data['users']['table']['group'] = t('User');
24
cffc1056
EM
25 $data['users']['table']['base'] = array(
26 'field' => 'uid',
27 'title' => t('User'),
8881fd4d 28 'help' => t('Users who have created accounts on your site.'),
cffc1056
EM
29 );
30
06f6fd84
EM
31 $data['users']['table']['join'] = array(
32 'node' => array(
33 'left_field' => 'uid',
34 'field' => 'uid',
34ed481b 35 'type' => 'INNER', // all nodes have an author.
06f6fd84 36 ),
6c12f53f 37 // This goes to the node so that we have consistent authorship.
06f6fd84 38 'node_revisions' => array(
34ed481b 39 'left_table' => 'node',
06f6fd84
EM
40 'left_field' => 'uid',
41 'field' => 'uid',
34ed481b 42 'type' => 'INNER', // all nodes have an author.
06f6fd84
EM
43 ),
44 );
cffc1056 45
38b3122d
EM
46 // uid
47 $data['users']['uid'] = array(
48 'title' => t('Uid'),
49 'help' => t('The user ID'), // The help that appears on the UI,
50 'field' => array(
51 'handler' => 'views_handler_field_user',
52 'click sortable' => TRUE,
53 ),
54 'argument' => array(
55 'handler' => 'views_handler_argument_user_uid',
56 'name field' => 'name', // display this field in the summary
57 ),
58 'filter' => array(
59 'title' => t('Name'),
60 'handler' => 'views_handler_filter_user_name',
61 ),
62 'sort' => array(
63 'handler' => 'views_handler_sort',
64 ),
65 );
66
67 // uid
68 $data['users']['uid_current'] = array(
69 'real field' => 'uid',
70 'title' => t('Current'),
71 'help' => t('Filter the view to the currently logged in user.'),
72 'filter' => array(
73 'handler' => 'views_handler_filter_user_current',
e598d0dd 74 'type' => 'yes-no',
38b3122d
EM
75 ),
76 );
77
a4b4d7ab
EM
78 // name
79 $data['users']['name'] = array(
cffc1056 80 'title' => t('Name'), // The item it appears as on the UI,
a4b4d7ab
EM
81 'help' => t('The user or author name.'), // The help that appears on the UI,
82 'field' => array(
a4b4d7ab 83 'handler' => 'views_handler_field_user_name',
725bd2c9 84 'click sortable' => TRUE,
a4b4d7ab 85 ),
b27116c5
EM
86 'sort' => array(
87 'handler' => 'views_handler_sort',
88 ),
06f6fd84
EM
89 'argument' => array(
90 'handler' => 'views_handler_argument_string',
91 ),
a4b4d7ab 92 );
7ae4dc41
EM
93
94 // mail
06f6fd84 95 // Note that this field implements field level access control.
7ae4dc41
EM
96 $data['users']['mail'] = array(
97 'title' => t('E-mail'), // The item it appears as on the UI,
fa00c800 98 'help' => t('Email address for a given user. This field is normally not shown to users, so be cautious when using it.'), // The help that appears on the UI,
7ae4dc41 99 'field' => array(
7ae4dc41
EM
100 'handler' => 'views_handler_field_user_mail',
101 'click sortable' => TRUE,
102 ),
06f6fd84
EM
103 'sort' => array(
104 'handler' => 'views_handler_sort',
105 ),
83076935
EM
106 'filter' => array(
107 'handler' => 'views_handler_filter_string',
108 ),
7ae4dc41
EM
109 );
110
ae6e1590
EM
111 // language
112 $data['users']['language'] = array(
113 'title' => t('Language'), // The item it appears as on the UI,
114 'help' => t('Language of the user'),
115 'field' => array(
116 'handler' => 'views_handler_field_user_language',
117 'click sortable' => TRUE,
118 ),
119 'sort' => array(
120 'handler' => 'views_handler_sort',
121 ),
122 'filter' => array(
03cc197d 123 'handler' => 'views_handler_filter_node_language',
ae6e1590
EM
124 ),
125 );
126
06f6fd84
EM
127 // picture
128 $data['users']['picture'] = array(
129 'title' => t('Picture'),
ad2ba848 130 'help' => t("The user's picture, if allowed."), // The help that appears on the UI,
06f6fd84
EM
131 // Information for displaying the uid
132 'field' => array(
06f6fd84
EM
133 'handler' => 'views_handler_field_user_picture',
134 'click sortable' => TRUE,
135 ),
c42a7a1b
EM
136 'sort' => array(
137 'handler' => 'views_handler_sort',
138 ),
dcb189ee
EM
139 'filter' => array(
140 'handler' => 'views_handler_filter_boolean_operator_string',
141 'label' => t('Has Avatar'),
e598d0dd 142 'type' => 'yes-no',
dcb189ee 143 ),
06f6fd84
EM
144 );
145
146 // created field
147 $data['users']['created'] = array(
148 'title' => t('Created date'), // The item it appears as on the UI,
149 'help' => t('The date the user was created.'), // The help that appears on the UI,
150 'field' => array(
151 'handler' => 'views_handler_field_date',
152 'click sortable' => TRUE,
153 ),
154 'sort' => array(
155 'handler' => 'views_handler_sort_date',
156 ),
157 'filter' => array(
158 'handler' => 'views_handler_filter_date',
159 ),
160 );
161
162 // access field
163 $data['users']['access'] = array(
164 'title' => t('Last access'), // The item it appears as on the UI,
ad2ba848 165 'help' => t("The user's last access date."), // The help that appears on the UI,
06f6fd84
EM
166 'field' => array(
167 'handler' => 'views_handler_field_date',
168 'click sortable' => TRUE,
169 ),
170 'sort' => array(
171 'handler' => 'views_handler_sort_date',
172 ),
173 'filter' => array(
174 'handler' => 'views_handler_filter_date',
175 ),
176 );
177
178 // login field
179 $data['users']['login'] = array(
180 'title' => t('Last login'), // The item it appears as on the UI,
ad2ba848 181 'help' => t("The user's last login date."), // The help that appears on the UI,
06f6fd84
EM
182 'field' => array(
183 'handler' => 'views_handler_field_date',
184 'click sortable' => TRUE,
185 ),
186 'sort' => array(
187 'handler' => 'views_handler_sort_date',
188 ),
189 'filter' => array(
190 'handler' => 'views_handler_filter_date',
191 ),
192 );
b27116c5 193
06f6fd84
EM
194 // published status
195 $data['users']['status'] = array(
196 'title' => t('Active'), // The item it appears as on the UI,
197 'help' => t('Whether a user is active or blocked.'), // The help that appears on the UI,
198 // Information for displaying a title as a field
199 'field' => array(
200 'handler' => 'views_handler_field_boolean',
201 'click sortable' => TRUE,
202 ),
203 'filter' => array(
204 'handler' => 'views_handler_filter_boolean_operator',
eeaee424 205 'label' => t('Active'),
e598d0dd 206 'type' => 'yes-no',
06f6fd84
EM
207 ),
208 'sort' => array(
209 'handler' => 'views_handler_sort',
210 ),
211 );
212
213 // log field
214 $data['users']['signature'] = array(
215 'title' => t('Signature'), // The item it appears as on the UI,
ad2ba848 216 'help' => t("The user's signature."), // The help that appears on the UI,
06f6fd84
EM
217 // Information for displaying a title as a field
218 'field' => array(
219 'handler' => 'views_handler_field_xss',
220 ),
221 'filter' => array(
222 'handler' => 'views_handler_filter_string',
223 ),
224 );
225
b57c309a
EM
226 $data['users']['edit_node'] = array(
227 'field' => array(
228 'title' => t('Edit link'),
229 'help' => t('Provide a simple link to edit the user.'),
230 'handler' => 'views_handler_field_user_link_edit',
231 ),
232 );
233
234 $data['users']['delete_node'] = array(
235 'field' => array(
236 'title' => t('Delete link'),
237 'help' => t('Provide a simple link to delete the user.'),
238 'handler' => 'views_handler_field_user_link_delete',
239 ),
240 );
241
06f6fd84 242 // ----------------------------------------------------------------------
83076935 243 // users_roles table
06f6fd84
EM
244
245 $data['users_roles']['table']['group'] = t('User');
246
247 // Explain how this table joins to others.
248 $data['users_roles']['table']['join'] = array(
249 // Directly links to users table.
250 'users' => array(
251 'left_field' => 'uid',
252 'field' => 'uid',
9aed44cc 253 ),
06f6fd84 254 'node' => array(
06f6fd84
EM
255 'left_field' => 'uid',
256 'field' => 'uid',
9aed44cc 257 ),
06f6fd84 258 'node_revisions' => array(
b98bccca 259 'left_table' => 'node',
06f6fd84
EM
260 'left_field' => 'uid',
261 'field' => 'uid',
262 ),
263 );
264
06f6fd84 265 $data['users_roles']['rid'] = array(
9aed44cc 266 'title' => t('Roles'),
d8aa7200 267 'help' => t('Roles that a user belongs to.'),
06f6fd84
EM
268 'field' => array(
269 'handler' => 'views_handler_field_user_roles',
270 ),
271 'filter' => array(
272 'handler' => 'views_handler_filter_user_roles',
273 'numeric' => TRUE,
274 ),
83076935
EM
275 'argument' => array(
276 'handler' => 'views_handler_argument_users_roles_rid',
277 'name table' => 'role',
278 'name field' => 'name',
b2b1dd2a 279 'empty field name' => t('No role'),
83076935
EM
280 'numeric' => TRUE,
281 ),
282 );
283
284 // ----------------------------------------------------------------------
285 // role table
286
287 $data['role']['table']['join'] = array(
288 // Directly links to users table.
289 'users' => array(
290 'left_table' => 'users_roles',
291 'left_field' => 'rid',
292 'field' => 'rid',
293 ),
4d6c659c
EM
294 // needed for many to one helper sometimes
295 'users_roles' => array(
296 'left_field' => 'rid',
297 'field' => 'rid',
298 ),
83076935
EM
299 'node' => array(
300 'left_table' => 'users_roles',
301 'left_field' => 'rid',
302 'field' => 'rid',
303 ),
304 'node_revisions' => array(
305 'left_table' => 'users_roles',
306 'left_field' => 'rid',
307 'field' => 'rid',
308 ),
06f6fd84
EM
309 );
310
cffc1056 311 return $data;
a4b4d7ab
EM
312}
313
a4b4d7ab 314/**
fd5edb77
EM
315 * Implementation of hook_views_plugins
316 */
317function user_views_plugins() {
318 return array(
319 'module' => 'views', // This just tells our themes are elsewhere.
fd5edb77
EM
320 'argument default' => array(
321 'user' => array(
322 'title' => t('User ID from URL'),
323 'handler' => 'views_plugin_argument_default_user',
6ed05843 324 'path' => drupal_get_path('module', 'views') . '/modules/user', // not necessary for most modules
fe44beb7 325 'parent' => 'fixed', // so that the parent class is included
b98b186a
EM
326 ),
327 'current_user' => array(
328 'title' => t('User ID from logged in user'),
329 'handler' => 'views_plugin_argument_default_current_user',
330 'path' => drupal_get_path('module', 'views') . '/modules/user', // not necessary for most modules
331 'parent' => 'fixed', // so that the parent class is included
fd5edb77
EM
332 ),
333 ),
ed484da5
EM
334 'argument validator' => array(
335 'user' => array(
336 'title' => t('User'),
337 'handler' => 'views_plugin_argument_validate_user',
338 'path' => drupal_get_path('module', 'views') . '/modules/user', // not necessary for most modules
339 ),
340 ),
fd5edb77
EM
341 );
342}
343
344/**
fe44beb7
EM
345 * Implementation of hook_views_handlers() to register all of the basic handlers
346 * views uses.
fd5edb77 347 */
fe44beb7
EM
348function user_views_handlers() {
349 return array(
350 'info' => array(
351 'path' => drupal_get_path('module', 'views') . '/modules/user',
352 ),
353 'handlers' => array(
354 'views_handler_argument_user_uid' => array(
355 'parent' => 'views_handler_argument_numeric',
fd5edb77 356 ),
fe44beb7
EM
357 'views_handler_field_user' => array(
358 'parent' => 'views_handler_field',
06f6fd84 359 ),
fe44beb7
EM
360 'views_handler_field_user_name' => array(
361 'parent' => 'views_handler_field_user',
362 ),
363 'views_handler_field_user_link' => array(
364 'parent' => 'views_handler_field',
365 ),
366 'views_handler_field_user_link_edit' => array(
367 'parent' => 'views_handler_field_user_link',
368 ),
369 'views_handler_field_user_link_delete' => array(
370 'parent' => 'views_handler_field_user_link',
371 ),
372 'views_handler_field_user_mail' => array(
373 'parent' => 'views_handler_field_user',
374 ),
ae6e1590
EM
375 'views_handler_field_user_language' => array(
376 'parent' => 'views_handler_field_user',
377 ),
fe44beb7
EM
378 'views_handler_field_user_picture' => array(
379 'parent' => 'views_handler_field',
380 ),
9afd38ad
EM
381 'views_handler_field_user_roles' => array(
382 'parent' => 'views_handler_field_prerender_list',
383 ),
fe44beb7
EM
384 'views_handler_filter_user_name' => array(
385 'parent' => 'views_handler_filter_in_operator',
386 ),
387 'views_handler_filter_user_current' => array(
388 'parent' => 'views_handler_filter_boolean_operator',
389 ),
390 'views_handler_filter_user_roles' => array(
391 'parent' => 'views_handler_filter_many_to_one',
392 ),
393 'views_handler_argument_users_roles_rid' => array(
394 'parent' => 'views_handler_argument_many_to_one',
395 ),
396 ),
397 );
38b3122d
EM
398}
399
06f6fd84
EM
400
401/**
0766852e
EM
402 * Allow replacement of current userid so we can cache these queries
403 */
404function user_views_query_substitutions($view) {
405 global $user;
406 return array('***CURRENT_USER***' => intval($user->uid));
407}
a4b4d7ab
EM
408
409/**
410 * @}
411 */