| | 1 | = Symfony Doctrine Friends Plugin = |
|---|
| | 2 | |
|---|
| | 3 | Modeling and helpers for a simple friends system between users |
|---|
| | 4 | |
|---|
| | 5 | == Configuation == |
|---|
| | 6 | |
|---|
| | 7 | In your project config directory create a file named sfDoctrineFriendsPlugin.yml and place this in it. In this example my friend table is named 'friend' and the user model being used if 'sfGuardUser' and the user model id is 'id' |
|---|
| | 8 | |
|---|
| | 9 | This just allows you to link your user system to the friends plugin, and customize the table name for the plugin. |
|---|
| | 10 | {{{ |
|---|
| | 11 | schema: |
|---|
| | 12 | friend_table: friend |
|---|
| | 13 | user_model: sfGuardUser |
|---|
| | 14 | user_model_id: id |
|---|
| | 15 | }}} |
|---|
| | 16 | |
|---|
| | 17 | == Usage == |
|---|
| | 18 | |
|---|
| | 19 | {{{ |
|---|
| | 20 | <?php |
|---|
| | 21 | $friend = FriendTable::retrieveFriend($id); // retrieve friend record by id |
|---|
| | 22 | FriendTable::deleteFriend($id); // delete friend record by id |
|---|
| | 23 | |
|---|
| | 24 | // Create new friend between $myUserId and $friendUserId |
|---|
| | 25 | $friend = FriendTable::newUserFriend($myUserId, $friendUserId); |
|---|
| | 26 | $friend->save(); |
|---|
| | 27 | |
|---|
| | 28 | $friends = FriendTable::retrieveUserFriends($myUserId); |
|---|
| | 29 | print_r($friends); |
|---|
| | 30 | |
|---|
| | 31 | $friend = FriendTable::retrieveUserFriend($myUserId, $friendUserId); |
|---|
| | 32 | |
|---|
| | 33 | $exists = FriendTable::userFriendExists($myUserId, $friendUserId); |
|---|
| | 34 | echo $exists ? true:false; |
|---|
| | 35 | ?> |
|---|
| | 36 | }}} |
|---|