Issue #1479454 by Hugo Wetterberg, galooph, dawehner, andypost, marcingy, heyrocker...
[project/drupal.git] / core / modules / user / user.views.inc
1 <?php
2
3 /**
4 * @file
5 * Provide views data and handlers for user.module.
6 *
7 * @ingroup views_module_handlers
8 */
9
10 /**
11 * Implements hook_views_data().
12 */
13 function user_views_data() {
14 // users table
15
16 // Define the base group of this table. Fields that don't
17 // have a group defined will go into this field by default.
18 $data['users']['table']['group'] = t('User');
19
20 $data['users']['table']['base'] = array(
21 'field' => 'uid',
22 'title' => t('User'),
23 'help' => t('Users who have created accounts on your site.'),
24 'access query tag' => 'user_access',
25 );
26 $data['users']['table']['entity type'] = 'user';
27 $data['users']['table']['wizard_id'] = 'user';
28
29 // uid
30 $data['users']['uid'] = array(
31 'title' => t('Uid'),
32 'help' => t('The user ID'), // The help that appears on the UI,
33 'field' => array(
34 'id' => 'user',
35 'click sortable' => TRUE,
36 ),
37 'argument' => array(
38 'id' => 'user_uid',
39 'name field' => 'name', // display this field in the summary
40 ),
41 'filter' => array(
42 'title' => t('Name'),
43 'id' => 'user_name',
44 ),
45 'sort' => array(
46 'id' => 'standard',
47 ),
48 'relationship' => array(
49 'title' => t('Content authored'),
50 'help' => t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'),
51 'id' => 'standard',
52 'base' => 'node',
53 'base field' => 'uid',
54 'field' => 'uid',
55 'label' => t('nodes'),
56 ),
57 );
58
59 // uid_raw
60 $data['users']['uid_raw'] = array(
61 'help' => t('The raw numeric user ID.'),
62 'real field' => 'uid',
63 'filter' => array(
64 'title' => t('The user ID'),
65 'id' => 'numeric',
66 ),
67 );
68
69 // uid
70 $data['users']['uid_representative'] = array(
71 'relationship' => array(
72 'title' => t('Representative node'),
73 'label' => t('Representative node'),
74 'help' => t('Obtains a single representative node for each user, according to a chosen sort criterion.'),
75 'id' => 'groupwise_max',
76 'relationship field' => 'uid',
77 'outer field' => 'users.uid',
78 'argument table' => 'users',
79 'argument field' => 'uid',
80 'base' => 'node',
81 'field' => 'nid',
82 'relationship' => 'node:uid'
83 ),
84 );
85
86 // uid
87 $data['users']['uid_current'] = array(
88 'real field' => 'uid',
89 'title' => t('Current'),
90 'help' => t('Filter the view to the currently logged in user.'),
91 'filter' => array(
92 'id' => 'user_current',
93 'type' => 'yes-no',
94 ),
95 );
96
97 // name
98 $data['users']['name'] = array(
99 'title' => t('Name'), // The item it appears as on the UI,
100 'help' => t('The user or author name.'), // The help that appears on the UI,
101 'field' => array(
102 'id' => 'user_name',
103 'click sortable' => TRUE,
104 ),
105 'sort' => array(
106 'id' => 'standard',
107 ),
108 'argument' => array(
109 'id' => 'string',
110 ),
111 'filter' => array(
112 'id' => 'string',
113 'title' => t('Name (raw)'),
114 'help' => t('The user or author name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete.')
115 ),
116 );
117
118 // mail
119 // Note that this field implements field level access control.
120 $data['users']['mail'] = array(
121 'title' => t('E-mail'), // The item it appears as on the UI,
122 '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,
123 'field' => array(
124 'id' => 'user_mail',
125 'click sortable' => TRUE,
126 ),
127 'sort' => array(
128 'id' => 'standard',
129 ),
130 'filter' => array(
131 'id' => 'string',
132 ),
133 'argument' => array(
134 'id' => 'string',
135 ),
136 );
137
138 // language
139 $data['users']['langcode'] = array(
140 'title' => t('Language'), // The item it appears as on the UI,
141 'help' => t('Language of the user'),
142 'field' => array(
143 'id' => 'user_language',
144 'click sortable' => TRUE,
145 ),
146 'sort' => array(
147 'id' => 'standard',
148 ),
149 'filter' => array(
150 'id' => 'language',
151 ),
152 'argument' => array(
153 'id' => 'language',
154 ),
155 );
156
157 // link
158 $data['users']['view_user'] = array(
159 'field' => array(
160 'title' => t('Link'),
161 'help' => t('Provide a simple link to the user.'),
162 'id' => 'user_link',
163 ),
164 );
165
166 // created field
167 $data['users']['created'] = array(
168 'title' => t('Created date'), // The item it appears as on the UI,
169 'help' => t('The date the user was created.'), // The help that appears on the UI,
170 'field' => array(
171 'id' => 'date',
172 'click sortable' => TRUE,
173 ),
174 'sort' => array(
175 'id' => 'date'
176 ),
177 'filter' => array(
178 'id' => 'date',
179 ),
180 );
181
182 $data['users']['created_fulldate'] = array(
183 'title' => t('Created date'),
184 'help' => t('Date in the form of CCYYMMDD.'),
185 'argument' => array(
186 'field' => 'created',
187 'id' => 'node_created_fulldate',
188 ),
189 );
190
191 $data['users']['created_year_month'] = array(
192 'title' => t('Created year + month'),
193 'help' => t('Date in the form of YYYYMM.'),
194 'argument' => array(
195 'field' => 'created',
196 'id' => 'node_created_year_month',
197 ),
198 );
199
200 $data['users']['created_year'] = array(
201 'title' => t('Created year'),
202 'help' => t('Date in the form of YYYY.'),
203 'argument' => array(
204 'field' => 'created',
205 'id' => 'node_created_year',
206 ),
207 );
208
209 $data['users']['created_month'] = array(
210 'title' => t('Created month'),
211 'help' => t('Date in the form of MM (01 - 12).'),
212 'argument' => array(
213 'field' => 'created',
214 'id' => 'node_created_month',
215 ),
216 );
217
218 $data['users']['created_day'] = array(
219 'title' => t('Created day'),
220 'help' => t('Date in the form of DD (01 - 31).'),
221 'argument' => array(
222 'field' => 'created',
223 'id' => 'node_created_day',
224 ),
225 );
226
227 $data['users']['created_week'] = array(
228 'title' => t('Created week'),
229 'help' => t('Date in the form of WW (01 - 53).'),
230 'argument' => array(
231 'field' => 'created',
232 'id' => 'node_created_week',
233 ),
234 );
235
236 // access field
237 $data['users']['access'] = array(
238 'title' => t('Last access'), // The item it appears as on the UI,
239 'help' => t("The user's last access date."), // The help that appears on the UI,
240 'field' => array(
241 'id' => 'date',
242 'click sortable' => TRUE,
243 ),
244 'sort' => array(
245 'id' => 'date'
246 ),
247 'filter' => array(
248 'id' => 'date',
249 ),
250 );
251
252 // login field
253 $data['users']['login'] = array(
254 'title' => t('Last login'), // The item it appears as on the UI,
255 'help' => t("The user's last login date."), // The help that appears on the UI,
256 'field' => array(
257 'id' => 'date',
258 'click sortable' => TRUE,
259 ),
260 'sort' => array(
261 'id' => 'date'
262 ),
263 'filter' => array(
264 'id' => 'date',
265 ),
266 );
267
268 // active status
269 $data['users']['status'] = array(
270 'title' => t('Active'), // The item it appears as on the UI,
271 'help' => t('Whether a user is active or blocked.'), // The help that appears on the UI,
272 // Information for displaying a title as a field
273 'field' => array(
274 'id' => 'boolean',
275 'click sortable' => TRUE,
276 'output formats' => array(
277 'active-blocked' => array(t('Active'), t('Blocked')),
278 ),
279 ),
280 'filter' => array(
281 'id' => 'boolean',
282 'label' => t('Active'),
283 'type' => 'yes-no',
284 ),
285 'sort' => array(
286 'id' => 'standard',
287 ),
288 );
289
290 // log field
291 $data['users']['signature'] = array(
292 'title' => t('Signature'), // The item it appears as on the UI,
293 'help' => t("The user's signature."), // The help that appears on the UI,
294 // Information for displaying a title as a field
295 'field' => array(
296 'id' => 'markup',
297 'format' => filter_fallback_format(),
298 ),
299 'filter' => array(
300 'id' => 'string',
301 ),
302 );
303
304 $data['users']['edit_node'] = array(
305 'field' => array(
306 'title' => t('Edit link'),
307 'help' => t('Provide a simple link to edit the user.'),
308 'id' => 'user_link_edit',
309 ),
310 );
311
312 $data['users']['cancel_node'] = array(
313 'field' => array(
314 'title' => t('Cancel link'),
315 'help' => t('Provide a simple link to cancel the user.'),
316 'id' => 'user_link_cancel',
317 ),
318 );
319
320 // users_roles table
321
322 $data['users_roles']['table']['group'] = t('User');
323
324 // Explain how this table joins to others.
325 $data['users_roles']['table']['join'] = array(
326 // Directly links to users table.
327 'users' => array(
328 'left_field' => 'uid',
329 'field' => 'uid',
330 ),
331 );
332
333 $data['users_roles']['rid'] = array(
334 'title' => t('Roles'),
335 'help' => t('Roles that a user belongs to.'),
336 'field' => array(
337 'id' => 'user_roles',
338 'no group by' => TRUE,
339 ),
340 'filter' => array(
341 'id' => 'user_roles',
342 'allow empty' => TRUE,
343 ),
344 'argument' => array(
345 'id' => 'users_roles_rid',
346 'name table' => 'role',
347 'name field' => 'name',
348 'empty field name' => t('No role'),
349 'zero is null' => TRUE,
350 'numeric' => TRUE,
351 ),
352 );
353
354 // permission table
355 $data['role_permission']['table']['group'] = t('User');
356 $data['role_permission']['table']['join'] = array(
357 // Directly links to users table.
358 'users' => array(
359 'left_table' => 'users_roles',
360 'left_field' => 'rid',
361 'field' => 'rid',
362 ),
363 );
364
365 $data['role_permission']['permission'] = array(
366 'title' => t('Permission'),
367 'help' => t('The user permissions.'),
368 'field' => array(
369 'id' => 'user_permissions',
370 'no group by' => TRUE,
371 ),
372 'filter' => array(
373 'id' => 'user_permissions',
374 ),
375 );
376
377 return $data;
378 }
379
380 /**
381 * Allow replacement of current userid so we can cache these queries
382 */
383 function user_views_query_substitutions($view) {
384 global $user;
385 return array('***CURRENT_USER***' => intval($user->uid));
386 }