public function addAction() { // add a member as a friend // given the logged in user and the id of the user to be added // add this to the friend database $request = $this->getRequest(); if ($request->isGet()) { $friend_user_id = $request->getParam('id'); if ($friend_user_id != NULL) { $auth = Zend_Auth::getInstance(); $identity = $auth->getIdentity(); $friendMapper = new Application_Model_FriendMapper(); $friend = new Application_Model_Friend(); $friend->setUserId($identity->id); $friend->setFriendUserId($friend_user_id); // we need to check if the friend request is already existing before adding it to the db $exists = $friendMapper->exists($friend->getUserId(), $friend->getFriendUserId()); if (!$exists) { try { $id = $friendMapper->save($friend); $this->view->msg = 'Your friend request has been sent.'; } catch (Exception $e) { // @TODO Log exception $this->view->msg = $e->getMessage(); } } else { // request was already sent $this->view->msg = 'Your friend request has already been sent.'; } } } }
public function save(Application_Model_Friend $friend) { $data = array('id' => $friend->getId(), 'user_id' => $friend->getUserId(), 'friend_user_id' => $friend->getFriendUserId(), 'confirmed' => $friend->getConfirmed()); if (null === ($id = $friend->getId())) { unset($data['id']); return $this->getDbTable()->insert($data); } else { $this->getDbTable()->update($data, array('id = ?' => $id)); } }