From b0ae9e6e0ad025d366e06f169e73b4e5e966376c Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 19 Jun 2016 16:38:02 +0200 Subject: [PATCH] Show friendlist on each controller This PR will change Friendships behavior so that the module will not only be available on the profile page, but also on each other pages. --- modules/class.friendshipsmodule.php | 88 +++++++++++++++++------------ 1 file changed, 51 insertions(+), 37 deletions(-) diff --git a/modules/class.friendshipsmodule.php b/modules/class.friendshipsmodule.php index 348f933..be5f867 100644 --- a/modules/class.friendshipsmodule.php +++ b/modules/class.friendshipsmodule.php @@ -94,46 +94,60 @@ private function _ConfirmFriendshipButton($UserID) { public function ToString() { + if(!CheckPermission('Friendships.Friends.View')){ + return ''; + } + if($this->_Sender instanceof ProfileController) { - if(CheckPermission('Friendships.Friends.View')){ - $ProfileOwnerID = $this->_Sender->User->UserID; - $String = '
'; - $String .= '

' . T('Friendships') . '

'; - if(Gdn::Session()->IsValid()){ //a logged user - $SessionUserID = Gdn::Session()->UserID; - //check if current user is on his page -> shows only his friend - if($ProfileOwnerID == $SessionUserID){ - //this is my profile page (AND obviously I'm NOT a guest) - $String .= $this->_ReceivedFriendshipRequests(); - }else{ - //this is NOT my profile page - //Check if a friendship exists or a friendship request exist: 'request' or 'confirm' - if($this->_FriendshipModel->FriendsFrom($SessionUserID, $ProfileOwnerID)){ - if(CheckPermission('Friendships.Friends.DeleteFriendship')){ - $String .= $this->_DeleteFriendshipButton($ProfileOwnerID); - } - }elseif($this->_FriendshipModel->Get($SessionUserID, $ProfileOwnerID)){ - $Out = $this->_FriendshipModel->GetAbsolute($SessionUserID, $ProfileOwnerID); - $In = $this->_FriendshipModel->GetAbsolute($ProfileOwnerID, $SessionUserID); - if($Out){ //is a friendship request from me - $String .= $this->_DeleteFriendshipRequestButton($Out->RequestedTo); - }else{ //is an incoming friendship request - $String .= $this->_ConfirmFriendshipButton($In->RequestedBy); - } - }else{ //show the "Request friendship" button - if(CheckPermission('Friendships.Friends.RequestFriendship')){ - $String .= $this->_RequestFriendshipButton($ProfileOwnerID); - } - } - } - $String .= $this->_FriendsList($ProfileOwnerID); - }else{//I'm guest -> I can have only view permission (internal vanilla security rule) - //show friends list - $String .= $this->_FriendsList($ProfileOwnerID); - } + $ProfileOwnerID = $this->_Sender->User->UserID; + }else{ + $ProfileOwnerID = Gdn::Session()->UserID; + } + + $String = '
'; + $String .= '

' . T('Friendships') . '

'; + + //I'm guest -> I can have only view permission (internal vanilla security rule) + if(!Gdn::Session()->IsValid()){ + if($this->_Sender instanceof ProfileController) { + //show friends list of profile user + $String .= $this->_FriendsList($ProfileOwnerID); $String .= '
'; return $String; + }else{ + //show nothing if not in profile + return ''; + } + } + + $SessionUserID = Gdn::Session()->UserID; + //check if current user is on his page -> shows only his friend + if($ProfileOwnerID == $SessionUserID){ + //this is my profile page + $String .= $this->_ReceivedFriendshipRequests(); + }else{ + //this is NOT my profile page, but must be a profile page + //Check if a friendship exists or a friendship request exist: 'request' or 'confirm' + if($this->_FriendshipModel->FriendsFrom($SessionUserID, $ProfileOwnerID)){ + if(CheckPermission('Friendships.Friends.DeleteFriendship')){ + $String .= $this->_DeleteFriendshipButton($ProfileOwnerID); + } + }elseif($this->_FriendshipModel->Get($SessionUserID, $ProfileOwnerID)){ + $Out = $this->_FriendshipModel->GetAbsolute($SessionUserID, $ProfileOwnerID); + $In = $this->_FriendshipModel->GetAbsolute($ProfileOwnerID, $SessionUserID); + if($Out){ //is a friendship request from me + $String .= $this->_DeleteFriendshipRequestButton($Out->RequestedTo); + }else{ //is an incoming friendship request + $String .= $this->_ConfirmFriendshipButton($In->RequestedBy); + } + }else{ //show the "Request friendship" button + if(CheckPermission('Friendships.Friends.RequestFriendship')){ + $String .= $this->_RequestFriendshipButton($ProfileOwnerID); + } } } + $String .= $this->_FriendsList($ProfileOwnerID); + $String .= '
'; + return $String; } -} \ No newline at end of file +}