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); }
public function configure() { $friend_array = array(); $friends = FriendTable::getFriendsOfUid($this->uid); $count = 0; foreach ($friends as $friend) { $friend_array[$friend->getUid()] = $friend->getName(); $count++; } //echo $count; //die; $this->setWidgets(array('recipients' => new sfWidgetFormChoice(array('multiple' => true, 'choices' => $friend_array)), 'subject' => new sfWidgetFormInput(), 'message' => new sfWidgetFormInput())); $this->setValidators(array('recipients' => new sfValidatorString(array('required' => false)), 'subject' => new sfValidatorString(array('required' => false)), 'message' => new sfValidatorString(array('required' => false)))); $this->widgetSchema->setNameFormat('message[%s]'); }
public function executeNewMessage(sfWebRequest $request) { $friend_array = array(); if ($request->hasParameter('uid')) { $profile = Doctrine_Core::getTable('Profile')->findOneByUid($request->getParameter('uid')); $friend_array[$profile->uid] = $profile->name; } else { $friends = FriendTable::getFriendsOfUid($this->getUser()->getAttribute('id')); $count = 0; foreach ($friends as $friend) { $friend_array[$friend->getUid()] = $friend->getName(); $count++; } } $this->form = new MessageForm($this->getUser()->getAttribute('id')); $this->form->setWidget('recipients', new sfWidgetFormChoice(array('multiple' => true, 'choices' => $friend_array))); //$this->form->setDefault('recipients', 4); }
'><?php echo $friend->getName(); ?> </a></div> <?php } ?> </div> </div> <div class="right"> <div id="profile_name"><?php echo $profile->getName(); ?> </div> <?php if (FriendTable::areFriends($sf_user->getAttribute('id'), $profile->getUid()) || $sf_user->getAttribute('id') == $profile->getUid()) { ?> <div class="wall"> <h4>Wall</h4> <form action ="profile/addWallpost" method="post"> <?php echo $form; ?> <input type="submit" value="Post"> </form> <?php foreach ($wall as $post) {
public function isFriendsWith($profile) { return FriendTable::areFriends($this->getAttribute('id'), $profile->getUid()) || $this->getAttribute('id') == $profile->getUid(); }
public function getFriends() { return FriendTable::getFriendsOfUid($this->uid); }