I am building a friend system in CakePHP for users based on this: Add a friend feature in CakePHP
But I 开发者_运维技巧need to add two additional features:
1.) Users need to be able to request and confirm/cancel friend requests
2.) Users need to be able to group friends e.g. Friends, Family, Co-workers etc
Can anyone give me some ideas as to what extra tables I would need and the likely relationships between them and the existing tables.
Also based on that article it seems the relationships are based on which user asked who but I don't care much for that so what would I do to make it so it's just a relationship rather than tracking which user requested the friendship and who is the friended friend?
NOTE: I asked a similar question earlier and had to delete it as everyone mis-understood the question. I am asking a question just like the one mentioned above and hoping to get answers like they have in terms of tables and relationships.
You'll need a field in your relationships database table called confirmed or similar. Basically when a friendship is requested a record is created, but with confirmed set to 0. When the "requestee" accepts the friendship, the confirmed field is set to 1, or if declined the record is deleted (allowing the requester to request friendship again).
To group, you'll obviously need a groups table with an ID and non-unique name field, and a groups_relationships
table that has two columns: relationship_id
and group_id
. This will allow a user to place a friend into a group. You can then query the groups_relationships
table with a group_id
to find the IDs of friends that a member has placed in that group.
精彩评论