Posted by Todd Nienkerk on April 22, 2009 at 3:17pm
2 followers
Jump to:
| Project: | |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
I'd like to add various fields created by the Profile module to the Twitter message view type's output. Currently, only values from the User module are available.
Comments
#1
To include user profile fields in Twitter message view types, something like the following needs to be added to
twitter_views_data_alter():if (module_exists('profile')) {
$fields = profile_views_get_fields();
foreach($fields as $field) {
$table_name = 'profile_values_' . $field->name;
// Beginning of stuff I know nothing about
$data[$table_name]['table']['join']['twitter'] = array(
'table' => 'profile_values',
'left_table' => 'twitter_user',
'left_field' => 'uid',
'field' => 'uid',
'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
);
// End of stuff I know nothing about
// All fields in the table are named 'value'.
$data[$table_name]['value'] = profile_views_fetch_field($field);
}
}
This was largely pulled from
profile_views_data()(profile.module). Please note I know next to nothing about how Views abstracts its queries, so this is obviously flawed.Anyway, the addition above produces the following query:
SELECT twitter.twitter_id AS twitter_id,profile_values_profile_FIELD1.value AS profile_values_profile_FIELD1_value,
profile_values_profile_FIELD2.value AS profile_values_profile_FIELD2_value,
twitter.text AS twitter_text
FROM twitter twitter
LEFT JOIN twitter_account twitter_account ON twitter.screen_name = twitter_account.screen_name
LEFT JOIN twitter_user twitter_user ON twitter_account.screen_name = twitter_user.screen_name
LEFT JOIN profile_values profile_values_profile_FIELD1 ON twitter_user.uid = profile_values_profile_FIELD1.uid AND profile_values_profile_FIELD1.fid = '1'
LEFT JOIN profile_values profile_values_profile_FIELD2 ON twitter_user.uid = profile_values_profile_FIELD2.uid AND profile_values_profile_FIELD2.fid = '2'
A colleague and I found this query returns better results:
SELECT twitter.twitter_id AS twitter_id,profile_values_profile_FIELD1.value AS profile_values_profile_FIELD1_value,
profile_values_profile_FIELD2.value AS profile_values_profile_FIELD2_value
twitter.text AS twitter_text
FROM twitter twitter
LEFT JOIN twitter_account twitter_account ON twitter.screen_name = twitter_account.screen_name
LEFT JOIN twitter_user twitter_user ON twitter_account.screen_name = twitter_user.screen_name
LEFT JOIN profile_values profile_values_profile_FIELD1 ON twitter_user.uid = profile_values_profile_FIELD1.uid
LEFT JOIN profile_values profile_values_profile_FIELD2 ON twitter_user.uid = profile_values_profile_FIELD2.uid
WHERE profile_values_profile_link_bio.fid = '2'
AND profile_values_profile_name_first.fid = '1'
Essentially, the ANDs that get added to the JOIN ON part need to be a WHERE AND at the end. We're not sure how to accomplish this in Views, as the documentation is sparse.
#2
Hi Todd
We are currently scrubbing the issue queue and dusting off old feature requests. Is this something we should look into? To me could this be a rather nice thing to have.