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

Scott Reynolds - April 27, 2009 - 16:22

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

Scott Reynolds - April 27, 2009 - 16:23

forgot patch

AttachmentSize
ur.patch 2.95 KB

#3

sirkitree - April 27, 2009 - 18:55
Status:active» needs work

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:
Edit view activity | activity2

#4

Scott Reynolds - April 27, 2009 - 18:58

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

Scott Reynolds - May 1, 2009 - 22:44

With this commit we achieve this
http://drupal.org/cvs?commit=205766

#6

Scott Reynolds - May 1, 2009 - 22:46

And heres the patch to UR

AttachmentSize
ur.patch 3.13 KB

#7

Scott Reynolds - May 1, 2009 - 22:46
Status:needs work» needs review

#8

sirkitree - May 2, 2009 - 00:01
Status:needs review» postponed

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

sirkitree - May 2, 2009 - 20:33

tagging so we can point ppl to issues and patch on how to integrate.

#10

Scott Reynolds - May 4, 2009 - 22:16
Status:postponed» needs work

we still need to fix the trigger implementation and the hook_activity_info().

#11

likewhoa - May 7, 2009 - 05:01

subscribing.

#12

andypost - May 27, 2009 - 00:43

So what is a status of issue?
All patches are landed. Is this still an issue?

#13

Scott Reynolds - May 27, 2009 - 01:29

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

ajayg - August 8, 2009 - 22:53

jUSt checking if there is any progress on this? IS there anything needed from UR side?

#15

hobgobbler - September 10, 2009 - 12:23

subscribing

#16

ajayg - September 13, 2009 - 20:31

@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

Scott Reynolds - September 13, 2009 - 21:49

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

mariano.barcia - September 17, 2009 - 00:46

@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

Scott Reynolds - September 17, 2009 - 18:18

The first step would be implementing Triggers in UR

http://drupal.org/node/375833

#20

mariano.barcia - September 23, 2009 - 20:16

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

ajayg - September 23, 2009 - 21:44

Please post it anyway so if someone has time they can build on it.

#22

mariano.barcia - September 23, 2009 - 21:53

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.patch
ur.actions.patch
user_relationships_api.activity.inc_.txt
to user_relationships/user_relationships_api folder under your modules base folder. This file has the earlier patch in #6 already applied.

Apply the patches by running
patch -p0 < ur.module.patch
patch -p0 < ur.actions.patch

Rename user_relationships_api.activity.inc_.txt to user_relationships_api.activity.inc

Then 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.

AttachmentSize
ur.actions.patch 2.68 KB
ur.module.patch 3.44 KB
user_relationships_api.activity.inc_.txt 1.66 KB
activity setting.jpg 96.77 KB
ur-activity item in a view.jpg 3.68 KB

#23

Scott Reynolds - September 23, 2009 - 22:04
Title:UR implementation for 2.x branch» Integrate with Activity2 Branch
Project:Activity» User Relationships
Version:6.x-2.x-dev» 6.x-1.x-dev
Component:Activity Contrib» Code
Assigned to:Scott Reynolds» Anonymous

debug code in patch
+ dd($type, 'type in token values');
+ dd($r, 'data in token values');

Moving to User Relationships module.

#24

mariano.barcia - September 24, 2009 - 14:54

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.patch
to user_relationships/user_relationships_api folder 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.patch

You 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.

AttachmentSize
ur.module.2.patch 3.46 KB
ur-activity (approver view).jpg 3.97 KB
ur-activity (requester view).jpg 3.65 KB

#25

andypost - September 24, 2009 - 17:28

+    $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

mariano.barcia - September 25, 2009 - 13:13

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

dafeder - October 2, 2009 - 13:34

Coming late to this conversation, but very interested.

Mariano, I'm applying all your patches and will report on my results.

#28

dafeder - October 2, 2009 - 23:08

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

mariano.barcia - October 3, 2009 - 16:22

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

marc.groth - October 6, 2009 - 13:09

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

dafeder - October 6, 2009 - 16:20

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

vermario - October 6, 2009 - 16:15

ehm... subscribing

#33

mariano.barcia - October 6, 2009 - 19:38

@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

dafeder - October 7, 2009 - 02:49

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

vermario - October 7, 2009 - 10:47

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

marc.groth - October 7, 2009 - 11:29

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!! :)

AttachmentSize
available-tokens.jpg 207.46 KB

#37

marc.groth - October 7, 2009 - 12:20

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

ajayg - October 7, 2009 - 17:31

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

dafeder - October 7, 2009 - 18:44

I think token list problem has something to do with the conditional ($type == 'user_relationships_api')

<?php
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)'),
    );
   
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

drupallogic - October 20, 2009 - 00:27

may I kindly ask UR RC3 will have support for activity module?

#41

wkmit - October 21, 2009 - 12:44

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

Scott Reynolds - October 21, 2009 - 17:29

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'.

You could have set this to not required and it would have worked as well. It will LEFT JOIN, allowing NULL values.

#43

tayzlor - October 23, 2009 - 11:04

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.

AttachmentSize
user_relationships_api_token_list.patch 1.04 KB

#44

tayzlor - October 23, 2009 - 15:02

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

tayzlor - October 23, 2009 - 15:39

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

Scott Reynolds - October 23, 2009 - 16:15

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

tayzlor - October 26, 2009 - 12:05

re-rolled patch to fix token bugs + bug with the filter not showing up in views.

AttachmentSize
user_relationships_api_activity.patch 4.65 KB

#48

tayzlor - October 26, 2009 - 12:05
Status:needs work» needs review

#49

tayzlor - October 26, 2009 - 12:09

forgot to remove line of debug in #47, re-uploading new patch.

AttachmentSize
user_relationships_api_activity.patch 4.62 KB

#50

alex.k - October 26, 2009 - 13:05

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

Scott Reynolds - October 26, 2009 - 16:47

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

dafeder - October 29, 2009 - 22:27

Committed in an RC would be great, even if still buggy...

#53

tayzlor - October 30, 2009 - 12:31

is this RTBC or what do we need? do we need a roll-up of all the patches into one single patch file?

#54

alex.k - November 7, 2009 - 19:20
Status:needs review» active

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

mariano.barcia - November 8, 2009 - 18:44

@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

adam_c - November 9, 2009 - 18: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

adam_c - November 9, 2009 - 19:34

Iv just realised i've been an idiot trying to update activity when I should have been updating UR.

#58

charlie836 - November 11, 2009 - 01:17

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)

AttachmentSize
views-capture.JPG 64.4 KB

#59

charlie836 - November 11, 2009 - 01:23

sorry, my Panel version 6.x-3.2

AttachmentSize
views-capture.JPG 64.4 KB

#60

Scott Reynolds - November 11, 2009 - 01:43

please create an issue in Activity. not here. and don't post a screen shot, post the exported view.

#61

Scott Reynolds - November 11, 2009 - 01:48

ooh i take that back. that error means that it failed to include UR's .activity.inc

#62

nitram079 - November 13, 2009 - 15:02
Category:feature request» bug report

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

alex.k - November 13, 2009 - 15:11
Category:bug report» feature request

Please leave as a feature request. The feature is not yet "ready".

#64

ajayg - November 19, 2009 - 05:39

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

ajayg - November 20, 2009 - 13:54

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

charlie836 - November 21, 2009 - 01:44

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

ajayg - November 23, 2009 - 18:10

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

ajayg - November 25, 2009 - 05:59

@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

tayzlor - November 25, 2009 - 10:09

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.

 
 

Drupal is a registered trademark of Dries Buytaert.