/[drupal]/contributions/modules/views/modules/profile.views.inc
ViewVC logotype

Contents of /contributions/modules/views/modules/profile.views.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Tue Sep 15 17:22:42 2009 UTC (2 months, 1 week ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.9: +2 -2 lines
File MIME type: text/x-php
#337741 by joachim: Allow profile fields to have "link to user" option.
1 <?php
2 //$Id: profile.views.inc,v 1.9 2008/09/24 21:21:21 merlinofchaos Exp $
3 /**
4 * @file
5 * Provide views data and handlers for user.module
6 */
7
8 /**
9 * @defgroup views_profile_module profile.module handlers
10 *
11 * @{
12 */
13
14 /**
15 * Implementation of hook_views_data()
16 */
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');
21
22 $data['profile_values']['table']['join'] = array(
23 'node' => array(
24 'left_table' => 'profile_values',
25 'left_field' => 'uid',
26 'field' => 'uid',
27 ),
28 'users' => array(
29 'left_table' => 'profile_values',
30 'left_field' => 'uid',
31 'field' => 'uid',
32 ),
33 );
34
35 $fields = profile_views_get_fields();
36 foreach($fields as $field) {
37 $table_name = 'profile_values_' . $field->name;
38 $data[$table_name] = array(
39 'table' => array(
40 'group' => t('Profile'),
41 'join' => array(
42 'node' => array(
43 'table' => 'profile_values',
44 'left_table' => 'users',
45 'left_field' => 'uid',
46 'field' => 'uid',
47 'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
48 ),
49 'users' => array(
50 'table' => 'profile_values',
51 'left_field' => 'uid',
52 'field' => 'uid',
53 'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
54 ),
55 ),
56 ),
57 );
58 // All fields in the table are named 'value'.
59 $data[$table_name]['value'] = profile_views_fetch_field($field);
60 }
61
62 return $data;
63 }
64
65 /**
66 * Get all profile fields
67 */
68 function profile_views_get_fields() {
69 static $fields = NULL;
70
71 if (!isset($fields)) {
72 $fields = array();
73 $results = db_query("SELECT * FROM {profile_fields} ORDER BY category, weight");
74
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;
80 unset($row->options);
81 $row->options = $options;
82 }
83 else {
84 // serialized fields or modified version
85 $row->options = unserialize(db_decode_blob($row->options));
86 }
87 }
88 $fields[$row->fid] = $row;
89 }
90 }
91 return $fields;
92 }
93
94
95 /**
96 * Add profile fields to view table
97 */
98 function profile_views_fetch_field($field) {
99 $data = array(
100 'title' => t('@field-name', array('@field-name' => $field->title)),
101 );
102
103 // Add fields specific to the profile type.
104 switch ($field->type) {
105 case 'textfield':
106 $data += array(
107 'help' => t('Profile textfield'),
108 'field' => array(
109 'handler' => 'views_handler_field_user',
110 'click sortable' => TRUE,
111 ),
112 'sort' => array(
113 'handler' => 'views_handler_sort',
114 ),
115 'filter' => array(
116 'handler' => 'views_handler_filter_string',
117 ),
118 'argument' => array(
119 'handler' => 'views_handler_argument_string',
120 ),
121 );
122
123 break;
124 case 'textarea':
125 $data += array(
126 'help' => t('Profile textarea'),
127 'field' => array(
128 'handler' => 'views_handler_field_markup',
129 'format' => FILTER_FORMAT_DEFAULT,
130 ),
131 'sort' => array(
132 'handler' => 'views_handler_sort',
133 ),
134 'filter' => array(
135 'handler' => 'views_handler_filter_string',
136 ),
137 );
138
139 break;
140 case 'checkbox':
141 $data += array(
142 'help' => t('Profile checkbox'),
143 'field' => array(
144 'handler' => 'views_handler_field_boolean',
145 'click sortable' => TRUE,
146 ),
147 'sort' => array(
148 'handler' => 'views_handler_sort',
149 ),
150 'filter' => array(
151 'handler' => 'views_handler_filter_boolean_operator',
152 ),
153 // @todo there ought to be a boolean argument handler
154 );
155
156 break;
157 case 'url':
158 $data += array(
159 'help' => t('Profile URL'),
160 'field' => array(
161 'handler' => 'views_handler_field_url',
162 'click sortable' => TRUE,
163 ),
164 'sort' => array(
165 'handler' => 'views_handler_sort',
166 ),
167 'filter' => array(
168 'handler' => 'views_handler_filter_string',
169 ),
170 );
171
172 break;
173 case 'selection':
174 $data += array(
175 'help' => t('Profile selection'),
176 'field' => array(
177 'handler' => 'views_handler_field',
178 'click sortable' => TRUE,
179 ),
180 'sort' => array(
181 'handler' => 'views_handler_sort',
182 ),
183 'filter' => array(
184 'handler' => 'views_handler_filter_profile_selection',
185 'fid' => $field->fid,
186 ),
187 'argument' => array(
188 'handler' => 'views_handler_argument_string',
189 ),
190 );
191
192 break;
193 case 'list':
194 $data += array(
195 'help' => t('Profile freeform list %field-name.', array('%field-name' => $field->title)),
196 'field' => array(
197 'handler' => 'views_handler_field_profile_list',
198 ),
199 'filter' => array(
200 'handler' => 'views_handler_filter_string',
201 ),
202 );
203
204 break;
205 case 'date':
206 $data += array(
207 'help' => t('Profile date %field-name.', array('%field-name' => $field->title)),
208 'field' => array(
209 'handler' => 'views_handler_field_profile_date',
210 ),
211 );
212
213 break;
214 }
215
216 // @todo: add access control to hidden fields.
217 return $data;
218 }
219
220 /**
221 * Implementation of hook_views_handlers() to register all of the basic handlers
222 * views uses.
223 */
224 function profile_views_handlers() {
225 return array(
226 'info' => array(
227 'path' => drupal_get_path('module', 'views') . '/modules/profile',
228 ),
229 'handlers' => array(
230 'views_handler_field_profile_date' => array(
231 'parent' => 'views_handler_field_date',
232 ),
233 'views_handler_field_profile_list' => array(
234 'parent' => 'views_handler_field_prerender_list',
235 ),
236 'views_handler_filter_profile_selection' => array(
237 'parent' => 'views_handler_filter_in_operator',
238 ),
239 ),
240 );
241 }
242
243 /**
244 * @}
245 */

  ViewVC Help
Powered by ViewVC 1.1.2