user.views.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <?php
  2. /**
  3. * @file
  4. * Provide views data and handlers for user.module.
  5. *
  6. * @ingroup views_module_handlers
  7. */
  8. /**
  9. * Implements hook_views_data().
  10. */
  11. function user_views_data() {
  12. // ----------------------------------------------------------------
  13. // users table
  14. // Define the base group of this table. Fields that don't
  15. // have a group defined will go into this field by default.
  16. $data['users']['table']['group'] = t('User');
  17. $data['users']['table']['base'] = array(
  18. 'field' => 'uid',
  19. 'title' => t('User'),
  20. 'help' => t('Users who have created accounts on your site.'),
  21. 'access query tag' => 'user_access',
  22. );
  23. $data['users']['table']['entity type'] = 'user';
  24. $data['users']['table']['default_relationship'] = array(
  25. 'node' => array(
  26. 'table' => 'node',
  27. 'field' => 'uid',
  28. ),
  29. 'node_revision' => array(
  30. 'table' => 'node_revision',
  31. 'field' => 'uid',
  32. ),
  33. 'file' => array(
  34. 'table' => 'file',
  35. 'field' => 'uid',
  36. ),
  37. );
  38. // uid
  39. $data['users']['uid'] = array(
  40. 'title' => t('Uid'),
  41. 'help' => t('The user ID'), // The help that appears on the UI,
  42. 'field' => array(
  43. 'handler' => 'views_handler_field_user',
  44. 'click sortable' => TRUE,
  45. ),
  46. 'argument' => array(
  47. 'handler' => 'views_handler_argument_user_uid',
  48. 'name field' => 'name', // display this field in the summary
  49. ),
  50. 'filter' => array(
  51. 'title' => t('Name'),
  52. 'handler' => 'views_handler_filter_user_name',
  53. ),
  54. 'sort' => array(
  55. 'handler' => 'views_handler_sort',
  56. ),
  57. 'relationship' => array(
  58. 'title' => t('Content authored'),
  59. 'help' => t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'),
  60. 'handler' => 'views_handler_relationship',
  61. 'base' => 'node',
  62. 'base field' => 'uid',
  63. 'field' => 'uid',
  64. 'label' => t('nodes'),
  65. ),
  66. );
  67. // uid_raw
  68. $data['users']['uid_raw'] = array(
  69. 'help' => t('The raw numeric user ID.'),
  70. 'real field' => 'uid',
  71. 'filter' => array(
  72. 'title' => t('The user ID'),
  73. 'handler' => 'views_handler_filter_numeric',
  74. ),
  75. );
  76. // uid
  77. $data['users']['uid_representative'] = array(
  78. 'relationship' => array(
  79. 'title' => t('Representative node'),
  80. 'label' => t('Representative node'),
  81. 'help' => t('Obtains a single representative node for each user, according to a chosen sort criterion.'),
  82. 'handler' => 'views_handler_relationship_groupwise_max',
  83. 'relationship field' => 'uid',
  84. 'outer field' => 'users.uid',
  85. 'argument table' => 'users',
  86. 'argument field' => 'uid',
  87. 'base' => 'node',
  88. 'field' => 'nid',
  89. ),
  90. );
  91. // uid
  92. $data['users']['uid_current'] = array(
  93. 'real field' => 'uid',
  94. 'title' => t('Current'),
  95. 'help' => t('Filter the view to the currently logged in user.'),
  96. 'filter' => array(
  97. 'handler' => 'views_handler_filter_user_current',
  98. 'type' => 'yes-no',
  99. ),
  100. );
  101. // name
  102. $data['users']['name'] = array(
  103. 'title' => t('Name'), // The item it appears as on the UI,
  104. 'help' => t('The user or author name.'), // The help that appears on the UI,
  105. 'field' => array(
  106. 'handler' => 'views_handler_field_user_name',
  107. 'click sortable' => TRUE,
  108. ),
  109. 'sort' => array(
  110. 'handler' => 'views_handler_sort',
  111. ),
  112. 'argument' => array(
  113. 'handler' => 'views_handler_argument_string',
  114. ),
  115. 'filter' => array(
  116. 'handler' => 'views_handler_filter_string',
  117. 'title' => t('Name (raw)'),
  118. 'help' => t('The user or author name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete.')
  119. ),
  120. );
  121. // mail
  122. // Note that this field implements field level access control.
  123. $data['users']['mail'] = array(
  124. 'title' => t('E-mail'), // The item it appears as on the UI,
  125. '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,
  126. 'field' => array(
  127. 'handler' => 'views_handler_field_user_mail',
  128. 'click sortable' => TRUE,
  129. ),
  130. 'sort' => array(
  131. 'handler' => 'views_handler_sort',
  132. ),
  133. 'filter' => array(
  134. 'handler' => 'views_handler_filter_string',
  135. ),
  136. 'argument' => array(
  137. 'handler' => 'views_handler_argument_string',
  138. ),
  139. );
  140. // language
  141. $data['users']['language'] = array(
  142. 'title' => t('Language'), // The item it appears as on the UI,
  143. 'help' => t('Language of the user'),
  144. 'field' => array(
  145. 'handler' => 'views_handler_field_user_language',
  146. 'click sortable' => TRUE,
  147. ),
  148. 'sort' => array(
  149. 'handler' => 'views_handler_sort',
  150. ),
  151. 'filter' => array(
  152. 'handler' => 'views_handler_filter_node_language',
  153. ),
  154. 'argument' => array(
  155. 'handler' => 'views_handler_argument_node_language',
  156. ),
  157. );
  158. // picture
  159. $data['users']['picture_fid']['moved to'] = array('users', 'picture');
  160. $data['users']['picture'] = array(
  161. 'title' => t('Picture'),
  162. 'help' => t("The user's picture, if allowed."), // The help that appears on the UI,
  163. // Information for displaying the uid
  164. 'field' => array(
  165. 'handler' => 'views_handler_field_user_picture',
  166. 'click sortable' => TRUE,
  167. ),
  168. 'sort' => array(
  169. 'handler' => 'views_handler_sort',
  170. ),
  171. 'filter' => array(
  172. 'handler' => 'views_handler_filter_boolean_operator',
  173. 'label' => t('Has Avatar'),
  174. 'type' => 'yes-no',
  175. ),
  176. );
  177. // link
  178. $data['users']['view_user'] = array(
  179. 'field' => array(
  180. 'title' => t('Link'),
  181. 'help' => t('Provide a simple link to the user.'),
  182. 'handler' => 'views_handler_field_user_link',
  183. ),
  184. );
  185. // created field
  186. $data['users']['created'] = array(
  187. 'title' => t('Created date'), // The item it appears as on the UI,
  188. 'help' => t('The date the user was created.'), // The help that appears on the UI,
  189. 'field' => array(
  190. 'handler' => 'views_handler_field_date',
  191. 'click sortable' => TRUE,
  192. ),
  193. 'sort' => array(
  194. 'handler' => 'views_handler_sort_date',
  195. ),
  196. 'filter' => array(
  197. 'handler' => 'views_handler_filter_date',
  198. ),
  199. );
  200. $data['users']['created_fulldate'] = array(
  201. 'title' => t('Created date'),
  202. 'help' => t('Date in the form of CCYYMMDD.'),
  203. 'argument' => array(
  204. 'field' => 'created',
  205. 'handler' => 'views_handler_argument_node_created_fulldate',
  206. ),
  207. );
  208. $data['users']['created_year_month'] = array(
  209. 'title' => t('Created year + month'),
  210. 'help' => t('Date in the form of YYYYMM.'),
  211. 'argument' => array(
  212. 'field' => 'created',
  213. 'handler' => 'views_handler_argument_node_created_year_month',
  214. ),
  215. );
  216. $data['users']['timestamp_year']['moved to'] = array('users', 'created_year');
  217. $data['users']['created_year'] = array(
  218. 'title' => t('Created year'),
  219. 'help' => t('Date in the form of YYYY.'),
  220. 'argument' => array(
  221. 'field' => 'created',
  222. 'handler' => 'views_handler_argument_node_created_year',
  223. ),
  224. );
  225. $data['users']['created_month'] = array(
  226. 'title' => t('Created month'),
  227. 'help' => t('Date in the form of MM (01 - 12).'),
  228. 'argument' => array(
  229. 'field' => 'created',
  230. 'handler' => 'views_handler_argument_node_created_month',
  231. ),
  232. );
  233. $data['users']['created_day'] = array(
  234. 'title' => t('Created day'),
  235. 'help' => t('Date in the form of DD (01 - 31).'),
  236. 'argument' => array(
  237. 'field' => 'created',
  238. 'handler' => 'views_handler_argument_node_created_day',
  239. ),
  240. );
  241. $data['users']['created_week'] = array(
  242. 'title' => t('Created week'),
  243. 'help' => t('Date in the form of WW (01 - 53).'),
  244. 'argument' => array(
  245. 'field' => 'created',
  246. 'handler' => 'views_handler_argument_node_created_week',
  247. ),
  248. );
  249. // access field
  250. $data['users']['access'] = array(
  251. 'title' => t('Last access'), // The item it appears as on the UI,
  252. 'help' => t("The user's last access date."), // The help that appears on the UI,
  253. 'field' => array(
  254. 'handler' => 'views_handler_field_date',
  255. 'click sortable' => TRUE,
  256. ),
  257. 'sort' => array(
  258. 'handler' => 'views_handler_sort_date',
  259. ),
  260. 'filter' => array(
  261. 'handler' => 'views_handler_filter_date',
  262. ),
  263. );
  264. // login field
  265. $data['users']['login'] = array(
  266. 'title' => t('Last login'), // The item it appears as on the UI,
  267. 'help' => t("The user's last login date."), // The help that appears on the UI,
  268. 'field' => array(
  269. 'handler' => 'views_handler_field_date',
  270. 'click sortable' => TRUE,
  271. ),
  272. 'sort' => array(
  273. 'handler' => 'views_handler_sort_date',
  274. ),
  275. 'filter' => array(
  276. 'handler' => 'views_handler_filter_date',
  277. ),
  278. );
  279. // active status
  280. $data['users']['status'] = array(
  281. 'title' => t('Active'), // The item it appears as on the UI,
  282. 'help' => t('Whether a user is active or blocked.'), // The help that appears on the UI,
  283. // Information for displaying a title as a field
  284. 'field' => array(
  285. 'handler' => 'views_handler_field_boolean',
  286. 'click sortable' => TRUE,
  287. 'output formats' => array(
  288. 'active-blocked' => array(t('Active'), t('Blocked')),
  289. ),
  290. ),
  291. 'filter' => array(
  292. 'handler' => 'views_handler_filter_boolean_operator',
  293. 'label' => t('Active'),
  294. 'type' => 'yes-no',
  295. ),
  296. 'sort' => array(
  297. 'handler' => 'views_handler_sort',
  298. ),
  299. );
  300. // log field
  301. $data['users']['signature'] = array(
  302. 'title' => t('Signature'), // The item it appears as on the UI,
  303. 'help' => t("The user's signature."), // The help that appears on the UI,
  304. // Information for displaying a title as a field
  305. 'field' => array(
  306. 'handler' => 'views_handler_field_markup',
  307. 'format' => filter_fallback_format(),
  308. ),
  309. 'filter' => array(
  310. 'handler' => 'views_handler_filter_string',
  311. ),
  312. );
  313. $data['users']['edit_node'] = array(
  314. 'field' => array(
  315. 'title' => t('Edit link'),
  316. 'help' => t('Provide a simple link to edit the user.'),
  317. 'handler' => 'views_handler_field_user_link_edit',
  318. ),
  319. );
  320. $data['users']['cancel_node'] = array(
  321. 'field' => array(
  322. 'title' => t('Cancel link'),
  323. 'help' => t('Provide a simple link to cancel the user.'),
  324. 'handler' => 'views_handler_field_user_link_cancel',
  325. ),
  326. );
  327. $data['users']['data'] = array(
  328. 'title' => t('Data'),
  329. 'help' => t('Provide serialized data of the user'),
  330. 'field' => array(
  331. 'handler' => 'views_handler_field_serialized',
  332. ),
  333. );
  334. // ----------------------------------------------------------------------
  335. // users_roles table
  336. $data['users_roles']['table']['group'] = t('User');
  337. // Explain how this table joins to others.
  338. $data['users_roles']['table']['join'] = array(
  339. // Directly links to users table.
  340. 'users' => array(
  341. 'left_field' => 'uid',
  342. 'field' => 'uid',
  343. ),
  344. );
  345. $data['users_roles']['table']['default_relationship'] = array(
  346. 'node' => array(
  347. 'table' => 'node',
  348. 'field' => 'uid',
  349. ),
  350. 'node_revision' => array(
  351. 'table' => 'node_revision',
  352. 'field' => 'uid',
  353. ),
  354. );
  355. $data['users_roles']['rid'] = array(
  356. 'title' => t('Roles'),
  357. 'help' => t('Roles that a user belongs to.'),
  358. 'field' => array(
  359. 'handler' => 'views_handler_field_user_roles',
  360. 'no group by' => TRUE,
  361. ),
  362. 'filter' => array(
  363. 'handler' => 'views_handler_filter_user_roles',
  364. 'numeric' => TRUE,
  365. 'allow empty' => TRUE,
  366. ),
  367. 'argument' => array(
  368. 'handler' => 'views_handler_argument_users_roles_rid',
  369. 'name table' => 'role',
  370. 'name field' => 'name',
  371. 'empty field name' => t('No role'),
  372. 'zero is null' => TRUE,
  373. 'numeric' => TRUE,
  374. ),
  375. );
  376. // ----------------------------------------------------------------------
  377. // role table
  378. $data['role']['table']['join'] = array(
  379. // Directly links to users table.
  380. 'users' => array(
  381. 'left_table' => 'users_roles',
  382. 'left_field' => 'rid',
  383. 'field' => 'rid',
  384. ),
  385. // needed for many to one helper sometimes
  386. 'users_roles' => array(
  387. 'left_field' => 'rid',
  388. 'field' => 'rid',
  389. ),
  390. );
  391. $data['role']['table']['default_relationship'] = array(
  392. 'node' => array(
  393. 'table' => 'node',
  394. 'field' => 'uid',
  395. ),
  396. 'node_revision' => array(
  397. 'table' => 'node_revision',
  398. 'field' => 'uid',
  399. ),
  400. );
  401. // permission table
  402. $data['role_permission']['table']['group'] = t('User');
  403. $data['role_permission']['table']['join'] = array(
  404. // Directly links to users table.
  405. 'users' => array(
  406. 'left_table' => 'users_roles',
  407. 'left_field' => 'rid',
  408. 'field' => 'rid',
  409. ),
  410. );
  411. $data['role_permission']['permission'] = array(
  412. 'title' => t('Permission'),
  413. 'help' => t('The user permissions.'),
  414. 'field' => array(
  415. 'handler' => 'views_handler_field_user_permissions',
  416. 'no group by' => TRUE,
  417. ),
  418. 'filter' => array(
  419. 'handler' => 'views_handler_filter_user_permissions',
  420. ),
  421. );
  422. // ----------------------------------------------------------------------
  423. // authmap table
  424. $data['authmap']['table']['group'] = t('User');
  425. $data['authmap']['table']['join'] = array(
  426. // Directly links to users table.
  427. 'users' => array(
  428. 'left_field' => 'uid',
  429. 'field' => 'uid',
  430. ),
  431. );
  432. $data['authmap']['table']['default_relationship'] = array(
  433. 'node' => array(
  434. 'table' => 'node',
  435. 'field' => 'uid',
  436. ),
  437. 'node_revision' => array(
  438. 'table' => 'node_revision',
  439. 'field' => 'uid',
  440. ),
  441. );
  442. $data['authmap']['aid'] = array(
  443. 'title' => t('Authmap ID'),
  444. 'help' => t('The Authmap ID.'),
  445. 'field' => array(
  446. 'handler' => 'views_handler_field_numeric',
  447. ),
  448. 'filter' => array(
  449. 'handler' => 'views_handler_filter_numeric',
  450. 'numeric' => TRUE,
  451. ),
  452. 'argument' => array(
  453. 'handler' => 'views_handler_argument_numeric',
  454. 'numeric' => TRUE,
  455. ),
  456. );
  457. $data['authmap']['authname'] = array(
  458. 'title' => t('Authentication name'),
  459. 'help' => t('The unique authentication name.'),
  460. 'field' => array(
  461. 'handler' => 'views_handler_field',
  462. ),
  463. 'filter' => array(
  464. 'handler' => 'views_handler_filter_string',
  465. ),
  466. 'argument' => array(
  467. 'handler' => 'views_handler_argument_string',
  468. ),
  469. );
  470. $data['authmap']['module'] = array(
  471. 'title' => t('Authentication module'),
  472. 'help' => t('The name of the module managing the authentication entry.'),
  473. 'field' => array(
  474. 'handler' => 'views_handler_field',
  475. ),
  476. 'filter' => array(
  477. 'handler' => 'views_handler_filter_string',
  478. ),
  479. 'argument' => array(
  480. 'handler' => 'views_handler_argument_string',
  481. ),
  482. );
  483. return $data;
  484. }
  485. /**
  486. * Implements hook_views_plugins().
  487. */
  488. function user_views_plugins() {
  489. return array(
  490. 'module' => 'views', // This just tells our themes are elsewhere.
  491. 'row' => array(
  492. 'user' => array(
  493. 'title' => t('User'),
  494. 'help' => t('Display the user with standard user view.'),
  495. 'handler' => 'views_plugin_row_user_view',
  496. 'base' => array('users'), // only works with 'users' as base.
  497. 'uses options' => TRUE,
  498. 'type' => 'normal',
  499. 'help topic' => 'style-users',
  500. ),
  501. ),
  502. 'argument default' => array(
  503. 'user' => array(
  504. 'title' => t('User ID from URL'),
  505. 'handler' => 'views_plugin_argument_default_user',
  506. 'path' => drupal_get_path('module', 'views') . '/modules/user', // not necessary for most modules
  507. ),
  508. 'current_user' => array(
  509. 'title' => t('User ID from logged in user'),
  510. 'handler' => 'views_plugin_argument_default_current_user',
  511. 'path' => drupal_get_path('module', 'views') . '/modules/user', // not necessary for most modules
  512. ),
  513. ),
  514. 'argument validator' => array(
  515. 'user' => array(
  516. 'title' => t('User'),
  517. 'handler' => 'views_plugin_argument_validate_user',
  518. 'path' => drupal_get_path('module', 'views') . '/modules/user', // not necessary for most modules
  519. ),
  520. ),
  521. );
  522. }
  523. /**
  524. * Allow replacement of current userid so we can cache these queries
  525. */
  526. function user_views_query_substitutions($view) {
  527. global $user;
  528. return array('***CURRENT_USER***' => intval($user->uid));
  529. }