user.views.inc 11.4 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php

/**
 * @file
 * Provide views data and handlers for user.module.
 *
 * @ingroup views_module_handlers
 */

/**
 * Implements hook_views_data().
 */
function user_views_data() {
  // users table

  // Define the base group of this table. Fields that don't
  // have a group defined will go into this field by default.
  $data['users']['table']['group']  = t('User');

  $data['users']['table']['base'] = array(
    'field' => 'uid',
    'title' => t('User'),
    'help' => t('Users who have created accounts on your site.'),
    'access query tag' => 'user_access',
  );
  $data['users']['table']['entity type'] = 'user';
27
  $data['users']['table']['wizard_id'] = 'user';
merlinofchaos's avatar
merlinofchaos committed
28 29 30 31 32 33

  // uid
  $data['users']['uid'] = array(
    'title' => t('Uid'),
    'help' => t('The user ID'), // The help that appears on the UI,
    'field' => array(
aspilicious's avatar
aspilicious committed
34
      'id' => 'user',
merlinofchaos's avatar
merlinofchaos committed
35 36 37
      'click sortable' => TRUE,
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
38
      'id' => 'user_uid',
merlinofchaos's avatar
merlinofchaos committed
39 40 41 42
      'name field' => 'name', // display this field in the summary
    ),
    'filter' => array(
      'title' => t('Name'),
aspilicious's avatar
aspilicious committed
43
      'id' => 'user_name',
merlinofchaos's avatar
merlinofchaos committed
44 45
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
46
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
47 48 49 50
    ),
    'relationship' => array(
      'title' => t('Content authored'),
      'help' => t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'),
aspilicious's avatar
aspilicious committed
51
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
52 53 54 55 56 57 58
      'base' => 'node',
      'base field' => 'uid',
      'field' => 'uid',
      'label' => t('nodes'),
    ),
  );

59 60 61 62 63 64
  // uid_raw
  $data['users']['uid_raw'] = array(
    'help' => t('The raw numeric user ID.'),
    'real field' => 'uid',
    'filter' => array(
      'title' => t('The user ID'),
aspilicious's avatar
aspilicious committed
65
      'id' => 'numeric',
66 67 68
    ),
  );

merlinofchaos's avatar
merlinofchaos committed
69 70 71 72 73 74
  // uid
  $data['users']['uid_representative'] = array(
    'relationship' => array(
      'title' => t('Representative node'),
      'label'  => t('Representative node'),
      'help' => t('Obtains a single representative node for each user, according to a chosen sort criterion.'),
aspilicious's avatar
aspilicious committed
75
      'id' => 'groupwise_max',
merlinofchaos's avatar
merlinofchaos committed
76 77 78
      'relationship field' => 'uid',
      'outer field' => 'users.uid',
      'argument table' => 'users',
79 80 81 82
      'argument field' => 'uid',
      'base' => 'node',
      'field' => 'nid',
      'relationship' => 'node:uid'
merlinofchaos's avatar
merlinofchaos committed
83 84 85 86 87 88 89 90 91
    ),
  );

  // uid
  $data['users']['uid_current'] = array(
    'real field' => 'uid',
    'title' => t('Current'),
    'help' => t('Filter the view to the currently logged in user.'),
    'filter' => array(
aspilicious's avatar
aspilicious committed
92
      'id' => 'user_current',
merlinofchaos's avatar
merlinofchaos committed
93 94 95 96 97 98 99 100 101
      'type' => 'yes-no',
    ),
  );

  // name
  $data['users']['name'] = array(
    'title' => t('Name'), // The item it appears as on the UI,
    'help' => t('The user or author name.'), // The help that appears on the UI,
    'field' => array(
aspilicious's avatar
aspilicious committed
102
      'id' => 'user_name',
merlinofchaos's avatar
merlinofchaos committed
103 104 105
      'click sortable' => TRUE,
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
106
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
107 108
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
109
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
110 111
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
112
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
113 114 115 116 117 118 119 120 121 122 123
      'title' => t('Name (raw)'),
      'help' => t('The user or author name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete.')
    ),
  );

  // mail
  // Note that this field implements field level access control.
  $data['users']['mail'] = array(
    'title' => t('E-mail'), // The item it appears as on the UI,
    '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,
    'field' => array(
aspilicious's avatar
aspilicious committed
124
      'id' => 'user_mail',
merlinofchaos's avatar
merlinofchaos committed
125 126 127
      'click sortable' => TRUE,
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
128
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
129 130
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
131
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
132 133
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
134
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
135 136 137 138
    ),
  );

  // language
139
  $data['users']['langcode'] = array(
merlinofchaos's avatar
merlinofchaos committed
140 141 142
    'title' => t('Language'), // The item it appears as on the UI,
    'help' => t('Language of the user'),
    'field' => array(
aspilicious's avatar
aspilicious committed
143
      'id' => 'user_language',
merlinofchaos's avatar
merlinofchaos committed
144 145 146
      'click sortable' => TRUE,
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
147
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
148 149
    ),
    'filter' => array(
150
      'id' => 'language',
merlinofchaos's avatar
merlinofchaos committed
151 152
    ),
    'argument' => array(
153
      'id' => 'language',
merlinofchaos's avatar
merlinofchaos committed
154 155 156 157 158 159 160 161
    ),
  );

  // link
  $data['users']['view_user'] = array(
    'field' => array(
      'title' => t('Link'),
      'help' => t('Provide a simple link to the user.'),
aspilicious's avatar
aspilicious committed
162
      'id' => 'user_link',
merlinofchaos's avatar
merlinofchaos committed
163 164 165 166 167 168 169 170
    ),
  );

  // created field
  $data['users']['created'] = array(
    'title' => t('Created date'), // The item it appears as on the UI,
    'help' => t('The date the user was created.'), // The help that appears on the UI,
    'field' => array(
aspilicious's avatar
aspilicious committed
171
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
172 173 174
      'click sortable' => TRUE,
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
175
      'id' => 'date'
merlinofchaos's avatar
merlinofchaos committed
176 177
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
178
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
179 180 181 182 183 184 185 186
    ),
  );

  $data['users']['created_fulldate'] = array(
    'title' => t('Created date'),
    'help' => t('Date in the form of CCYYMMDD.'),
    'argument' => array(
      'field' => 'created',
aspilicious's avatar
aspilicious committed
187
      'id' => 'node_created_fulldate',
merlinofchaos's avatar
merlinofchaos committed
188 189 190 191 192 193 194 195
    ),
  );

  $data['users']['created_year_month'] = array(
    'title' => t('Created year + month'),
    'help' => t('Date in the form of YYYYMM.'),
    'argument' => array(
      'field' => 'created',
aspilicious's avatar
aspilicious committed
196
      'id' => 'node_created_year_month',
merlinofchaos's avatar
merlinofchaos committed
197 198 199 200 201 202 203 204
    ),
  );

  $data['users']['created_year'] = array(
    'title' => t('Created year'),
    'help' => t('Date in the form of YYYY.'),
    'argument' => array(
      'field' => 'created',
aspilicious's avatar
aspilicious committed
205
      'id' => 'node_created_year',
merlinofchaos's avatar
merlinofchaos committed
206 207 208 209 210 211 212 213
    ),
  );

  $data['users']['created_month'] = array(
    'title' => t('Created month'),
    'help' => t('Date in the form of MM (01 - 12).'),
    'argument' => array(
      'field' => 'created',
aspilicious's avatar
aspilicious committed
214
      'id' => 'node_created_month',
merlinofchaos's avatar
merlinofchaos committed
215 216 217 218 219 220 221 222
    ),
  );

  $data['users']['created_day'] = array(
    'title' => t('Created day'),
    'help' => t('Date in the form of DD (01 - 31).'),
    'argument' => array(
      'field' => 'created',
aspilicious's avatar
aspilicious committed
223
      'id' => 'node_created_day',
merlinofchaos's avatar
merlinofchaos committed
224 225 226 227 228 229 230 231
    ),
  );

  $data['users']['created_week'] = array(
    'title' => t('Created week'),
    'help' => t('Date in the form of WW (01 - 53).'),
    'argument' => array(
      'field' => 'created',
aspilicious's avatar
aspilicious committed
232
      'id' => 'node_created_week',
merlinofchaos's avatar
merlinofchaos committed
233 234 235 236 237 238 239 240
    ),
  );

  // access field
  $data['users']['access'] = array(
    'title' => t('Last access'), // The item it appears as on the UI,
    'help' => t("The user's last access date."), // The help that appears on the UI,
    'field' => array(
aspilicious's avatar
aspilicious committed
241
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
242 243 244
      'click sortable' => TRUE,
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
245
      'id' => 'date'
merlinofchaos's avatar
merlinofchaos committed
246 247
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
248
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
249 250 251 252 253 254 255 256
    ),
  );

  // login field
  $data['users']['login'] = array(
    'title' => t('Last login'), // The item it appears as on the UI,
    'help' => t("The user's last login date."), // The help that appears on the UI,
    'field' => array(
aspilicious's avatar
aspilicious committed
257
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
258 259 260
      'click sortable' => TRUE,
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
261
      'id' => 'date'
merlinofchaos's avatar
merlinofchaos committed
262 263
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
264
      'id' => 'date',
merlinofchaos's avatar
merlinofchaos committed
265 266 267 268 269 270 271 272 273
    ),
  );

  // active status
  $data['users']['status'] = array(
    'title' => t('Active'), // The item it appears as on the UI,
    'help' => t('Whether a user is active or blocked.'), // The help that appears on the UI,
     // Information for displaying a title as a field
    'field' => array(
aspilicious's avatar
aspilicious committed
274
      'id' => 'boolean',
merlinofchaos's avatar
merlinofchaos committed
275 276 277 278 279 280
      'click sortable' => TRUE,
      'output formats' => array(
        'active-blocked' => array(t('Active'), t('Blocked')),
      ),
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
281
      'id' => 'boolean',
merlinofchaos's avatar
merlinofchaos committed
282 283 284 285
      'label' => t('Active'),
      'type' => 'yes-no',
    ),
    'sort' => array(
aspilicious's avatar
aspilicious committed
286
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
287 288 289 290 291 292 293 294 295
    ),
  );

  // log field
  $data['users']['signature'] = array(
    'title' => t('Signature'), // The item it appears as on the UI,
    'help' => t("The user's signature."), // The help that appears on the UI,
     // Information for displaying a title as a field
    'field' => array(
aspilicious's avatar
aspilicious committed
296
      'id' => 'markup',
merlinofchaos's avatar
merlinofchaos committed
297 298 299
      'format' => filter_fallback_format(),
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
300
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
301 302 303 304 305 306 307
    ),
  );

  $data['users']['edit_node'] = array(
    'field' => array(
      'title' => t('Edit link'),
      'help' => t('Provide a simple link to edit the user.'),
aspilicious's avatar
aspilicious committed
308
      'id' => 'user_link_edit',
merlinofchaos's avatar
merlinofchaos committed
309 310 311 312 313 314 315
    ),
  );

  $data['users']['cancel_node'] = array(
    'field' => array(
      'title' => t('Cancel link'),
      'help' => t('Provide a simple link to cancel the user.'),
aspilicious's avatar
aspilicious committed
316
      'id' => 'user_link_cancel',
merlinofchaos's avatar
merlinofchaos committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
    ),
  );

  // users_roles table

  $data['users_roles']['table']['group']  = t('User');

  // Explain how this table joins to others.
  $data['users_roles']['table']['join'] = array(
     // Directly links to users table.
    'users' => array(
      'left_field' => 'uid',
      'field' => 'uid',
    ),
  );

  $data['users_roles']['rid'] = array(
    'title' => t('Roles'),
    'help' => t('Roles that a user belongs to.'),
    'field' => array(
aspilicious's avatar
aspilicious committed
337
      'id' => 'user_roles',
merlinofchaos's avatar
merlinofchaos committed
338 339 340
      'no group by' => TRUE,
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
341
      'id' => 'user_roles',
merlinofchaos's avatar
merlinofchaos committed
342 343 344
      'allow empty' => TRUE,
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
345
      'id' => 'users_roles_rid',
merlinofchaos's avatar
merlinofchaos committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
      'name table' => 'role',
      'name field' => 'name',
      'empty field name' => t('No role'),
      'zero is null' => TRUE,
      'numeric' => TRUE,
    ),
  );

  // role table

  $data['role']['table']['join'] = array(
     // Directly links to users table.
    'users' => array(
      'left_table' => 'users_roles',
      'left_field' => 'rid',
      'field' => 'rid',
    ),
    // needed for many to one helper sometimes
    'users_roles' => array(
      'left_field' => 'rid',
      'field' => 'rid',
    ),
  );

  // permission table
  $data['role_permission']['table']['group']  = t('User');
  $data['role_permission']['table']['join'] = array(
     // Directly links to users table.
    'users' => array(
      'left_table' => 'users_roles',
      'left_field' => 'rid',
      'field' => 'rid',
    ),
  );

  $data['role_permission']['permission'] = array(
    'title' => t('Permission'),
    'help' => t('The user permissions.'),
    'field' => array(
aspilicious's avatar
aspilicious committed
385
      'id' => 'user_permissions',
merlinofchaos's avatar
merlinofchaos committed
386 387 388
      'no group by' => TRUE,
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
389
      'id' => 'user_permissions',
merlinofchaos's avatar
merlinofchaos committed
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
    ),
  );

  // authmap table

  $data['authmap']['table']['group']  = t('User');
  $data['authmap']['table']['join'] = array(
     // Directly links to users table.
    'users' => array(
      'left_field' => 'uid',
      'field' => 'uid',
    ),
  );

  $data['authmap']['aid'] = array(
    'title' => t('Authmap ID'),
    'help' => t('The Authmap ID.'),
    'field' => array(
aspilicious's avatar
aspilicious committed
408
      'id' => 'numeric',
merlinofchaos's avatar
merlinofchaos committed
409 410
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
411
      'id' => 'numeric',
merlinofchaos's avatar
merlinofchaos committed
412 413 414
      'numeric' => TRUE,
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
415
      'id' => 'numeric',
merlinofchaos's avatar
merlinofchaos committed
416 417 418 419 420 421 422
      'numeric' => TRUE,
    ),
  );
  $data['authmap']['authname'] = array(
    'title' => t('Authentication name'),
    'help' => t('The unique authentication name.'),
    'field' => array(
aspilicious's avatar
aspilicious committed
423
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
424 425
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
426
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
427 428
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
429
      'id' => 'numeric',
merlinofchaos's avatar
merlinofchaos committed
430 431 432 433 434 435
    ),
  );
  $data['authmap']['module'] = array(
    'title' => t('Authentication module'),
    'help' => t('The name of the module managing the authentication entry.'),
    'field' => array(
aspilicious's avatar
aspilicious committed
436
      'id' => 'standard',
merlinofchaos's avatar
merlinofchaos committed
437 438
    ),
    'filter' => array(
aspilicious's avatar
aspilicious committed
439
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
440 441
    ),
    'argument' => array(
aspilicious's avatar
aspilicious committed
442
      'id' => 'string',
merlinofchaos's avatar
merlinofchaos committed
443 444 445 446 447 448 449 450 451 452 453 454 455
    ),
  );

  return $data;
}

/**
 * Allow replacement of current userid so we can cache these queries
 */
function user_views_query_substitutions($view) {
  global $user;
  return array('***CURRENT_USER***' => intval($user->uid));
}