Views2 Integration
idontknowtheanswer - November 17, 2008 - 19:09
| Project: | Activity |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | sirkitree |
| Status: | closed |
| Issue tags: | activity-6.x-1-3 |
Description
I've created a couple of blocks using using the Activity module to show recent comments on a users articles and recent comments\articles that a user has created. At the moment though I can't see any way of creating these blocks without having to make calls directly into the module itself. Should there be an include file that exposes handy core functions like "activity_get_activity", "activity_token_*" etc?
It's my understanding of Drupal that external APIs that are intended to be called should be in the include file (is that correct?), I'm a bit nervous calling the module functions directly as I guess they can be changed at will.
Hope I've not missed the point!

#1
You've not missed the point at all. I actually plan on getting some Views2 integration into activity within the next month or two here and that will take care of a lot of problems I believe, specifically this one :) Hence I might as well use this issue! Changing Category and Title, assigning to myself.
#2
This would be great to see.
(Subscribing)
#3
nice ! subscribing
#4
Please review this package based on DRUPAL-6--1 branch. Extract in activity/ module directory patch activity.module from cvs.
There are a couple of handlers to handle the target_role, module, and data fields. There's a basic default view comparable to the All Activity page.
The serialized $data just gets output as a link to whatever kind of object it was (node, comment, user). This should catch all of the contrib modules, but if there are any others, then it'll dump the serialized data (for testing). The output is probably not desirable, and more options are required in case someone wants to display node->teaser or some other kind of object. This also checks to make sure the node/user/comment exists before linking to a non-existent path (it just prints out the id which again is probably not desirable).
This is a work-in-progress, not complete functionality. Hopefully this gets the ball rolling to churn around ideas about how things should look and what needs to be added.
#5
Awesome! Thank you mradcliffe! I look forward to reviewing this soon!
#5
Wow!! It works great!!
I would appreciate a lot having the comment:insert field with the tokens already applied, this way it would be possible to show exactly the same texts that are now in the existing module pages and blocks. The only issue would be for selecting which one from the different role configurations. Maybe it could be done with the activity:role field as a display option for the comment:insert field or using a filter in the view with the activity:role.
(We need to be careful using the right access permissions to show only the right information depending of user roles or role permissions)
I have tested it with the Spy Views from Views Bonus Module and it has a nice scrolling effect, I guess that it can be used as well with the ticker or carousel views modules.
Very nice!
#6
Yes this is what's left to do besides tidying things up.
It looks like you can do this in either pre_render() or render().
I'm having trouble formatting things correctly so that I can run
activity_token_replace(). The $row array needs to be built properly. So far I have it replacing some tokens, but not all of them trying to step through the token replacement in activity manually.Also we need to make sure that the case where a user has not included the correct fields is taken care of. If a user decides not to include module, created, operation, type, and target_role, then you won't be able to do token replacement because there is no data for it to replace! It would be pretty ugly to do another query to get that info. even though there are some view handlers that do extra queries in odd places in the views api.
#7
I figured out what I needed from the previous post though I'm not able to use activity_replace_token(), but doing something similar.
I included the alternate serial output in case a user doesn't use the required fields. The code is a bit ugly and needs cleaned up.
For the role I'm using an option form in the serial field for now.
#8
Hi mradcliffe,
I was testing your second patch, and although it works fine, it is not really very useful with the data serial field, it is not possible to process the information directly from views without coding. First patch was better. Thank you.
#9
Testing this too
#10
You probably don't want to use the default view, it needs to be redone. Please create your own view to test.
#11
Looking forward to this being committed :-) Subscribing
#12
This needs a tokenized text field rather than just the info output.
Also getting these errors:
* user warning: Unknown column 'activity_targets.uid' in 'on clause' query: SELECT COUNT(*) FROM (SELECT activity.aid AS aid FROM test_activity activity LEFT JOIN test_activity_targets activity_targets ON activity.aid = activity_targets.aid LEFT JOIN test_users users_activity_targets ON activity_targets.uid = users_activity_targets.uid LEFT JOIN test_users users_activity ON activity.uid = users_activity.uid ) count_alias in C:\xampp\htdocs\drupal\sites\all\modules\views\includes\view.inc on line 705.
* user warning: Unknown column 'activity_targets.uid' in 'on clause' query: SELECT activity.aid AS aid, users_activity_targets.name AS users_activity_targets_name, users_activity_targets.uid AS users_activity_targets_uid, activity.created AS activity_created, activity.data AS activity_data, activity.module AS activity_module, activity.operation AS activity_operation, activity.type AS activity_type FROM test_activity activity LEFT JOIN test_activity_targets activity_targets ON activity.aid = activity_targets.aid LEFT JOIN test_users users_activity_targets ON activity_targets.uid = users_activity_targets.uid LEFT JOIN test_users users_activity ON activity.uid = users_activity.uid LIMIT 0, 25 in C:\xampp\htdocs\drupal\sites\all\modules\views\includes\view.inc on line 731.
#13
Since this seems to be kind of tabled into 6.2 I'm going to switch over and work on that instead.
One thing I noticed about the activity 6.2 views integration is that it's missing a couple of things that might help make the activity stream. Having 'type' and/or 'op' as fields will enable you to use them as grouping fields (and thus group the similar activity types on the same row as discussed at the BoF). Also should provide a relationship to the users table for 'uid' (doer) that way you can put things like user profile pictures and other user information. Again helps with the activity stream/facebook-style messages.
#14
Definitely interested in Views2 integration (either activity branch)... subscribing.
#15
Here's another version of the patch. It's rolled against the latest 6.x-1.x-dev version and includes a new 'Row style' called 'Activity'. This will print the activity message generated from the serialized data column.
I know work on the 6.x-2.x branch is happening, but there's no upgrade path and I imagine it isn't that stable yet, so I'd still like to see this patch committed if possible.
Cheers,
Stella
#16
subscribe, thx!
#17
New version, with new filters for activity operation and type.
#18
subscribe
#19
tagging for next point release.
#20
Stella, your patch applies cleanly enough, however I'm not seeing the row style plugin so the data field is just being rendered serialized. I know you have a couple of // FIXME:'s in here, so what am I missing?


I really want to get this in, so any feedback would be greatly appreciated.
#21
retagging for next release
#22
In order to see the row style plugin, you must first create a view of the "activity" type (rather than node, user, taxonomy, etc). See the first image - 'add_view.png'.

Once you do that the activity row style plugin is available - see 'set_row_style.png'.
#23
I think those FIXME notes are from me, from activity_views_handler_field_serial.inc.
Edit: In fact ignore everything in this post except that comment above.
VVVVV Ignore that patch, it's bad.... crap.
#24
Okay, I tested and the patch works for me.
I have re-arranged things in the following patch as well as fixing an issue with the serial handler.
Sorry for the false edit above.
#25
Oh ok, I was going by the default view that is provided in this patch which I assumed already had Activity as it's base table, described in the first screenshot of #22
#26
Last patch omitted the default view for activity items, so have added this back in.
Cheers,
Stella
#27
I removed the default view because it may be better to use the row style instead of the serial field hack in a default view. It's kind of confusing at the moment. I kind of threw it in there just for testing purposes.
Probably need 2-3 default views to correspond with the activity pages already defined (activity activity/my or whatever it is now).
#28
Yeah, the default view provided uses the table layout and just displays each of the columns in the db. I agree it might be better to switch to the 'unformatted' layout and use the 'activity' row style rather than 'fields' instead, so I've attached another version of the patch that does this.
#29
Looking good guys! I added a little error checking to _filter_type.inc and _filter_operation.inc mainly because hook_activity_info() has changed between versions (6.x-1 and 6.x-2) and if the 'op' or 'type' key isn't returned by hook_activity_info() we end up with errors when adding those filters.
The default view that stella rolled in is good to go - thank you.
However, I have a feeling that there are going to be people who really want to be able to use fields in order to customize their display, and it doesn't seem that _field_serial.inc is quite working yet, evidenced by the fact that when I did change the style from Unformatted to Table, my display looks like this:

I fixed this by simply resaving the data field so that it contained the $this->options['target_role'] variable, however the code style in that file was not satisfactory either (mainly the if else's). I formatted it with normal Drupal coding standards.
Also, can one of you verify what this piece within activity_views_plugin_row_activity_view.inc (commented out) is and remove it if we really don't need it?
<?php
/*
if ($view->query === NULL) {
return;
}
// Clear the fields first
//$view->query->clear_fields();
$view->query->add_field('activity', 'aid', 'aid');
$view->query->add_field('activity', 'uid', 'uid');
$view->query->add_field('activity', 'module', 'module');
$view->query->add_field('activity', 'type', 'type');
$view->query->add_field('activity', 'operation', 'operation');
$view->query->add_field('activity', 'created', 'created');
$view->query->add_field('activity', 'data', 'data');
//$view->query->add_field('activity', 'nid', 'nid');
*/
?>
Please try my reroll to make sure that it's still performing as you've intended.
Thanks! Pretty excited to get this committed :)
#30
Yep, it still works as expected. :)
The commented out code isn't needed - I think it was something I was testing when adding the row style plugin, and it should have been removed before creating the patch, my bad.
#31
Alright guys, it's landed! Thanks for all your help getting this in!
http://drupal.org/cvs?commit=204306
#32
I added a documentation child page for this as it may be confusing -- http://drupal.org/node/447536. There is a spot for Activity 2.x views documentation as well.
#33
Awesome! Thanks mradcliffe!
#34
I probably sound like a lazy idiot, but how do we get the updated module with views support??
#35
download the latest 6.x-1.x-dev version
#36
I've downloaded and enabled the dev version but when I create a new View of the Activity type, I only see "Fields" for Row Style. I do not see "Activity" as in screen shot from post #22.
#37
Add me as a person referenced from post #29 that would like to control all of the fields manually.
One of the things I am looking to do is to integrate the view with both user relationships and content profile. I.E. I'd like to add views relationships and fields so I can customize the output based on the content profile of each user in the activity action, and then have something like"[mycckfirstnamefield] [myccklastnamefield] is now following [mycckfirstnamefield] [myccklastnamefield]" where they are all linked back to the content/node profile. I could also use this to pull in other cck profile fields, like the user's picture.
Thanks in advance for the work everyone has done on this so far!
#38
Automatically closed -- issue fixed for 2 weeks with no activity.
#39
Is this a separate module, if so is there a module page, or only CVS? Does this allow you to create site wide activity using views, or limited to user based activity?
#40
its in the -dev release and will be rolled in 1.3 when that is released
#41
Any plans to release 1.3? Views integration is a must for most of the use cases of this module.