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