public function executeAdd(sfWebRequest $request) { //Set the local vars used in this function for easy access. $uid_from = $this->getUser()->getAttribute('id'); $uid_to = $request->getParameter('uid'); //Error Checking $this->errorCheck(!$this->getUser()->hasAttribute('id'), "Required request paramater uid_from is not set."); $this->errorCheck(!$request->hasParameter('uid'), "Required request paramater uid is not set."); $this->errorCheck($uid_to == null || $uid_to == 0, "Account id can not be null."); $this->errorCheck($uid_to == 1, "Friendship requests to the Administrator account are not allowed."); $this->errorCheck(!AccountTable::accountExists($uid_from), "Account ({$uid_from}) does not exist in database."); $this->errorCheck(!AccountTable::accountExists($uid_to), "Account ({$uid_to}) does not exist in database."); $this->errorCheck(FriendTable::areFriends($uid_from, $uid_to), "Account ({$uid_from}) and ({$uid_to}) are already friends."); $this->errorCheck(FriendRequestTable::requestPending($uid_from, $uid_to), "Account ({$uid_from}) has already requested ({$uid_to}) for friendship."); $this->errorCheck(FriendRequestTable::requestPending($uid_to, $uid_from), "Account ({$uid_to}) has already requested ({$uid_from}) for friendship."); $this->errorCheck($uid_from == $uid_to, "Account ({$uid_from}) can not request friendship with itself."); //Request is valid if code reaches here so make a friend request object and save it. $friendRequest = new FriendRequest(); $friendRequest->uid_from = $uid_from; $friendRequest->uid_to = $uid_to; $friendRequest->save(); $url = "default/index"; if ($request->hasParameter('redirect_url')) { $url = $request->getParameter('redirect_url') . 'index'; } $this->flashAndRedirect("Friendship successfully requested.", $url); }
?> <div id="text_send_message"><?php echo link_to('Send Message', "messages/newMessage?uid=" . $profile->getUid()); ?> </div> <?php } ?> <?php if (FriendTable::areFriends($sf_user->getAttribute('id'), $profile->getUid()) || $sf_user->getAttribute('id') == $profile->getUid()) { $x = null; } else { if (FriendRequestTable::requestPending($sf_user->getAttribute('id'), $profile->getUid())) { $x = "Friend Request Pending"; } else { if (FriendRequestTable::requestPending($profile->getUid(), $sf_user->getAttribute('id'))) { $x = link_to('Accept Pending Friend Request', 'friendRequests/accept?uid=' . $profile->getUid()); } else { $x = link_to('Add As Friend', 'friendRequests/add?uid=' . $profile->getUid()); } } } echo $x; ?> <div class="friend_list"> <h4>Friends</h4><hr width="100px" align="left"> <?php foreach ($friends as $friend) { ?>
public function mustRespondToAFriendRequestFrom($profile) { return FriendRequestTable::requestPending($profile->getUid(), $this->getAttribute('id')); }