Facebook-Like User Permissions

How would I start realizing per user permissions for a social network regarding who can see who’s content like: the friends of my friends may see my pictures.

I have already two tables in my db - one for friends connections like



      1|      2| friends request

      1|      3| approved

      3|      1| approved 

as well as a permissions table

userid|      images| birthday| email


     1|    everyone|  friends| only_me

     2| all_members|  only_me| friends-of-friends

By using this tables it is quite easy to find out if someone is permitted to see certain content. But how would I do it in Yii style? I would like to exchange complete widgets for a "user has restricted the permissions to view this content. maybe you want to connect to username?" text.

Does an extension exists or is already the extension ‘rights’ useful in this case?