profile.views.inc

  1. cis7 sites/all/modules/ulmus/views/modules/profile.views.inc
  2. cle7 sites/all/modules/ulmus/views/modules/profile.views.inc
  3. ecd7 sites/all/modules/ulmus/views/modules/profile.views.inc
  4. elmsmedia7 sites/all/modules/ulmus/views/modules/profile.views.inc
  5. harmony7 sites/all/modules/ulmus/views/modules/profile.views.inc
  6. icor7 sites/all/modules/ulmus/views/modules/profile.views.inc
  7. meedjum_blog7 sites/all/modules/ulmus/views/modules/profile.views.inc
  8. mooc7 sites/all/modules/ulmus/views/modules/profile.views.inc

Provide views data and handlers for user.module.

Functions

Namesort descending Description
profile_views_data Implements hook_views_data().
profile_views_fetch_field Add profile fields to view table
profile_views_get_fields Get all profile fields

File

sites/all/modules/ulmus/views/modules/profile.views.inc
View source
  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 profile_views_data() {
  12. $data['profile_values']['moved to'] = 'profile_value';
  13. // Define the base group of this table. Fields that don't
  14. // have a group defined will go into this field by default.
  15. $data['profile_value']['table']['group'] = t('Profile');
  16. $data['profile_value']['table']['join'] = array(
  17. 'node' => array(
  18. 'left_table' => 'profile_value',
  19. 'left_field' => 'uid',
  20. 'field' => 'uid',
  21. ),
  22. 'users' => array(
  23. 'left_table' => 'profile_value',
  24. 'left_field' => 'uid',
  25. 'field' => 'uid',
  26. ),
  27. );
  28. $fields = profile_views_get_fields();
  29. foreach ($fields as $field) {
  30. $table_name = 'profile_value_' . str_replace('-', '_', $field->name);
  31. $data[$table_name] = array(
  32. 'table' => array(
  33. 'group' => t('Profile'),
  34. 'join' => array(
  35. 'node' => array(
  36. 'table' => 'profile_value',
  37. 'left_table' => 'users',
  38. 'left_field' => 'uid',
  39. 'field' => 'uid',
  40. 'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
  41. ),
  42. 'users' => array(
  43. 'table' => 'profile_value',
  44. 'left_field' => 'uid',
  45. 'field' => 'uid',
  46. 'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
  47. ),
  48. ),
  49. ),
  50. );
  51. // All fields in the table are named 'value'.
  52. $data[$table_name]['value'] = profile_views_fetch_field($field);
  53. }
  54. return $data;
  55. }
  56. /**
  57. * Get all profile fields
  58. */
  59. function profile_views_get_fields() {
  60. static $fields = NULL;
  61. if (!isset($fields)) {
  62. $fields = array();
  63. $results = db_query("SELECT * FROM {profile_field} ORDER BY category, weight");
  64. foreach ($results as $row) {
  65. if (!empty($row->options)) {
  66. if (!in_array(substr($row->options, 0, 2), array('a:', 'b:', 'i:', 'f:', 'o:', 's:', ))) {
  67. // unserialized fields default version
  68. $options = $row->options;
  69. unset($row->options);
  70. $row->options = $options;
  71. }
  72. else {
  73. // serialized fields or modified version
  74. $row->options = unserialize($row->options);
  75. }
  76. }
  77. $fields[$row->fid] = $row;
  78. }
  79. }
  80. return $fields;
  81. }
  82. /**
  83. * Add profile fields to view table
  84. */
  85. function profile_views_fetch_field($field) {
  86. $data = array(
  87. 'title' => t('@category: @field-name', array('@category' => $field->category, '@field-name' => $field->title)),
  88. );
  89. // Add fields specific to the profile type.
  90. switch ($field->type) {
  91. case 'textfield':
  92. $data += array(
  93. 'help' => t('Profile textfield'),
  94. 'field' => array(
  95. 'handler' => 'views_handler_field_user',
  96. 'click sortable' => TRUE,
  97. ),
  98. 'sort' => array(
  99. 'handler' => 'views_handler_sort',
  100. ),
  101. 'filter' => array(
  102. 'handler' => 'views_handler_filter_string',
  103. ),
  104. 'argument' => array(
  105. 'handler' => 'views_handler_argument_string',
  106. ),
  107. );
  108. break;
  109. case 'textarea':
  110. $data += array(
  111. 'help' => t('Profile textarea'),
  112. 'field' => array(
  113. 'handler' => 'views_handler_field_markup',
  114. 'format' => filter_default_format(),
  115. ),
  116. 'sort' => array(
  117. 'handler' => 'views_handler_sort',
  118. ),
  119. 'filter' => array(
  120. 'handler' => 'views_handler_filter_string',
  121. ),
  122. );
  123. break;
  124. case 'checkbox':
  125. $data += array(
  126. 'help' => t('Profile checkbox'),
  127. 'field' => array(
  128. 'handler' => 'views_handler_field_boolean',
  129. 'click sortable' => TRUE,
  130. ),
  131. 'sort' => array(
  132. 'handler' => 'views_handler_sort',
  133. ),
  134. 'filter' => array(
  135. 'handler' => 'views_handler_filter_boolean_operator',
  136. 'accept null' => TRUE,
  137. ),
  138. // @todo there ought to be a boolean argument handler
  139. );
  140. break;
  141. case 'url':
  142. $data += array(
  143. 'help' => t('Profile URL'),
  144. 'field' => array(
  145. 'handler' => 'views_handler_field_url',
  146. 'click sortable' => TRUE,
  147. ),
  148. 'sort' => array(
  149. 'handler' => 'views_handler_sort',
  150. ),
  151. 'filter' => array(
  152. 'handler' => 'views_handler_filter_string',
  153. ),
  154. );
  155. break;
  156. case 'selection':
  157. $data += array(
  158. 'help' => t('Profile selection'),
  159. 'field' => array(
  160. 'handler' => 'views_handler_field',
  161. 'click sortable' => TRUE,
  162. ),
  163. 'sort' => array(
  164. 'handler' => 'views_handler_sort',
  165. ),
  166. 'filter' => array(
  167. 'handler' => 'views_handler_filter_profile_selection',
  168. 'fid' => $field->fid,
  169. ),
  170. 'argument' => array(
  171. 'handler' => 'views_handler_argument_string',
  172. ),
  173. );
  174. break;
  175. case 'list':
  176. $data += array(
  177. 'help' => t('Profile freeform list %field-name.', array('%field-name' => $field->title)),
  178. 'field' => array(
  179. 'handler' => 'views_handler_field_profile_list',
  180. 'no group by' => TRUE,
  181. ),
  182. 'filter' => array(
  183. 'handler' => 'views_handler_filter_string',
  184. ),
  185. );
  186. break;
  187. case 'date':
  188. $data += array(
  189. 'help' => t('Profile date %field-name.', array('%field-name' => $field->title)),
  190. 'field' => array(
  191. 'handler' => 'views_handler_field_profile_date',
  192. ),
  193. );
  194. break;
  195. }
  196. // @todo: add access control to hidden fields.
  197. return $data;
  198. }

Related topics