2 //$Id: profile.views.inc,v 1.9 2008/09/24 21:21:21 merlinofchaos Exp $
5 * Provide views data and handlers for user.module
9 * @defgroup views_profile_module profile.module handlers
15 * Implementation of hook_views_data()
17 function profile_views_data() {
18 // Define the base group of this table. Fields that don't
19 // have a group defined will go into this field by default.
20 $data['profile_values']['table']['group'] = t('Profile');
22 $data['profile_values']['table']['join'] = array(
24 'left_table' => 'profile_values',
25 'left_field' => 'uid',
29 'left_table' => 'profile_values',
30 'left_field' => 'uid',
35 $fields = profile_views_get_fields();
36 foreach($fields as $field) {
37 $table_name = 'profile_values_' . $field->name;
38 $data[$table_name] = array(
40 'group' => t('Profile'),
43 'table' => 'profile_values',
44 'left_table' => 'users',
45 'left_field' => 'uid',
47 'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
50 'table' => 'profile_values',
51 'left_field' => 'uid',
53 'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
58 // All fields in the table are named 'value'.
59 $data[$table_name]['value'] = profile_views_fetch_field($field);
66 * Get all profile fields
68 function profile_views_get_fields() {
69 static $fields = NULL;
71 if (!isset($fields)) {
73 $results = db_query("SELECT * FROM {profile_fields} ORDER BY category, weight");
75 while ($row = db_fetch_object($results)) {
76 if (!empty($row->options)) {
77 if (!in_array(substr($row->options, 0, 2), array('a:', 'b:', 'i:', 'f:', 'o:', 's:', ))) {
78 // unserialized fields default version
79 $options = $row->options;
81 $row->options = $options;
84 // serialized fields or modified version
85 $row->options = unserialize(db_decode_blob($row->options));
88 $fields[$row->fid] = $row;
96 * Add profile fields to view table
98 function profile_views_fetch_field($field) {
100 'title' => t('@field-name', array('@field-name' => $field->title)),
103 // Add fields specific to the profile type.
104 switch ($field->type) {
107 'help' => t('Profile textfield'),
109 'handler' => 'views_handler_field',
110 'click sortable' => TRUE,
113 'handler' => 'views_handler_sort',
116 'handler' => 'views_handler_filter_string',
119 'handler' => 'views_handler_argument_string',
126 'help' => t('Profile textarea'),
128 'handler' => 'views_handler_field_markup',
129 'format' => FILTER_FORMAT_DEFAULT,
132 'handler' => 'views_handler_sort',
135 'handler' => 'views_handler_filter_string',
142 'help' => t('Profile checkbox'),
144 'handler' => 'views_handler_field_boolean',
145 'click sortable' => TRUE,
148 'handler' => 'views_handler_sort',
151 'handler' => 'views_handler_filter_boolean_operator',
153 // @todo there ought to be a boolean argument handler
159 'help' => t('Profile URL'),
161 'handler' => 'views_handler_field_url',
162 'click sortable' => TRUE,
165 'handler' => 'views_handler_sort',
168 'handler' => 'views_handler_filter_string',
175 'help' => t('Profile selection'),
177 'handler' => 'views_handler_field',
178 'click sortable' => TRUE,
181 'handler' => 'views_handler_sort',
184 'handler' => 'views_handler_filter_profile_selection',
185 'fid' => $field->fid,
188 'handler' => 'views_handler_argument_string',
195 'help' => t('Profile freeform list %field-name.', array('%field-name' => $field->title)),
197 'handler' => 'views_handler_field_profile_list',
200 'handler' => 'views_handler_filter_string',
207 'help' => t('Profile date %field-name.', array('%field-name' => $field->title)),
209 'handler' => 'views_handler_field_profile_date',
216 // @todo: add access control to hidden fields.
221 * Implementation of hook_views_handlers() to register all of the basic handlers
224 function profile_views_handlers() {
227 'path' => drupal_get_path('module', 'views') . '/modules/profile',
230 'views_handler_field_profile_date' => array(
231 'parent' => 'views_handler_field_date',
233 'views_handler_field_profile_list' => array(
234 'parent' => 'views_handler_field_prerender_list',
236 'views_handler_filter_profile_selection' => array(
237 'parent' => 'views_handler_filter_in_operator',