Integrate with Activity2 Branch
Scott Reynolds - April 26, 2009 - 23:32
| Project: | User Relationships |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
| Issue tags: | activity2-integration |
Description
Composed of providing the two access controls.
hook_activity_grants($activity)
hook_activity_access_grants($account)
It has a trigger implementation already.

#1
First working pass. We are probably going to need to add another hook
<?php/**
* Implementation of hook_activity_access_info().
* return an array, keyed by realm that has a friendly title
*/
function hook_activity_access_info() {
return array(
'friend' => array(
'title' => t('Friend'),
),
);
}
?>
This then allows the Views filters to ask which realm in particular they care about or all realms that the module provides. Or maybe we just create the filters based on the realms returned from this. Remove the notion of module completely. I like the later approach best.
#2
forgot patch
#3
You may want to roll this from the module's root directory before submitting to them. Otherwise the new file appears in the wrong directory.
One thing I'm concerned about is basically requiring the other module to implement hook_init() and check for the Activity module in order to conditionally include the module.activity.inc file. Is there a better way to handle this? Maybe as a 'path' parameter in hook_activity_info() such as views does, and then we include the file through activity.module?
Also, once I go to add the user_relationships_api Activity Access filter, shouldn't I see a list of defined relationships in order to choose which relationship I'm filtering by? I'm just seeing:

#4
Thats not implemented yet but thats the plan. And then you can actually expose this as well, which is kindof cool.
The idea of removing the hook_init() i like as well. its a good extension.
#5
With this commit we achieve this
http://drupal.org/cvs?commit=205766
#6
And heres the patch to UR
#7
#8
I guess the only other thing to add is the file scanning to activity to look for activity.inc files and then we can submit this to UR
#446482: Inclusion of $module.activity.inc files
#9
tagging so we can point ppl to issues and patch on how to integrate.
#10
we still need to fix the trigger implementation and the hook_activity_info().
#11
subscribing.
#12
So what is a status of issue?
All patches are landed. Is this still an issue?
#13
This patch works. It doesn't allow though "User A became friends with User B". Just need to wrap the trigger stuff.
Flag_friend module is fully integrated.
#14
jUSt checking if there is any progress on this? IS there anything needed from UR side?
#15
subscribing
#16
@Scott Reynolds
is there any help you need to get this finished? Could you please describe what is still remaining to get this moving?
#17
See comment 13.
Again the patch works. Just missing trigger implementation for UR.
You can very easily create a View of all your Friend's activity
#18
@Scott could you point us to the trigger code and/or what needs to be done/updated there?
I'm needing the "User A became friends with User B" feature, as per your comment in #13. Thanks!
#19
The first step would be implementing Triggers in UR
http://drupal.org/node/375833
#20
I got it running for the "approve" operation of user_relationships_api. I can't get it to work properly with the tokens. Shall I post a patch or copy the source code here? It's not that much code.
#21
Please post it anyway so if someone has time they can build on it.
#22
Ok, I got it running for the "approve" operation of user_relationships_api. However, I can't get it to work properly with the tokens.
Copy
ur.module.patchur.actions.patchuser_relationships_api.activity.inc_.txtto
user_relationships/user_relationships_apifolder under your modules base folder. This file has the earlier patch in #6 already applied.Apply the patches by running
patch -p0 < ur.module.patchpatch -p0 < ur.actions.patchRename
user_relationships_api.activity.inc_.txttouser_relationships_api.activity.incThen create an activity at
admin/settings/activity/create, choose "User relationships api" as the type. I have it configured as in the sshot attached.Then request and approve a relationship, and see the activity is recorded (as in the last sshot attached).
Know issues:
- As you can see, the requester ("admin") is repeated, instead of displaying the requestee in the last place. Also, I cannot see the activity record when logged in as the requester.
- Haven't tested with more than one relationship type
I will be looking forward to your comments, thanks.
#23
debug code in patch
+ dd($type, 'type in token values');
+ dd($r, 'data in token values');
Moving to User Relationships module.
#24
Ok, today I got it running for the "approve" and "request" operations of user_relationships_api and fixed the token issues. Also removed the debug messages.
Copy
ur.module.2.patchto
user_relationships/user_relationships_apifolder under your modules base folder.reverse the ur.module.patch patch applied above, then,
apply the new patch by running
patch -p0 < ur.module.2.patchYou are now ready to create 2 activities at
admin/settings/activity/create, choose "User relationships api" as the type, one for "approve" another for "request".Then request and approve a relationship, and see both activity records being displayed (sshots attached). If you don't have a view, take a look at the activity* tables in the DB, as shown below.
mysql> select * from activity where op='approve' or op='request';
+-----+-----+---------+------------------------+------+------------+
| aid | uid | op | type | nid | created |
+-----+-----+---------+------------------------+------+------------+
| 438 | 50 | approve | user_relationships_api | NULL | 1253801590 |
| 437 | 1 | request | user_relationships_api | NULL | 1253801436 |
+-----+-----+---------+------------------------+------+------------+
2 rows in set (0.02 sec)
mysql> select * from activity_messages am join activity_targets at on at.amid=am.amid where at.aid=437 or at.aid=438;+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+-----+-----+------+
| amid | message | aid | uid | amid |
+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+-----+-----+------+
| 842 | <a href="/profile/admin" title="View user profile.">admin</a> requested connection to <a href="/profile/twiti" title="View user profile.">Twiti Jones</a> | 437 | 0 | 842 |
| 843 | <a href="/profile/admin" title="View user profile.">admin</a> and <a href="/profile/twiti" title="View user profile.">Twiti Jones</a> are now connected | 438 | 0 | 843 |
+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+-----+-----+------+
2 rows in set (0.00 sec)
Know issues:
- Haven't tested with more than one relationship type
- cannot display the approve activity in the requester stream, as the activity has an owner but not a "related" user or something that could act as argument as well.
- Done for two-way relationships, with request/approve workflow.
I will be looking forward to your comments, thanks.
#25
+ $info->objects = array('Requester' => 'requester', 'Requestee' => 'requestee+', 'Relationship' => 'relationship');
Code format is wrong
+ $token_values = array(+ 'requestee' => theme('username', user_load(array('uid' => $r->requestee_id))),
+ 'relationship-name' => theme('placeholder', $r->name),
+ );
+ // dd($token_values, 'token values return (relationship');
dd still here
#26
ok thanks, those are details, I'd like to receive more "interesting" feedback about the feature.
I am using it now in a project, and I'll keep the thread updated. Thanks in advance.
#27
Coming late to this conversation, but very interested.
Mariano, I'm applying all your patches and will report on my results.
#28
I have applied your two patches and am not seeing "User relationships api" in my list of type I can add. Any idea what I'm doing wrong?
#29
Daniel,
Thanks.
If you applied the ur.module.2.patch, you should be seeing this code inside user_relationships_api.module:
function user_relationships_api_activity_info() {$info = new stdClass();
$info->api = 2;
$info->name = 'user_relationships_api';
$info->object_type = 'user_relationships_api';
$info->objects = array('Requester' => 'requester', 'Requestee' => 'requestee
', 'Relationship' => 'relationship');
$info->hooks = array('user_relationships_api' => array('approve', 'request'));
return $info;
}
AFAIK, Activity scans all modules in search for that hook (activity_info) and finds it in the user_relationships_api.module and displays the new option in the activity template form. I remember having issues when discovering how Activity knew about the plugins, but all it needed was that hook in the .module file.
Not sure if this helps you, at least it confirms the hook implementation is everything. If, for some reason, Activity can't find the .module then it will not display anything different... Let me know if you can solve this or if you are still blocked. Thanks.
--m
#30
Hi Mariano Barcia,
The patch didn't quite work for me (kept getting an error when trying to apply the patch using TortoiseSVN)... However, when I manually applied the changes it worked very well!! Congrats on the work so far :)
Any ideas on how we can get this information to display in the activity stream (i.e. at /activity/all)?I checked the view and I'm assuming a Relationship is needed for User Relationships under "Relationships" (/admin/build/views/edit/all_activity)? I'm not entirely sure, but seems correct since the ones that are currently displaying (Node, User) have relationships setup. Any ideas on this? Are you currently working on this at all?Any help is greatly appreciated.Turns out creating a brand new view with the field "Activity: Message" (and no Filters - I think this is the key?) seems to bring back all the Activity... Now I just need to figure out why the Tokens in your patch don't seem to be available when creating the activity... Any ideas?
Many thanks once again,
Marc
#31
OK, I hadn't applied the patch correctly, and hadn't noticed. I'm a little confused about what version the patch is for, as my files look a little different from the lines in the patch. Anyway, applied module.2 "manually" and the options do show up in Activity. Do I still need to apply the actions patch as well? Confused because user_relationships_api_action_info() is commented out in my version (latest release).
#32
ehm... subscribing
#33
@Daniel,
You have to apply both patches (do #22 and then #24). the actions patch is needed.
BTW, to reverse a patch invoke the same as if you were to apply it. Then, the patch command is smart enough to detect that the patch had been applied before and asks for the confirmation of the rollback.
@Marc,
Thanks!
I have the activity configured like this
"[requestee] and [requester] are now connected" and it's working well so far. What's exactly the problem?
#34
All right, the actions patch did not work, but I added it manually, probably an issue of new dev releases since the patch was posted?
Anyway, I now have the ability to add a UR but the only tokens I am shown for to use in my messages are global tokens, which aren't too useful. I did some very quick debugging and it seems like user_relationships_api_token_list() isn't being called at all.
#35
Hi!
same problem here, after applying patches manually, the token area shows just global ones.
Might this be related to the fact i am using the 5th october dev version of activity? It has some major changes in translation handling...
EDIT: no, the patch did not work correctly and I applied it manually but not completely.
#36
Hi Mariano,
I tried putting in "[requestee] and [requester] are now connected" in the "configure" page for "User relationships api"... Which, when the activity is recorded, seems to do what it should (i.e. brings back the correct data). My only issue is that I don't seem to actually see those particular tokens available under "Available tokens"... Does it show up for you? I've supplied a screenshot of what I see when I click "Available tokens" >> "Global"
I've checked and the code is there, or so it seems...
<?php/**
* Implementation of hook_token_list().
*/
function user_relationships_api_token_list($type = 'all') {
if ($type == 'user_relationships_api') {
$tokens['user_relationships_api'] = array(
'requester' => t('The user who issued the connection request.'),
'requestee' => t('The user who approved the connnection request.'),
'relationship-name' => t('The relationship name (singular form)'),
);
return $tokens;
}
}
?>
Any ideas?
Thanks again, it works perfectly otherwise!! :)
#37
Hmm anyone else having issues with the template not being saved when you hit "Save"? The field "Requestee message:" always comes up blank, even though the others get saved as they should. Any ideas on this?Where abouts in the code does this field get saved/retrieved?EDIT: Never mind, I didn't patch the module quite correctly... In case anyone else gets this issue... Turns out it was because of a space after "requestee" in
$info->objects = array('Requester' => 'requester', 'Requestee' => 'requestee', 'Relationship' => 'relationship');Which was copied over as:
$info->objects = array('Requester' => 'requester', 'Requestee' => 'requestee ', 'Relationship' => 'relationship');#38
Since we have so many comments and moving parts, could someone please submit patch against latest dev UR and Activity 2 branch? So we can start with a common baseline and go from there to improve further.
#39
I think token list problem has something to do with the conditional ($type == 'user_relationships_api')
<?phpfunction user_relationships_api_token_list($type = 'all') {
if ($type == 'user_relationships_api') {
$tokens['user_relationships_api'] = array(
'requester' => t('The user who issued the connection request.'),
'requestee' => t('The user who approved the connnection request.'),
'relationship-name' => t('The relationship name (singular form)'),
);
print_r($tokens);
return $tokens;
}
}
?>
Debugging shows the $type being recieved is "requester".
And yes, I think this would be an appropriate time for a commit to the dev version. Won't break anything else and will make this all much easier :) .
#40
may I kindly ask UR RC3 will have support for activity module?
#41
Marc,
Figured out that removing "Relationships Activity: Node" from the view makes the user relationship activities show up.
This makes sense as activity table rows, involving user relationship activities, have a nid of 'null'.
If you want to filter the view further, say you want to display only approved user relationship activities, just add 'Activity: Operation = approve used in: user_relationships_api' in the view.
#42
You could have set this to not required and it would have worked as well. It will LEFT JOIN, allowing NULL values.
#43
For the tokens to appear in the token list the hook_token_list() implementation needs to be -
/*** Implementation of hook_token_list().
*/
function user_relationships_api_token_list($type = 'all') {
if ($type == 'requester') {
$tokens['user_relationships_api'] = array(
'requester' => t('The user who issued the connection request.'),
);
}else if ($type = 'relationship'){
$tokens['user_relationships_api'] = array(
'requestee' => t('The user who approved the connnection request.'),
'relationship-name' => t('The relationship name (singular form)'),
);
}
return $tokens;
}
Attaching patch for only the hook_token_list() but it may be easier to just copy / paste the above into your patch.
#44
code in #43 takes care of token_list().
I discovered hook_token_values() was not working in all cases.
The below code should work across the board -
/**
* Implementation of hook_token_values().
*/
function user_relationships_api_token_values($type, $data = NULL, $options = array()) {
if ($type == 'requester') {
$r = $data;
$token_values = array(
'requester' => theme('username', user_load(array('uid' => $r))),
);
}elseif ($type == 'requestee'){
$r = $data;
$token_values = array(
'requestee' => theme('username', user_load(array('uid' => $r))),
);
}
elseif ($type == 'relationship') {
$r = $data;
$r_type = user_relationships_type_load($r->rtid);
$token_values = array(
'requestee' => theme('username', user_load(array('uid' => $r->requestee_id))),
'requester' => theme('username', user_load(array('uid' => $r->requester_id))),
'relationship-name' => theme('placeholder', $r_type->name),
);
}
return $token_values;
}
#45
also, when i install the patches in #22 and #24 , i dont see any User Relationships Access filters in the View Filters area to choose from??
#46
You need to turn on the Access filters via admin/settings/activity
This is because we don't record it unless we need to, saves DB space.
#47
re-rolled patch to fix token bugs + bug with the filter not showing up in views.
#48
#49
forgot to remove line of debug in #47, re-uploading new patch.
#50
Would you like to see this patch in a RC? Should be rolling it in the next couple of days.
Also, it would be nice to see this as a conditional include file, so that it stays outside if activity is not enabled.
#51
Activity provides the mechism for conditional includes
<?php// This will tell activity to include user_relationships_api/includes/user_relationships_api.activity.inc
// only when it needs it
$info->path = drupal_get_path('module', 'user_relationships_api') .'/includes';
?>
And to create a patch with a new file:
http://drupal.org/patch/create where there is some good info on how to add a new file in a cvs patch with a link to a fakeadd.sh script that works wonderfully.
#52
Committed in an RC would be great, even if still buggy...
#53
is this RTBC or what do we need? do we need a roll-up of all the patches into one single patch file?
#54
Committed the various patches in http://drupal.org/cvs?commit=285542. I used user_relationships_api.module patch from #49, user_relationships_api.actions.inc and user_relationships_api.activity.inc from #22. After that there were two implementations of user_relationships_api_activity_grants() and user_relationships_api_activity_access_grants() - in .module and in .activity.inc. I removed the ones in .module. Please check that things fell into the right places as I may have missed something. Thanks!
#55
@alex.k
Just did a quick double-check of the process you followed, and it looks fine ==> the files should be ready to be checked out and tested/reviewed. Thanks. I'll give it a try this week.
#56
I appologise for my noobness but this patch is exactly what I need but tortoise SVN is really not happy about applying it for some reason and so I need to manually create this patch with what is available on this page.
I gather that a directory needs to be created /activity/user_relationships/user_relationships_api
and within that 2 files are needed: user_relationships_api.module and user_relationships_api.actions.inc
I thought that the patch in #49 would have all the functionality required for this integration, although it seems to be missing some functions from earlier patches and seems to put them all into user_relationships_api.module whereas I believe some belong in user_relationships_api.actions.inc, am i correct so far?
So my current position is that I have the direcories as above and I have user_relationships_api.module with all the functions in patch #49 in it. Perhaps not surprisingly when i go to admin/settings/activity I do not see any reference to user relationships.
Can someone please advise as to where I am going wrong?
Thanks
#57
Iv just realised i've been an idiot trying to update activity when I should have been updating UR.
#58
Hi,
I have a probleme with integration "Views". I want my friends activity in my profil "Panels".
Error with views
"warning: Invalid argument supplied for foreach() in mysite/public_html/sites/all/modules/activity/views/activity_views_handler_filter_access.inc on line 64"I would like to see the activities of my friends and myself in the same view. Is it possible?
Thx for your help !
Version activity2 6.x-2.x-dev (2009-nov.-06)
Version User Relationships 6.x-1.x-dev (2009-nov.-09)
#59
sorry, my Panel version 6.x-3.2
#60
please create an issue in Activity. not here. and don't post a screen shot, post the exported view.
#61
ooh i take that back. that error means that it failed to include UR's .activity.inc
#62
Scott,
I have the same problem: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/lbproduction/sites/all/modules/activity/views/activity_views_handler_filter_access.inc on line 64.
is there any hope to get that fixed?
Many thanks for the awesomenes!
#63
Please leave as a feature request. The feature is not yet "ready".
#64
I have opened following issue against activity2 #636974: Default view does not show UR activity records since the UR activities are recorded in DB but somehow default all activity view is skipping it.
#65
I tried to poke around and found that atleast in activity_get_module_info (activity.module) it is getting the value
of $info->path as correct path to "user_relationships_api" module. But don't know how to debug further.
IS this correct module, it should be trying to include conditionally?
#66
I dont understand ... UserRelationships and Activity2 does not show the activities of my friends. FlagFriends - 2.0 Flag and Activity2 does not show the activities of my friends ...
I may be zero! But all these modules are very big and important to create a community.
It's been a week that reported the bug to the support of all the modules.
Can you explain the solution please? Propose a view model to integrate with Panels!
I dont know, I want a solution ...
I know you have a lot of work and request, but this function is very important for the community.
Thank you for your help.
#67
I wanted to help debug this but don't know where I can go next. Already confirmed the path was correct atleast untill in activity_get_module_info (activity.module).
Any thoughts/hints/ideas?
#68
@tayzlor
Till your patch in #47, user_relationships_api_activity_access_grants had only one parameter, $account, but you have introduced three parameters $account, $object, $type; Why?
In activity_views_handler_filter_access_inc , activity_access_grants is being called without any parameter when it is expecting 3 $account, $object, $type and I think that is an issue.
#69
i have this patch working on a version of my code here, allowing users to only see their 'friends' activities.
not sure whats gone wrong in between, will checkout the latest UR + activty and try and re-apply the patches.