Alex Trofimov 12 лет назад
Родитель
Сommit
bf0a69ab87

+ 51 - 4
inc/classes/BxDolGridConnections.php

@@ -59,10 +59,6 @@ class BxDolGridConnections extends BxTemplGrid
         $aIds = bx_get('ids');
         if ($aIds && is_array($aIds))
             $iId = (int)array_pop($aIds);
-/*
-        if (!$iId)
-            $iId = (int)bx_get('ID');
-*/
 
         if (!$iId) {
             $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
@@ -79,6 +75,14 @@ class BxDolGridConnections extends BxTemplGrid
             $this->_echoResultJson(array('grid' => $this->getCode(false), 'blink' => $iId), true);
     }
 
+    /**
+     * 'add friend' action handler
+     */
+    public function performActionAddFriend() 
+    {
+        return $this->performActionAccept();
+    }
+
     protected function _delete ($mixedId) {
         bx_import('BxDolConnection');
         $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
@@ -101,6 +105,36 @@ class BxDolGridConnections extends BxTemplGrid
         return parent::_getCellDefault ($oProfile->getUnit(), $sKey, $aField, $aRow);
     }
 
+    protected function _getCellInfo ($mixedValue, $sKey, $aField, $aRow)
+    {
+        $s = '';
+        bx_import('BxDolConnection');
+        $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
+
+        // for friend requests display mutual friends
+        if ($this->_bOwner && !$aRow['mutual']) {
+            $a = $oConn->getCommonContent($aRow['id'], bx_get_logged_profile_id(), true);
+            $i = count($a);
+            if (1 == $i) {
+                $iProfileId = array_pop($a);
+                bx_import('BxDolProfile');
+                $oProfile = BxDolProfile::getInstance($iProfileId);
+                $s = _t('_bx_persons_txt_one_mutual_friend', $oProfile->getUrl(), $oProfile->getDisplayName());
+            } elseif ($i) {
+                $s = _t('_bx_persons_txt_n_mutual_friends', $i);
+            }
+        }
+
+        // display friends number if no other info is available
+        if (!$s) {
+            $a = $oConn->getConnectedContent($aRow['id'], true);
+            $i = count($a);
+            $s = _t('_bx_persons_txt_n_friends', $i);
+        }
+
+        return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
+    }
+
     protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
     {
         if (!$this->_bOwner)
@@ -115,6 +149,19 @@ class BxDolGridConnections extends BxTemplGrid
 
         return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
     }
+
+    protected function _getActionAddFriend ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
+    {
+        if ($this->_bOwner || $aRow['id'] == bx_get_logged_profile_id())
+            return '';
+
+        bx_import('BxDolConnection');
+        $oConn = BxDolConnection::getObjectInstance($this->_sObjectConnections);
+        if ($oConn->isConnected($aRow['id'], bx_get_logged_profile_id()) || $oConn->isConnected(bx_get_logged_profile_id(), $aRow['id']))
+            return '';
+
+        return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
+    }
 }
 
 /** @} */

+ 7 - 6
install/sql/system.sql

@@ -3065,17 +3065,18 @@ INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `conf
 
 -- GRID: connections
 
-INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_mode`, `sorting_fields`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES
-('sys_grid_connections', 'Sql', 'SELECT `p`.`id`, `added`, `mutual` FROM `sys_profiles` AS `p` {join_connections}', 'sys_profiles', 'id', 'added', '', 10, NULL, 'start', '', '', 'auto', '', 2147483647, 'BxDolGridConnections', '');
+INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `field_active`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_fields_translatable`, `filter_mode`, `sorting_fields`, `sorting_fields_translatable`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES
+('sys_grid_connections', 'Sql', 'SELECT `p`.`id`, `c`.`added`, `c`.`mutual` FROM `sys_profiles` AS `p` INNER JOIN `sys_accounts` AS `a` ON (`a`.`id` = `p`.`account_id`) {join_connections}', 'sys_profiles', 'id', 'c`.`added', '', '', 10, NULL, 'start', '', 'name,email', '', 'auto', '', '', 2147483647, 'BxDolGridConnections', '');
 
 INSERT INTO `sys_grid_fields` (`object`, `name`, `title`, `width`, `params`, `order`) VALUES
-('sys_grid_connections', 'name', '_sys_name', '70%', '', 1),
-('sys_grid_connections', 'actions', '', '30%', '', 2);
+('sys_grid_connections', 'name', '_sys_name', '40%', '', 1),
+('sys_grid_connections', 'info', '', '30%', '', 2),
+('sys_grid_connections', 'actions', '', '30%', '', 3);
 
 INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `confirm`, `order`) VALUES
 ('sys_grid_connections', 'single', 'accept', '_sys_accept', '', 0, 1),
-('sys_grid_connections', 'single', 'delete', '', 'remove', 1, 2);
-
+('sys_grid_connections', 'single', 'delete', '', 'remove', 1, 2),
+('sys_grid_connections', 'single', 'add_friend', '_sys_add_friend', 'plus', 0, 3);
 
 -- --------------------------------------------------------
 

+ 1 - 0
modules/boonex/english/data/langs/system.xml

@@ -1356,6 +1356,7 @@
 	<string name="_sys_acl_action_unauthenticated"><![CDATA[Not logged in users can't <b>{1}</b>.]]></string>
 	<string name="_sys_acl_action_unconfirmed"><![CDATA[You didn't confirm your profile. Please check your email with profile activation link. Unconfirmed members can't <b>{1}</b>.]]></string>
 	<string name="_sys_acl_action_vote"><![CDATA[Vote]]></string>
+	<string name="_sys_add_friend"><![CDATA[Add friend]]></string>
 	<string name="_sys_adm_installed"><![CDATA[Installed]]></string>
 	<string name="_sys_admin_apply"><![CDATA[Apply]]></string>
 	<string name="_sys_admin_filter"><![CDATA[Filter:]]></string>

+ 4 - 0
modules/boonex/persons/install/langs/en.xml

@@ -110,4 +110,8 @@
 
     <string name="_bx_persons_txt_change_image"><![CDATA[Change Picure]]></string>
     <string name="_bx_persons_txt_no_picture_uploaded"><![CDATA[No picture uploaded]]></string>
+    <string name="_bx_persons_txt_n_friends"><![CDATA[{0} friends]]></string>
+    <string name="_bx_persons_txt_n_mutual_friends"><![CDATA[{0} mutual friends]]></string>
+    <string name="_bx_persons_txt_one_mutual_friend"><![CDATA[<a href="{0}">{1}</a> mutual friend]]></string>
+
 </resources>