Closed (fixed)
Project:
User Relationships
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Oct 2007 at 20:49 UTC
Updated:
12 Nov 2007 at 22:42 UTC
Jump to comment: Most recent file
Comments
Comment #1
prfctns6@gmail.com commentedI really want
user_relationships_load_relationships($criteria)to return an array indexed by relatee whenever possible. But it seems a little weird to have that behavior only happen if $criteria contains a key of 'uid' — it seems like the behavior is hidden from the API user. Another option is to have it accept an optional second parameter, $relater. If $relater is set, use that to determine the $relatee to index by. My problem with that is that it's possible to specify the criteria such that some of the matching relationships don't have $relater as either the requester_id or the requestee_id. The returned array might then be unpredictably indexed, possibly leading to weird, hard-to-track-down bugs.What do folks think? How should the function determine the uid of the relater: by inspecting the criteria, which is a bit cryptic but always safe, or by accepting a parameter, which is more explicit but riskier?
Comment #2
prfctns6@gmail.com commentedWell, I'll just have a big ol' conversation with myself here. :-)
I realized that there can be more than one relationship between 2 individuals, so returning a flat array indexed by relatee would only return one of their relationships, selected somewhat arbitrarily. That's obviously unacceptable, so now I'm thinking of having 3 API functions:
ur_count_relationships() just returns a count, as it does already. ur_load_relationships() returns a flat array with an arbitrary index. ur_load_relationships_by_relatee() returns an array indexed by $relatee relative to $relater. Each element of the array is itself an array of the relationships that exist between $relater and $relatee. All relationships that match the criteria but don't involve $relater are returned in the array indexed by $relatee=-1, so as not to conflict with any valid user id.
I think this works ok., and is fairly comprehensible. Anybody else want to chime in on this conversation? :-)
Comment #3
prfctns6@gmail.com commentedHere's a patch that implements the API as described in update #2 above.
Comment #4
prfctns6@gmail.com commentedIn the absence of any objections, I've committed the changes to the API.
I also updated the criteria for counting/loading relationships such that the values of uid, uid1, uid2, rid, requester_id, requestee_id and rtid can be scalars or arrays; if they're arrays, the functions match relationships where the appropriate column matches any element in the array.
Comment #5
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.