/** * Ajax function to approve a friend request **/ public function ajaxApproveRequest($requestId) { $filter = JFilterInput::getInstance(); $requestId = $filter->clean($requestId, 'int'); if (!COwnerHelper::isRegisteredUser()) { return $this->ajaxBlockUnregister(); } $objResponse = new JAXResponse(); $my = CFactory::getUser(); $friendsModel = CFactory::getModel('friends'); if ($friendsModel->isMyRequest($requestId, $my->id)) { $connected = $friendsModel->approveRequest($requestId); if ($connected) { $act = new stdClass(); $act->cmd = 'friends.request.approve'; $act->actor = $connected[0]; $act->target = $connected[1]; $act->title = ''; //JText::_('COM_COMMUNITY_ACTIVITY_FRIENDS_NOW'); $act->content = ''; $act->app = 'friends.connect'; $act->cid = 0; $friendId = $connected[0] == $my->id ? $connected[1] : $connected[0]; $friend = CFactory::getUser($friendId); //generate the activity if enabled $userPointModel = CFactory::getModel('Userpoints'); $point = $userPointModel->getPointData('friends.request.approve'); if ($point->published) { CActivityStream::add($act); //add user points - give points to both party //CFactory::load( 'libraries' , 'userpoints' ); CUserPoints::assignPoint('friends.request.approve'); CUserPoints::assignPoint('friends.request.approve', $friendId); } // Add the friend count for the current user and the connected user $friendsModel->addFriendCount($connected[0]); $friendsModel->addFriendCount($connected[1]); // Add notification //CFactory::load( 'libraries' , 'notification' ); $params = new CParameter(''); $params->set('url', 'index.php?option=com_community&view=profile&userid=' . $my->id); $params->set('friend', $my->getDisplayName()); $params->set('friend_url', 'index.php?option=com_community&view=profile&userid=' . $my->id); CNotificationLibrary::add('friends_create_connection', $my->id, $friend->id, JText::sprintf('COM_COMMUNITY_FRIEND_REQUEST_APPROVED'), '', 'friends.approve', $params); $objResponse->addScriptCall('joms.jQuery("#msg-pending-' . $requestId . '").html("' . addslashes(JText::sprintf('COM_COMMUNITY_FRIENDS_NOW', $friend->getDisplayName())) . '");'); $objResponse->addScriptCall('joms.notifications.updateNotifyCount();'); $objResponse->addScriptCall('joms.jQuery("#noti-pending-' . $requestId . '").fadeOut(1000, function() { joms.jQuery("#noti-pending-' . $requestId . '").remove();} );'); $objResponse->addScriptCall('update_counter("#jsMenuNotif > .notifcount", -1);'); $objResponse->addScriptCall('update_counter("#jsMenuFriend > .notifcount", -1);'); //trigger for onFriendApprove require_once JPATH_ROOT . '/components/com_community/controllers/friends.php'; $eventObject = new stdClass(); $eventObject->profileOwnerId = $my->id; $eventObject->friendId = $friendId; CommunityFriendsController::triggerFriendEvents('onFriendApprove', $eventObject); unset($eventObject); } } else { $objResponse->addScriptCall('joms.jQuery("#error-pending-' . $requestId . '").html("' . JText::_('COM_COMMUNITY_FRIENDS_NOT_YOUR_REQUEST') . '");'); $objResponse->addScriptCall('joms.jQuery("#error-pending-' . $requestId . '").attr("class", "error");'); } return $objResponse->sendResponse(); }
/** * Ajax function to approve a friend request **/ public function ajaxApproveRequest($requestId) { if (!COwnerHelper::isRegisteredUser()) { return $this->ajaxBlockUnregister(); } $objResponse = new JAXResponse(); $my = CFactory::getUser(); $friendsModel = CFactory::getModel('friends'); if ($friendsModel->isMyRequest($requestId, $my->id)) { $connected = $friendsModel->approveRequest($requestId); if ($connected) { $act = new stdClass(); $act->cmd = 'friends.request.approve'; $act->actor = $connected[0]; $act->target = $connected[1]; $act->title = JText::_('CC ACTIVITIES FRIENDS NOW'); $act->content = ''; $act->app = 'friends'; $act->cid = 0; CFactory::load('libraries', 'activities'); CActivityStream::add($act); //add user points - give points to both party CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint('friends.request.approve'); $friendId = $connected[0] == $my->id ? $connected[1] : $connected[0]; $friend = CFactory::getUser($friendId); CUserPoints::assignPoint('friends.request.approve', $friendId); // Add the friend count for the current user and the connected user $friendsModel->addFriendCount($connected[0]); $friendsModel->addFriendCount($connected[1]); // Add notification CFactory::load('libraries', 'notification'); $params = new JParameter(''); $params->set('url', 'index.php?option=com_community&view=profile&userid=' . $my->id); CNotificationLibrary::add('friends.create.connection', $my->id, $friend->id, JText::sprintf('CC FRIEND REQUEST APPROVED', $my->getDisplayName()), '', 'friends.approve', $params); $objResponse->addScriptCall('joms.jQuery("#msg-pending-' . $requestId . '").html("' . addslashes(JText::sprintf('CC FRIENDS NOW', $friend->getDisplayName())) . '");'); $objResponse->addScriptCall('joms.notifications.updateNotifyCount();'); $objResponse->addScriptCall('joms.jQuery("#noti-pending-' . $requestId . '").fadeOut(1000, function() { joms.jQuery("#noti-pending-' . $requestId . '").remove();} );'); //trigger for onFriendApprove require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'controllers' . DS . 'friends.php'; $eventObject = new stdClass(); $eventObject->profileOwnerId = $my->id; $eventObject->friendId = $friendId; CommunityFriendsController::triggerFriendEvents('onFriendApprove', $eventObject); unset($eventObject); } } else { $objResponse->addScriptCall('joms.jQuery("#error-pending-' . $requestId . '").html("' . JText::_('CC NOT YOUR REQUEST') . '");'); $objResponse->addScriptCall('joms.jQuery("#error-pending-' . $requestId . '").attr("class", "error");'); } return $objResponse->sendResponse(); }