1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Provides support for the Views module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_views_plugins().
|
10 |
|
|
*/
|
11 |
|
|
function flag_views_plugins() {
|
12 |
|
|
return array(
|
13 |
|
|
'argument validator' => array(
|
14 |
|
|
'flag_flaggable_node' => array(
|
15 |
|
|
'title' => t('Flaggable node'),
|
16 |
|
|
'flag type' => 'node',
|
17 |
|
|
'handler' => 'flag_plugin_argument_validate_flaggability',
|
18 |
|
|
'path' => drupal_get_path('module', 'flag') . '/includes',
|
19 |
|
|
),
|
20 |
|
|
'flag_flaggable_user' => array(
|
21 |
|
|
'title' => t('Flaggable user'),
|
22 |
|
|
'flag type' => 'user',
|
23 |
|
|
'handler' => 'flag_plugin_argument_validate_flaggability',
|
24 |
|
|
'path' => drupal_get_path('module', 'flag') . '/includes',
|
25 |
|
|
),
|
26 |
|
|
// A comment validator won't be very useful. Moreover, having it will
|
27 |
|
|
// contribute to the argument object's $options polution, so let's skip
|
28 |
|
|
// it.
|
29 |
|
|
),
|
30 |
|
|
);
|
31 |
|
|
}
|
32 |
|
|
/**
|
33 |
|
|
* Implements hook_views_data().
|
34 |
|
|
*/
|
35 |
|
|
function flag_views_data() {
|
36 |
|
|
$data = array();
|
37 |
|
|
|
38 |
|
|
$data['flagging']['table']['group'] = t('Flags');
|
39 |
|
|
$data['flag_counts']['table']['group'] = t('Flags');
|
40 |
|
|
|
41 |
|
|
// Notify views from flag 2.x of our changes to views data.
|
42 |
|
|
// @see flag_update_7301().
|
43 |
|
|
$data['flag_content']['moved to'] = 'flagging';
|
44 |
|
|
// @see flag_update_7303().
|
45 |
|
|
$data['flag_content']['content_id']['moved to'] = array('flagging', 'entity_id');
|
46 |
|
|
|
47 |
|
|
$data['flagging']['uid'] = array(
|
48 |
|
|
'title' => t('User uid'),
|
49 |
|
|
'help' => t('The user that flagged an item. If you need more fields than the uid add the "Flags: User" relationship.'),
|
50 |
|
|
'relationship' => array(
|
51 |
|
|
'base' => 'users',
|
52 |
|
|
'title' => t('User'),
|
53 |
|
|
'help' => t('Relate an item to the user that flagged it.'),
|
54 |
|
|
'handler' => 'views_handler_relationship',
|
55 |
|
|
'label' => t('Flag user'),
|
56 |
|
|
),
|
57 |
|
|
'filter' => array(
|
58 |
|
|
'handler' => 'views_handler_filter_user_name',
|
59 |
|
|
),
|
60 |
|
|
'argument' => array(
|
61 |
|
|
'handler' => 'views_handler_argument_numeric',
|
62 |
|
|
),
|
63 |
|
|
'field' => array(
|
64 |
|
|
'handler' => 'views_handler_field_user',
|
65 |
|
|
),
|
66 |
|
|
);
|
67 |
|
|
|
68 |
|
|
$data['flagging']['timestamp'] = array(
|
69 |
|
|
'title' => t('Flagged time'),
|
70 |
|
|
'help' => t('Display the time the content was flagged by a user.'),
|
71 |
|
|
'field' => array(
|
72 |
|
|
'handler' => 'views_handler_field_date',
|
73 |
|
|
'click sortable' => TRUE,
|
74 |
|
|
),
|
75 |
|
|
'sort' => array(
|
76 |
|
|
'handler' => 'views_handler_sort_date',
|
77 |
|
|
),
|
78 |
|
|
'filter' => array(
|
79 |
|
|
'handler' => 'views_handler_filter_date',
|
80 |
|
|
),
|
81 |
|
|
'argument' => array(
|
82 |
|
|
'handler' => 'views_handler_argument_date',
|
83 |
|
|
),
|
84 |
|
|
);
|
85 |
|
|
|
86 |
|
|
// Argument for content ID, used for "Who's flagged this" views.
|
87 |
|
|
$data['flagging']['entity_id'] = array(
|
88 |
4cfd8be6
|
Assos Assos
|
'title' => t('Entity ID'),
|
89 |
85ad3d82
|
Assos Assos
|
'help' => t('The unique ID of the object that has been flagged.'),
|
90 |
|
|
'argument' => array(
|
91 |
|
|
'handler' => 'flag_handler_argument_entity_id',
|
92 |
|
|
),
|
93 |
|
|
);
|
94 |
|
|
|
95 |
|
|
// Specialized is null/is not null filter.
|
96 |
|
|
$data['flagging']['flagged'] = array(
|
97 |
|
|
'title' => t('Flagged'),
|
98 |
|
|
'real field' => 'uid',
|
99 |
|
|
'field' => array(
|
100 |
|
|
'handler' => 'flag_handler_field_flagged',
|
101 |
|
|
'label' => t('Flagged'),
|
102 |
|
|
'help' => t('A boolean field to show whether the flag is set or not.'),
|
103 |
|
|
),
|
104 |
|
|
'filter' => array(
|
105 |
|
|
'handler' => 'flag_handler_filter_flagged',
|
106 |
|
|
'label' => t('Flagged'),
|
107 |
|
|
'help' => t('Filter to ensure content has or has not been flagged.'),
|
108 |
|
|
),
|
109 |
|
|
'sort' => array(
|
110 |
|
|
'handler' => 'flag_handler_sort_flagged',
|
111 |
|
|
'label' => t('Flagged'),
|
112 |
|
|
'help' => t('Sort by whether entities have or have not been flagged.'),
|
113 |
|
|
),
|
114 |
|
|
);
|
115 |
|
|
|
116 |
|
|
// Flag content links.
|
117 |
|
|
$data['flagging']['ops'] = array(
|
118 |
|
|
'title' => t('Flag link'),
|
119 |
|
|
'help' => t('Display flag/unflag link.'),
|
120 |
|
|
'field' => array(
|
121 |
|
|
'handler' => 'flag_handler_field_ops',
|
122 |
|
|
),
|
123 |
|
|
);
|
124 |
|
|
|
125 |
4cfd8be6
|
Assos Assos
|
$data['flagging']['sid'] = array(
|
126 |
|
|
'title' => t('Flagging session ID'),
|
127 |
|
|
'help' => t('The session ID of the flagging.'),
|
128 |
|
|
'field' => array(
|
129 |
|
|
'handler' => 'views_handler_field_numeric',
|
130 |
|
|
'click sortable' => TRUE,
|
131 |
|
|
),
|
132 |
|
|
'sort' => array(
|
133 |
|
|
'handler' => 'views_handler_sort',
|
134 |
|
|
),
|
135 |
|
|
'filter' => array(
|
136 |
|
|
'handler' => 'views_handler_filter_numeric',
|
137 |
|
|
),
|
138 |
|
|
'argument' => array(
|
139 |
|
|
'handler' => 'views_handler_argument_numeric',
|
140 |
|
|
),
|
141 |
|
|
);
|
142 |
|
|
|
143 |
85ad3d82
|
Assos Assos
|
$data['flag_counts']['count'] = array(
|
144 |
|
|
'title' => t('Flag counter'),
|
145 |
|
|
'help' => t('The number of times a piece of content is flagged by any user.'),
|
146 |
|
|
'field' => array(
|
147 |
|
|
'handler' => 'views_handler_field_numeric',
|
148 |
|
|
'click sortable' => TRUE,
|
149 |
|
|
),
|
150 |
|
|
'sort' => array(
|
151 |
|
|
'handler' => 'views_handler_sort',
|
152 |
|
|
),
|
153 |
|
|
'filter' => array(
|
154 |
|
|
'handler' => 'views_handler_filter_numeric',
|
155 |
|
|
),
|
156 |
|
|
'argument' => array(
|
157 |
|
|
'handler' => 'views_handler_argument_numeric',
|
158 |
|
|
),
|
159 |
|
|
);
|
160 |
|
|
|
161 |
|
|
$data['flag_counts']['last_updated'] = array(
|
162 |
|
|
'title' => t('Time last flagged'),
|
163 |
|
|
'help' => t('The time a piece of content was most recently flagged by any user.'),
|
164 |
|
|
'field' => array(
|
165 |
|
|
'handler' => 'views_handler_field_date',
|
166 |
|
|
'click sortable' => TRUE,
|
167 |
|
|
),
|
168 |
|
|
'sort' => array(
|
169 |
|
|
'handler' => 'views_handler_sort_date',
|
170 |
|
|
),
|
171 |
|
|
'filter' => array(
|
172 |
|
|
'handler' => 'views_handler_filter_date',
|
173 |
|
|
),
|
174 |
|
|
'argument' => array(
|
175 |
|
|
'handler' => 'views_handler_argument_date',
|
176 |
|
|
),
|
177 |
|
|
);
|
178 |
|
|
|
179 |
|
|
return $data;
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
/**
|
183 |
|
|
* Implements hook_views_data_alter().
|
184 |
|
|
*/
|
185 |
|
|
function flag_views_data_alter(&$data) {
|
186 |
|
|
|
187 |
|
|
foreach (array_keys(flag_fetch_definition()) as $flag_type) {
|
188 |
|
|
$flag = flag_flag::factory_by_entity_type($flag_type);
|
189 |
|
|
$info = $flag->get_views_info();
|
190 |
|
|
|
191 |
|
|
if (!isset($info)) {
|
192 |
|
|
continue;
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
if (!empty($info['join field'])) {
|
196 |
|
|
// Add the flag relationship.
|
197 |
|
|
$data[$info['views table']]['flag_content_rel'] = array(
|
198 |
|
|
'group' => t('Flags'),
|
199 |
|
|
'title' => $info['title'],
|
200 |
|
|
'help' => $info['help'],
|
201 |
|
|
'relationship' => array(
|
202 |
|
|
'flag type' => $flag_type,
|
203 |
|
|
'handler' => 'flag_handler_relationship_content',
|
204 |
|
|
'label' => t('flag'),
|
205 |
|
|
'base' => 'flagging',
|
206 |
|
|
'base field' => 'entity_id',
|
207 |
|
|
'relationship field' => $info['join field'],
|
208 |
|
|
),
|
209 |
|
|
);
|
210 |
|
|
|
211 |
|
|
// Add the flag counter relationship.
|
212 |
|
|
$data[$info['views table']]['flag_count_rel'] = array(
|
213 |
|
|
'group' => t('Flags'),
|
214 |
|
|
'title' => $info['counter title'],
|
215 |
|
|
'help' => $info['counter help'],
|
216 |
|
|
'relationship' => array(
|
217 |
|
|
'flag type' => $flag_type,
|
218 |
|
|
'handler' => 'flag_handler_relationship_counts',
|
219 |
|
|
'label' => t('counter'),
|
220 |
|
|
'base' => 'flag_counts',
|
221 |
|
|
'base field' => 'entity_id',
|
222 |
|
|
'relationship field' => $info['join field'],
|
223 |
|
|
),
|
224 |
|
|
);
|
225 |
|
|
}
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
// Add a relationship for the user that flagged any type of content.
|
229 |
|
|
$data['users']['flag_user_content_rel'] = array(
|
230 |
|
|
'group' => t('Flags'),
|
231 |
|
|
'title' => t("User's flaggings"),
|
232 |
|
|
'help' => t('Relate users to the flaggings they have made on objects, using a particular flag.'),
|
233 |
|
|
'relationship' => array(
|
234 |
|
|
'base' => 'flagging',
|
235 |
|
|
'base field' => 'uid',
|
236 |
|
|
'relationship field' => 'uid',
|
237 |
|
|
'handler' => 'flag_handler_relationship_user_content',
|
238 |
|
|
'label' => t('user flagged content'),
|
239 |
|
|
),
|
240 |
|
|
);
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
/**
|
244 |
|
|
* Implements hook_views_query_substitutions().
|
245 |
|
|
*
|
246 |
|
|
* Allow replacement of current user's session id so we can cache these queries.
|
247 |
|
|
*/
|
248 |
|
|
function flag_views_query_substitutions() {
|
249 |
|
|
return array(
|
250 |
|
|
'***FLAG_CURRENT_USER_SID***' => flag_get_sid(),
|
251 |
|
|
);
|
252 |
|
|
}
|
253 |
|
|
/**
|
254 |
|
|
* A helper function that creates a radio list of available flags.
|
255 |
|
|
*
|
256 |
|
|
* This function is used to select the desired flag when setting up flag
|
257 |
|
|
* relationships and fields.
|
258 |
|
|
*/
|
259 |
|
|
function flag_views_flag_config_form($form_type, $entity_type, $current_flag) {
|
260 |
|
|
$flags = flag_get_flags($entity_type);
|
261 |
|
|
|
262 |
|
|
$options = array();
|
263 |
|
|
foreach ($flags as $flag) {
|
264 |
|
|
$options[$flag->name] = $flag->get_title();
|
265 |
|
|
}
|
266 |
|
|
|
267 |
|
|
$form = array(
|
268 |
|
|
'#type' => $form_type,
|
269 |
|
|
'#title' => t('Flag'),
|
270 |
|
|
'#options' => $options,
|
271 |
|
|
'#default_value' => $current_flag,
|
272 |
|
|
'#required' => TRUE,
|
273 |
|
|
);
|
274 |
|
|
|
275 |
|
|
return $form;
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
/**
|
279 |
|
|
* Helper function that gets the first defined flag and returns its name.
|
280 |
|
|
*/
|
281 |
|
|
function flag_views_flag_default($entity_type) {
|
282 |
|
|
$default_flag = &drupal_static(__FUNCTION__, array());
|
283 |
|
|
|
284 |
|
|
if (!array_key_exists($entity_type, $default_flag)) {
|
285 |
4cfd8be6
|
Assos Assos
|
$flags = flag_get_flags($entity_type);
|
286 |
|
|
$flag = array_shift($flags);
|
287 |
85ad3d82
|
Assos Assos
|
$default_flag[$entity_type] = $flag ? $flag->name : NULL;
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
return $default_flag[$entity_type];
|
291 |
|
|
} |