After an encouraging email outlining a good idea (@see http://drupal.org/project/drupal_universal_relation_api) here's my first pass at this integration/theory. ;)

Comments

sirkitree’s picture

I have either hook_all_pending_from() or _to() incorrect. Will take another stab at them soon.

mercmobily’s picture

Hi,

First of all,

** THANK YOU **

Now, humble notes :D

function flag_friend_get_related_users($uid, $relation_name = NULL, $relation_style = 'all') {
  $friends = flag_friend_get_friends($uid, TRUE);
  if (!empty($friends)) {
    return array_keys($friends);
}

Remember that the API is based on UIDs, rather than user objects. So, this function should return an array() of UIDs rather than User Objects.

About this one:

 * NOTE: Could these function be consolidated into one?
 * IE: hook_all_pending()
 * @see hook_all_pending_from().
 * @see hook_all_pending_to().

Well, they could, but we should wait for then next version of the API :D

/**
 * Implementation of hook_get_relation_names().
 */
function flag_friend_get_relation_names($relation_style = 'all') {
  // flag_friend only implements one relationship type, return the title of the
  // flag.
  $flag = flag_get_flag('friend');
  return $flag->title;
}

/**
 * Implementation of hook_relation_type().
 */
function flag_friend_relation_type($relation_name) {
  // flag_friend only implements two-way relationships. If a one way
  // relationship is needed, you should be just using flag.
  return 'two-way';
}

Hummm the name of this API function is misleading -- sorry. The "relation names" should actually be the short_names used by your module to identify different relation types. You only have one. So, all you need to do is this:



<code>
/**
 * Implementation of hook_get_relation_names().
 */
function flag_friend_get_relation_names($relation_style = 'all') {
  return 'friend';
}

/**
 * Implementation of hook_relation_type().
 */
function flag_friend_relation_type($relation_name) {
  // flag_friend only implements the "friend" relation type
  // So, this is easy
  if($relation_name == 'friend'){
    return 'two-way';
  }
}

About hook_all_pending_from() and hook_all_pending_to(), can't really help because I am not using FlagFriend, but keep in mind that you need to return UIDs :D

Bye!

Merc.

andypost’s picture

StatusFileSize
new3.87 KB

Fixed flag_friend_get_relation_names() & flag_friend_relation_type()

First function should return array of types
And both should check parameters

mercmobily’s picture

Hi,

And all functions return UIDs, right?

I think we have an integration... don't we?

Merc.

andypost’s picture

Not all - only:
flag_friend_get_related_users() flag_friend_all_pending_from() flag_friend_all_pending_to()

All others return exactly what they should - arrays bools

sirkitree’s picture

I'm still not sure that we have flag_friend_all_pending_from() flag_friend_all_pending_to() implemented correctly.

@merc - do you have a module that is currently utilizing these api functions that you can do some testing upon?

mercmobily’s picture

Hi,

Yep, of course not all of them return UIDs -- silly me :D

I have been out of the scene for 6 months... so I am not sure which module actually uses the API. Sorry!

But, if they return a bunch of IDs as they should, we should be good to go.

They are so simple,I would mark them as fixed and wait for bug reports to pop in if things don't work as they should! But, these functions are so simple...

Thanks a million,

Merc.

sirkitree’s picture

Status: Active » Closed (won't fix)

unless someone would like to champion this