Exemplo n.º 1
0
 public function addFriendAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $userNs = new Zend_Session_Namespace('members');
     $userId = $userNs->userId;
     $params = $this->getRequest()->getParams();
     $friendId = $params['id'];
     $connectionType = $params['ftype'];
     //check user login
     if (!isset($userId) && !is_numeric($userId)) {
         $userM = new Application_Model_User();
         $profileUser = $userM->find($friendId);
         $profileUrl = "/";
         if (false !== $profileUser) {
             $profileUrl = "/" . $profileUser->getUsername();
         }
         $JsonResultArray = array('error' => 1, 'response' => "Please login to make this request.", "profileUrl" => $profileUrl);
         echo Zend_Json::encode($JsonResultArray);
         exit;
     }
     $friendM = new Application_Model_Friend();
     $frienddata = $friendM->fetchRow("user_id = '{$userId}' and friend_id = '{$friendId}'");
     $reqStatus = "";
     if (false !== $frienddata) {
         $reqStatus = $frienddata->getStatus();
         if ($reqStatus == "pending") {
             $response = "You already have sent friend request to this user.";
         } else {
             if ($reqStatus == "accept") {
                 $response = "This user already added in your friend list.";
             } else {
                 if ($reqStatus == "decline") {
                     //update friend request status to pending
                     $frienddata->setStatus("pending");
                     $frienddata->save();
                     //send friend request email to user
                     $userObj = new Application_Model_User();
                     //get sender information
                     $Sender = $userObj->find($userId);
                     $mailOptions['sender_email'] = $Sender->getEmail();
                     $mailOptions['sender_name'] = ucwords($Sender->getFirstName()) . ' ' . ucwords($Sender->getLastName());
                     //get receiver information
                     $Receiver = $userObj->find($friendId);
                     $mailOptions['receiver_email'] = $Receiver->getEmail();
                     $mailOptions['receiver_name'] = ucwords($Receiver->getFirstName()) . ' ' . ucwords($Receiver->getLastName());
                     $mailOptions['con_type'] = ucwords($connectionType);
                     //create mail class object and send the email
                     $Mail = new Base_Mail();
                     $Mail->sendFriendRequest($mailOptions);
                     $response = "Your friend request has been sent.";
                 } else {
                     $response = "Error occured, please contact system administrator.";
                 }
             }
         }
     } else {
         $data['userId'] = $userId;
         $data['friendId'] = $friendId;
         $data['connectionType'] = $connectionType;
         $data['status'] = 'pending';
         $friendM = new Application_Model_Friend($data);
         $res = $friendM->save();
         if ($res) {
             //send friend request email to user
             $userObj = new Application_Model_User();
             //get sender information
             $Sender = $userObj->find($userId);
             $mailOptions['sender_email'] = $Sender->getEmail();
             $mailOptions['sender_name'] = ucwords($Sender->getFirstName()) . ' ' . ucwords($Sender->getLastName());
             //get receiver information
             $Receiver = $userObj->find($friendId);
             $mailOptions['receiver_email'] = $Receiver->getEmail();
             $mailOptions['receiver_name'] = ucwords($Receiver->getFirstName()) . ' ' . ucwords($Receiver->getLastName());
             $mailOptions['con_type'] = ucwords($connectionType);
             //create mail class object and send the email
             $Mail = new Base_Mail();
             $Mail->sendFriendRequest($mailOptions);
             $response = "Your friend request has been sent.";
         } else {
             $response = "Error occured please try again later.";
         }
     }
     $JsonResultArray = array('error' => 2, 'response' => $response);
     echo Zend_Json::encode($JsonResultArray);
     exit;
 }
Exemplo n.º 2
0
 /**
  * @Created By 	: Mahipal Singh Adhikari
  * @Created On 	: 28-Dec-2010
  * @Description	: Get the Login User and User's connection
  * @Input		: $user_id(int), $friend_id(int)
  * @Return		: returns String(connection type) if exists relation otherwise returns False
  **/
 public function getUserConnection($user_id, $friend_id)
 {
     $connection = false;
     //if logged in user viewing own
     if ($user_id == $friend_id) {
         $connection = "own";
     }
     //now if user is logged in i.e. $friend_id is not null, check connection with user
     if (isset($friend_id) && is_numeric($friend_id)) {
         $friendM = new Application_Model_Friend();
         $friend_cond = "user_id='{$user_id}' AND friend_id='{$friend_id}' AND status='accept'";
         $conTypeObj = $friendM->fetchRow($friend_cond);
         //if logged in user connected with this user
         if (false !== $conTypeObj) {
             $con_type = $conTypeObj->getConnectionType();
             $connection = $con_type;
         }
         //end if
     }
     //end if
     return $connection;
 }
Exemplo n.º 3
0
 /**
  * @Created By 	: Mahipal Singh Adhikari
  * @Created On 	: 17-Nov-2010
  * @Description	: This function is used to check user privacy settings for his profile
  * @Input		: $user_id(int), $friend_id(int), $permission_id(int)
  * @Return		: boolean(True or False)
  **/
 public function checkUserPrivacySettings($user_id, $friend_id, $permission_id)
 {
     $permit = false;
     //if no parameters sent, return false
     if (!isset($user_id) && $user_id == "" || !isset($permission_id) && $permission_id) {
         return false;
     }
     //if logged in user viewing own
     if ($user_id == $friend_id) {
         return true;
     }
     //now get user permission settings
     $UserPermissionObj = new Application_Model_UserPermission();
     $wherePerCond = "user_id='{$user_id}' AND permission_id={$permission_id}";
     $permission = $UserPermissionObj->fetchRow($wherePerCond);
     if (false == $permission) {
         return false;
     }
     $permissionId = $permission->getId();
     $permission = $permission->getFriendGroupId();
     //echo "<br />permission=".$permission." for id=".$friend_id."<br />";
     //if permission is public return true
     if ($permission == 1) {
         return true;
         //display to public
     }
     //now if user is logged in i.e. $friend_id is not null, check connection with user
     if (isset($friend_id) && is_numeric($friend_id)) {
         $friendM = new Application_Model_Friend();
         $friend_cond = "user_id='{$user_id}' AND friend_id='{$friend_id}' AND status='accept'";
         $conTypeObj = $friendM->fetchRow($friend_cond);
         //if logged in user connected with this user
         if (false !== $conTypeObj) {
             $con_type = $conTypeObj->getConnectionType();
             //echo "<br />connection type=".$con_type."<br />";
             if ($con_type == "friend" && ($permission == 2 || $permission == 4)) {
                 $permit = true;
                 //display to Friends & Family AND Friends, Family and Mates
             } else {
                 if ($con_type == "family" && ($permission == 2 || $permission == 4)) {
                     $permit = true;
                     //display to Friends & Family AND Friends, Family and Mates
                 } else {
                     if ($con_type == "travelmate" && ($permission == 3 || $permission == 4)) {
                         $permit = true;
                         //display to Travel Mates AND Friends, Family and Mates
                     } else {
                         $permit = false;
                     }
                 }
             }
         } else {
             $permit = false;
         }
     }
     //end if
     return $permit;
 }