Hello all,
I've made some tests and got OG working for my purposes by extending og_views.inc.
The objective is:
Provide a droplet in mysite that shows posts in the user subscribed groups. Current limitation is that OG doesn't provide such a filter (it only provides a filter for the currenly logged-in user).
Not everything on this patch must necessarily be in og_views, but the filter should be there (and would need approval of the OG dev team).
Attached you will find a patch for the og_views.inc file, and instructions to test are:
- move to og module basedir, and patch og_views.inc executing
patch -p0 < og_views.inc.txt - clear the cache (truncate cache table or use devel module)
- import the view below
- go to the mysite settings and add a droplet based on the newly created block "Latest Posts in my groups"
- enable the droplet for some user and you will see the posts only for that user's subscribed groups
This is the exported view (based upon og_mytracker)
<?php
$view = new stdClass();
$view->name = 'og_mysitetracker';
$view->description = 'Shows all activity in subscribed groups.';
$view->access = array (
0 => '2',
);
$view->view_args_php = '';
$view->page = FALSE;
$view->page_title = 'Recent posts in mysite groups';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = 'There are no posts in your subscribed groups.';
$view->page_empty_format = '1';
$view->page_type = 'table';
$view->url = 'group/mysitetracker';
$view->use_pager = TRUE;
$view->nodes_per_page = '25';
$view->menu = TRUE;
$view->menu_title = 'My recent';
$view->menu_tab = TRUE;
$view->menu_tab_weight = '0';
$view->menu_tab_default = FALSE;
$view->menu_tab_default_parent = NULL;
$view->menu_tab_default_parent_type = 'tab';
$view->menu_parent_tab_weight = '0';
$view->menu_parent_title = '';
$view->block = TRUE;
$view->block_title = 'Latest Posts in my groups';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'node';
$view->nodes_per_block = '5';
$view->block_more = FALSE;
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
);
$view->argument = array (
array (
'type' => 'rss_feed',
'argdefault' => '2',
'title' => '',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'og_node_data',
'field' => 'title',
'label' => 'Group',
),
array (
'tablename' => 'node',
'field' => 'type',
'label' => 'Type',
'sortable' => '1',
),
array (
'tablename' => 'node',
'field' => 'title',
'label' => 'Group',
'handler' => 'views_handler_field_nodelink_with_mark',
'sortable' => '1',
'options' => 'link',
),
array (
'tablename' => 'users',
'field' => 'name',
'label' => 'Author',
'sortable' => '1',
),
array (
'tablename' => 'node_comment_statistics',
'field' => 'comment_count',
'label' => 'Replies',
'handler' => 'views_handler_comments_with_new',
'sortable' => '1',
),
array (
'tablename' => 'node_comment_statistics',
'field' => 'last_comment_timestamp',
'label' => 'Last Post',
'handler' => 'views_handler_field_since',
'sortable' => '1',
'defaultsort' => 'DESC',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'og_uid_node',
'field' => 'mysiteuid',
'operator' => '=',
'options' => '',
'value' => '<strong><em>MYSITE_USER</em></strong>',
),
);
$view->exposed_filter = array (
);
$view->requires = array(og_node_data, node, users, node_comment_statistics, og_uid_node);
$views[$view->name] = $view;
?>Next step would be do the same for buddylist module. It would be nice if MySite could provide these filters without having to mess with other modules' codebase, perhaps it's possible.
Hope this helps,
--mariano
| Attachment | Size |
|---|---|
| og_views.inc_.txt | 1.74 KB |
Comments
Plugins
It would probably be easier to write an OG plugin for the MySite module, using the API. http://therickards.com/api
MySite doesn't really pass data to Views via filters since MySite itself does not generate any data.
Similar topics discussed at http://drupal.org/node/155969 and http://groups.drupal.org/node/5854
--
http://ken.therickards.com/
http://savannahnow.com/user/2
http://blufftontoday.com/user/3
--
http://ken.therickards.com/
Options
Hi Ken,
Thanks for the feedback.
An API is powerful, but also complex. I read the docs, and I couldn't get a good idea of how to achieve what I'm trying to do.
MySite is a powerful module, I am positive that other module maintainers would be willing to integrate if they can get things easy. Oh, and BTW, the long piece of code above is just to build the view, and the real patch is fairly small.
I can think of implementing these 2 functions (one is a hook of views module) to MySite:
<?php
/<em>
* Allow replacement of current group so we can cache these queries.
*/
function mysite_views_query_substitutions($view) {
global $user;
if (arg(0) == 'mysite' && is_numeric(arg(1))) {
$uid = arg(1);
}
else {
$uid = $user->uid;
}
$ret_array = array('***MYSITE_USER***' => $uid);
return $ret_array;
}
/</em>
* Simple array for MySite user.
*/
function mysite_handler_filter_mysiteuser() {
return array('***MYSITE_USER***' => t('MySite User'));
}
?>
This way, other modules could simply add a filter and, like in the case of OG, it should be a simple addition (like 6 lines of code). My point here is that every module is doing this very same thing for the currently logged-in user, and that they should simply add a similar filter with the callback already provided by MySite.
In the example of OG, they already have a filter to return all the posts in the subbed groups, for the currently logged-in user. Simply adding an almost identical filter, should work. Buddylist and other modules should work in a similar fashion don't you think?
In OG, I simply "hacked" the already existing filter set, and added another filter based on the existing "uid" filter of OG
<?php+ 'mysiteuid' => array(
+ 'field' => 'uid',
+ 'name' => t('Og: Post in MySite User Subbed Groups'),
+ 'operator' => 'views_handler_operator_eqneq',
+ 'list' => 'mysite_handler_filter_mysiteuser',
+ 'list-type' => 'select',
+ 'help' => t('Posts are filtered to groups that current MySite user is a member of.'),
+ ),
+ ),
?>
Salud,
Mariano Barcia
Colaborativa.net
Company:
http://www.colaborativa.net
Blog:
http://borabora.colaborativa.net
Nuevo:
http://tequejas.com
I agree that for cases that
I agree that for cases that can be handled by Views, we should simply use Droplets (that's why Droplets support Views).
Actually, I don't know the inner working of Views enough to answer those questions.
I think I get those first two pieces
mysite_views_query_substitutionsandmysite_handler_filter_mysiteuser, and it would make sense to include them. I presume they provide UI hooks for View creation.Can you open a feature request?
For the MySite API, see http://drupal.org/node/119576 and http://drupal.org/node/119583 for additional documentation.
MySite plugins are best used for cases where you have near-limitless options for data choices.
--
http://ken.therickards.com/
http://savannahnow.com/user/2
http://blufftontoday.com/user/3
--
http://ken.therickards.com/
Feature request added
http://drupal.org/node/198904
Thanks a lot Ken, I will be looking forward to more feedback ;-)
Mariano Barcia
Colaborativa.net
Company:
http://www.colaborativa.net
Blog:
http://borabora.colaborativa.net
Nuevo:
http://tequejas.com